base.util
Class FileUtil

java.lang.Object
  extended by base.util.FileUtil

public class FileUtil
extends java.lang.Object

This class provides some basic methods to manage files and folders.

Author:
Guido Angelo Ingenito

Constructor Summary
FileUtil()
           
 
Method Summary
static java.io.File[] allFileContent(java.io.File file)
          This method builds an array of files.
static boolean checkCRC32Checksum(java.io.File file, java.lang.Long crc32Checksum)
          This method checks if the computed CRC32 Checksum of the input file is equals to the provided crc32Checksum passed as formal argument.
static boolean checkMD5Digest(java.io.File file, java.lang.String md5Digest)
          This method checks if the computed MD5 Digest of the input file is equals to the provided md5Digest passed as formal argument.
static void copyFile(java.io.File input, java.io.File output)
           
static java.lang.Long createCRC32Checksum(java.io.File file)
          This method creates a CRC32 Checksum relative to the file passed as formal parameter.
static java.lang.String createMD5Digest(java.io.File file)
          This method builds an MD5 Digest of a provided input file.
static boolean deleteDirectory(java.io.File directory)
          Deletes all files and subdirectories under directory.
static java.lang.String fileContent(java.io.File file)
          This method reads all the lines of the input file returning its content in form of a String.
static long fileSizeInByte(java.io.File file)
          This method computes the specified file occupied space on the HD.
static long fileSizeInGB(java.io.File file)
          This method computes the specified file occupied space on the HD.
static long fileSizeInKB(java.io.File file)
          This method computes the specified file occupied space on the HD.
static long fileSizeInMB(java.io.File file)
          This method computes the specified file occupied space on the HD.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtil

public FileUtil()
Method Detail

fileSizeInByte

public static long fileSizeInByte(java.io.File file)
This method computes the specified file occupied space on the HD. If the input file is a simple file will be returned its size otherwise if the file is a directory on local HD will be recursivelly computed the occupied space of subfolders and contained files.

Parameters:
file - The file or directory whose size must be computed.
Returns:
A Byte rappresentation of the file'size.

fileSizeInKB

public static long fileSizeInKB(java.io.File file)
This method computes the specified file occupied space on the HD. If the input file is a simple file will be returned its size otherwise if the file is a directory on local HD will be recursivelly computed the occupied space of subfolders and contained files.

Parameters:
file - The file or directory whose size must be computed.
Returns:
A Kylo Byte rappresentation of the file'size.

fileSizeInMB

public static long fileSizeInMB(java.io.File file)
This method computes the specified file occupied space on the HD. If the input file is a simple file will be returned its size otherwise if the file is a directory on local HD will be recursivelly computed the occupied space of subfolders and contained files.

Parameters:
file - The file or directory whose size must be computed.
Returns:
A Mega Byte rappresentation of the file'size.

fileSizeInGB

public static long fileSizeInGB(java.io.File file)
This method computes the specified file occupied space on the HD. If the input file is a simple file will be returned its size otherwise if the file is a directory on local HD will be recursivelly computed the occupied space of subfolders and contained files.

Parameters:
file - The file or directory whose size must be computed.
Returns:
A Giga Byte rappresentation of the file'size.

createCRC32Checksum

public static java.lang.Long createCRC32Checksum(java.io.File file)
                                          throws java.io.IOException
This method creates a CRC32 Checksum relative to the file passed as formal parameter.

Parameters:
file - The file whose checksum must be created.
Returns:
The value of the CRC32 checksum-
Throws:
java.io.IOException - If can't be created the InputStream associated to the input File.

checkCRC32Checksum

public static boolean checkCRC32Checksum(java.io.File file,
                                         java.lang.Long crc32Checksum)
                                  throws java.io.IOException
This method checks if the computed CRC32 Checksum of the input file is equals to the provided crc32Checksum passed as formal argument.

Parameters:
file - The file whose checksum must be compared with the input crc32Checksum.
crc32Checksum - The comparation parameter.
Returns:
True if the computed checksum is queals to the crc32Checksum, false otherwise.
Throws:
java.io.IOException - If can't be created the InputStream associated to the input File.

allFileContent

public static java.io.File[] allFileContent(java.io.File file)
This method builds an array of files. In the case the passed formal parameter named "file" is a simple file it is returned otherwise if it is a directory all sub-files and sub-directories are navigated recursivelly and are added to the resultant array.

Parameters:
file - The file or folder from which the resultant array is built.
Returns:
An array of one file if the formal parameter named "file" is a simple file a list of sub-files or sub-directories built recursivelly if the formal parameter is a directory.

deleteDirectory

public static boolean deleteDirectory(java.io.File directory)
Deletes all files and subdirectories under directory.

Parameters:
directory - The directory that must be deleted.
Returns:
True if all deletions were successful. If a deletion fails, the method stops attempting to delete and returns false.

createMD5Digest

public static java.lang.String createMD5Digest(java.io.File file)
                                        throws java.io.IOException
This method builds an MD5 Digest of a provided input file.

Parameters:
file - The file whose MD5 Digest must be build.
Returns:
The files'MD5 Digest.
Throws:
java.io.IOException - If the method can't use the filesystem or the provided file doesn't exists.

checkMD5Digest

public static boolean checkMD5Digest(java.io.File file,
                                     java.lang.String md5Digest)
                              throws java.io.IOException
This method checks if the computed MD5 Digest of the input file is equals to the provided md5Digest passed as formal argument.

Parameters:
file - The file whose md5 digest must be compared with the input md5Digest.
md5Digest - The comparation parameter.
Returns:
True if the computed md5 digest is queals to the md5Digest, false otherwise.
Throws:
java.io.IOException - If can't be created the InputStream associated to the input File.

fileContent

public static java.lang.String fileContent(java.io.File file)
                                    throws java.io.IOException
This method reads all the lines of the input file returning its content in form of a String.

Parameters:
file - The file whose content must be retrieved.
Returns:
The content of the input file.
Throws:
java.io.IOException - If can't work on the filesystem.

copyFile

public static void copyFile(java.io.File input,
                            java.io.File output)
                     throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2006 SF.net. All Rights Reserved.