cluster5.shared.utils
Class FileUtils

java.lang.Object
  extended by cluster5.shared.utils.FileUtils

public class FileUtils
extends java.lang.Object


Constructor Summary
FileUtils()
           
 
Method Summary
static void copy(java.io.InputStream inputStream, java.io.OutputStream outputStream)
          Copies data from input stream into output stream and after all data is copied it closes the output stream.
static boolean deleteDirectory(java.lang.String fullPath)
          Deletes a nonempty directory.
static boolean deleteFile(java.lang.String fullPath)
          Deletes specified file from the file system.
static java.lang.String generateFilename(java.lang.String prefix, java.lang.String fileExtension)
          Generates new filename composed by prefix, randomly generated integer, current time in milliseconds and extension given by the original fileName.
static java.lang.String getFileExtension(java.lang.String filename)
          Returns extension of specified file.
static byte[] readFromFile(java.lang.String fullPath)
          Reads data from specified file.
static void saveToFile(java.lang.String fullPath, byte[] data)
          Saves data into a file.
static void saveToFile(java.lang.String fullPath, java.io.InputStream inputStream)
          Saves all data coming from the input stream into specified file.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtils

public FileUtils()
Method Detail

generateFilename

public static java.lang.String generateFilename(java.lang.String prefix,
                                                java.lang.String fileExtension)
Generates new filename composed by prefix, randomly generated integer, current time in milliseconds and extension given by the original fileName.

Parameters:
prefix -
fileExtension -
Returns:
newly generated file name

deleteFile

public static boolean deleteFile(java.lang.String fullPath)
Deletes specified file from the file system.

Parameters:
fullPath - path where the file is located
Returns:
true if the file was deleted

deleteDirectory

public static boolean deleteDirectory(java.lang.String fullPath)
Deletes a nonempty directory.

Parameters:
fullPath -
Returns:
true if the directory was deleted

getFileExtension

public static java.lang.String getFileExtension(java.lang.String filename)
Returns extension of specified file.

Parameters:
filename -
Returns:
extension of specified file

saveToFile

public static void saveToFile(java.lang.String fullPath,
                              java.io.InputStream inputStream)
                       throws java.io.FileNotFoundException,
                              java.io.IOException
Saves all data coming from the input stream into specified file.

Parameters:
fullPath -
inputStream -
Throws:
java.io.FileNotFoundException
java.io.IOException

saveToFile

public static void saveToFile(java.lang.String fullPath,
                              byte[] data)
                       throws java.io.FileNotFoundException
Saves data into a file.

Parameters:
fullPath -
data - bytes to save
Throws:
java.io.FileNotFoundException

copy

public static void copy(java.io.InputStream inputStream,
                        java.io.OutputStream outputStream)
                 throws java.io.IOException
Copies data from input stream into output stream and after all data is copied it closes the output stream. Reads data from the input stream until there are some available and the input stream is open. (It basically provides the same functionality as import org.apache.commons.io.IOUtils.copy().)

Parameters:
inputStream - source input stream
outputStream - sink output stream
Throws:
java.io.IOException

readFromFile

public static byte[] readFromFile(java.lang.String fullPath)
Reads data from specified file. Note that reading huge files might result in OutOfMemoryException.

Parameters:
fullPath - path + filename to a file
Returns:
file content in byte array or null if file was not found