openr66.protocol.utils
Class FileUtils

java.lang.Object
  extended by openr66.protocol.utils.FileUtils

public class FileUtils
extends Object

File Utils

Author:
Frederic Bregier

Constructor Summary
FileUtils()
           
 
Method Summary
static String consolidatePath(String base, String path)
           
static File[] copy(File[] from, File directoryTo, boolean move)
          Copy a group of files to a directory
static void copy(File from, File to, boolean move, boolean append)
          Copy one file to another one
static File copyToDir(File from, File directoryTo, boolean move)
          Copy one file to a directory
static boolean createDir(File directory)
          Create the directory associated with the File as path
static boolean delete(File file)
          Delete physically the file
static boolean deleteDir(File directory)
          Delete the directory associated with the File as path if empty
static void deleteOnExit(File file)
          Delete physically the file but when the JVM exits (useful for temporary file)
static boolean deleteRecursiveDir(File directory)
          Delete the directory and its subdirs associated with the File as path if empty
static boolean FileExist(String _FileName, String _Path)
           
static File[] getFiles(File directory)
          Get the list of files from a given directory
static File[] getFiles(File directory, FilenameFilter filter)
          Get the list of files from a given directory and a filter
static org.jboss.netty.buffer.ChannelBuffer getHash(org.jboss.netty.buffer.ChannelBuffer buffer)
           
static String getHash(File f)
          Calculates and returns the hash of the contents of the given file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtils

public FileUtils()
Method Detail

consolidatePath

public static String consolidatePath(String base,
                                     String path)
                              throws OpenR66ProtocolSystemException
Parameters:
base - in absolute
path - path in absolute or relative
Returns:
a new String for a file from the base and the path (according to relative or absolute path)
Throws:
OpenR66ProtocolSystemException

copy

public static void copy(File from,
                        File to,
                        boolean move,
                        boolean append)
                 throws OpenR66ProtocolSystemException
Copy one file to another one

Parameters:
from -
to -
move - True if the copy is in fact a move operation
append - True if the copy is in append
Throws:
OpenR66ProtocolSystemException

copy

public static File[] copy(File[] from,
                          File directoryTo,
                          boolean move)
                   throws OpenR66ProtocolSystemException
Copy a group of files to a directory

Parameters:
from -
directoryTo -
move - True if the copy is in fact a move operation
Returns:
the group of copy files or null (partially or totally) if an error occurs
Throws:
OpenR66ProtocolSystemException

copyToDir

public static File copyToDir(File from,
                             File directoryTo,
                             boolean move)
                      throws OpenR66ProtocolSystemException
Copy one file to a directory

Parameters:
from -
directoryTo -
move - True if the copy is in fact a move operation
Returns:
The copied file or null if an error occurs
Throws:
OpenR66ProtocolSystemException

createDir

public static boolean createDir(File directory)
Create the directory associated with the File as path

Parameters:
directory -
Returns:
True if created, False else.

delete

public static boolean delete(File file)
Delete physically the file

Parameters:
file -
Returns:
True if OK, else if not (or if the file never exists).

deleteDir

public static boolean deleteDir(File directory)
Delete the directory associated with the File as path if empty

Parameters:
directory -
Returns:
True if deleted, False else.

deleteOnExit

public static void deleteOnExit(File file)
Delete physically the file but when the JVM exits (useful for temporary file)

Parameters:
file -

deleteRecursiveDir

public static boolean deleteRecursiveDir(File directory)
Delete the directory and its subdirs associated with the File as path if empty

Parameters:
directory -
Returns:
True if deleted, False else.

FileExist

public static boolean FileExist(String _FileName,
                                String _Path)
Parameters:
_FileName -
_Path -
Returns:
true if the file exist in the specified path

getFiles

public static File[] getFiles(File directory)
Get the list of files from a given directory

Parameters:
directory -
Returns:
the list of files (as an array)

getFiles

public static File[] getFiles(File directory,
                              FilenameFilter filter)
Get the list of files from a given directory and a filter

Parameters:
directory -
filter -
Returns:
the list of files (as an array)

getHash

public static String getHash(File f)
                      throws OpenR66ProtocolSystemException
Calculates and returns the hash of the contents of the given file.

Parameters:
f - FileInterface to hash
Returns:
the hash from the given file
Throws:
OpenR66ProtocolSystemException

getHash

public static org.jboss.netty.buffer.ChannelBuffer getHash(org.jboss.netty.buffer.ChannelBuffer buffer)
Parameters:
buffer -
Returns:
the hash from the given Buffer


Copyright © 2009-2012 Frederic Bregier. All Rights Reserved.