amber.utility
Class FileHandler

java.lang.Object
  |
  +--amber.utility.FileHandler

public class FileHandler
extends java.lang.Object


Constructor Summary
FileHandler()
          Default constructor.
FileHandler(java.io.File initialDirectory)
          Construct the FileHandler object pointing to a specified base directory.
FileHandler(java.lang.String initialDirectory)
          Construct the FileHandler object pointing to a specified base directory.
 
Method Summary
 void cd(java.lang.String destination)
          Changes the current directory to the specified directory.
static java.lang.String createCompositeFilename(java.lang.String directory, java.lang.String name)
          This function creates a composite filename given a directory and filename.
 void delete(java.lang.String filename)
          Deletes the specified file or directory in the current directory.
 void deleteDirectory(java.lang.String baseDirectory, boolean deleteDirectory)
          Deletes the specified directory.
 void deleteDirectoryStructure(java.io.File baseDirectory, boolean deleteDirectory)
          Deletes the specified directory.
 java.lang.String[] dir()
          Returns the files in the current directory.
 java.lang.String[] dir(java.io.FilenameFilter criteria)
          Returns the matching files in the current directory.
 java.lang.String[] dir(java.lang.String directory)
          Returns the files in the current directory.
 java.lang.String[] dir(java.lang.String directory, java.io.FilenameFilter criteria)
          Returns the files in the current directory.
 java.lang.String[] dirDirectories()
          Returns only the directories in the current directory.
 java.lang.String[] dirFiles()
          Returns only the files in the current directory.
 java.io.File getCurrentDirectory()
          Returns the current directory of this object.
 java.io.File getParent()
          Returns the parent directory of the current directory.
static java.io.File getParent(java.io.File child)
          Returns the parent directory of the input directory.
static java.io.File getRelativeDirectory(java.io.File startingDirectory, java.lang.String relativeDirectory)
          This function returns the directory specified in the relativeDirectory argument relative to the directory specified in start.
static java.io.File getRelativeFile(java.io.File startingDirectory, java.lang.String relativeFile)
          This function returns the directory specified in the relativeDirectory argument relative to the directory specified in start.
static java.io.File getRelativeFile(java.io.File startingDirectory, java.lang.String relativeFile, boolean mustExist)
          This function returns the directory specified in the relativeDirectory argument relative to the directory specified in start.
 void makeDirectory(java.lang.String directory)
          Creates the specified directory in the current directory.
 void makeDirectoryTree(java.lang.String directory)
          Creates the specified directory in the current directory.
static java.lang.String removeTrailingSeparator(java.lang.String dir)
          This function removes trailing file separator characters to ensure that the directory ends without them.
 void rename(java.lang.String oldFilename, java.lang.String newFilename)
          Renames the specified file in the current directory.
 void setCurrentDirectory(java.io.File directory)
          Sets the current directory of this object.
 void setCurrentDirectory(java.lang.String directory)
          Sets the current directory of this object.
 void up()
          This changes the current directory up one directory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileHandler

public FileHandler()
Default constructor.

FileHandler

public FileHandler(java.io.File initialDirectory)
            throws java.io.IOException
Construct the FileHandler object pointing to a specified base directory.
Parameters:
initialDirectory - File containing the initial directory.
Throws:
java.io.IOException - containing errors connecting to the specified directory.

FileHandler

public FileHandler(java.lang.String initialDirectory)
            throws java.io.IOException
Construct the FileHandler object pointing to a specified base directory.
Parameters:
initialDirectory - String containing the initial directory.
Throws:
java.io.IOException - containing errors connecting to the specified directory.
Method Detail

createCompositeFilename

public static java.lang.String createCompositeFilename(java.lang.String directory,
                                                       java.lang.String name)
This function creates a composite filename given a directory and filename.
Parameters:
directory - String containing the directory name.
filename - String filename.
Returns:
String containing the absolute file path including the directory.

removeTrailingSeparator

public static java.lang.String removeTrailingSeparator(java.lang.String dir)
This function removes trailing file separator characters to ensure that the directory ends without them. This is required as the Java File class acts strangely if they remain. Should there be no trailing separator the function simply returns the directory string unchanged.
Parameters:
dir - String directory to truncate.
Returns:
String containing the directory truncated.

setCurrentDirectory

public void setCurrentDirectory(java.lang.String directory)
                         throws java.io.IOException
Sets the current directory of this object.
Parameters:
directory - String containing the current directory.
Throws:
java.io.IOException - containing errors in making the directory change.

setCurrentDirectory

public void setCurrentDirectory(java.io.File directory)
Sets the current directory of this object.
Parameters:
directory - File containing the current directory.

getCurrentDirectory

public java.io.File getCurrentDirectory()
Returns the current directory of this object.
Returns:
File containing the current directory.

getRelativeDirectory

public static java.io.File getRelativeDirectory(java.io.File startingDirectory,
                                                java.lang.String relativeDirectory)
                                         throws java.io.IOException
This function returns the directory specified in the relativeDirectory argument relative to the directory specified in start.
Parameters:
startingDirectory - File containing the directory to start at.
relativeDirectory - String containing the path of the new directory relative to the startingDirectory.
Returns:
File containing the new directory.
Throws:
java.io.IOException - containing errors in making the directory change.

getRelativeFile

public static java.io.File getRelativeFile(java.io.File startingDirectory,
                                           java.lang.String relativeFile)
                                    throws java.io.IOException
This function returns the directory specified in the relativeDirectory argument relative to the directory specified in start.
Parameters:
startingDirectory - File containing the directory to start at.
relativeFile - String containing the path of the new file/directory relative to the startingDirectory.
Returns:
File containing the new file/directory.
Throws:
java.io.IOException - containing errors in making the directory change.

getRelativeFile

public static java.io.File getRelativeFile(java.io.File startingDirectory,
                                           java.lang.String relativeFile,
                                           boolean mustExist)
                                    throws java.io.IOException
This function returns the directory specified in the relativeDirectory argument relative to the directory specified in start.
Parameters:
startingDirectory - File containing the directory to start at.
relativeFile - String containing the path of the new file/directory relative to the startingDirectory.
mustExist - boolean when true the file must exist.
Returns:
File containing the new file/directory.
Throws:
java.io.IOException - containing errors in making the directory change.

getParent

public static java.io.File getParent(java.io.File child)
                              throws java.io.IOException
Returns the parent directory of the input directory.
Parameters:
child - File containing the object to get the parent of.
Returns:
File parent directory of the child.
Throws:
java.io.IOException - containing errors in making the directory change.

getParent

public java.io.File getParent()
                       throws java.io.IOException
Returns the parent directory of the current directory.
Returns:
File parent directory of the current directory.
Throws:
java.io.IOException - containing errors in making the directory change.

up

public void up()
        throws java.io.IOException
This changes the current directory up one directory.
Throws:
java.io.IOException - containing errors in making the directory change.

cd

public void cd(java.lang.String destination)
        throws java.io.IOException
Changes the current directory to the specified directory.
Parameters:
destination - String directory to change to.
Throws:
java.io.IOException - containing errors in making the directory change.

dir

public java.lang.String[] dir()
Returns the files in the current directory.
Returns:
String [] containing the files/directories in the directory.

dirFiles

public java.lang.String[] dirFiles()
Returns only the files in the current directory.
Returns:
String [] containing the files in the directory.

dirDirectories

public java.lang.String[] dirDirectories()
Returns only the directories in the current directory.
Returns:
String [] containing the child directories in the directory.

dir

public java.lang.String[] dir(java.io.FilenameFilter criteria)
Returns the matching files in the current directory.
Parameters:
criteria - FilenameFilter which is used to define which files are of interest.
Returns:
String [] containing the files/directories in the directory.

dir

public java.lang.String[] dir(java.lang.String directory)
                       throws java.io.IOException
Returns the files in the current directory.
Parameters:
directory - String containing the directory to list.
Returns:
String [] containing the files/directories in the directory.
Throws:
java.io.IOException - containing errors in making the directory change.

dir

public java.lang.String[] dir(java.lang.String directory,
                              java.io.FilenameFilter criteria)
                       throws java.io.IOException
Returns the files in the current directory.
Parameters:
directory - String containing the directory to list.
criteria - FilenameFilter which is used to define which files are of interest.
Returns:
String [] containing the files/directories in the directory.
Throws:
java.io.IOException - containing errors in making the directory change.

makeDirectory

public void makeDirectory(java.lang.String directory)
                   throws java.io.IOException
Creates the specified directory in the current directory.
Parameters:
directory - String containing the directory to create.
Throws:
java.io.IOException - containing errors in making the directory.

makeDirectoryTree

public void makeDirectoryTree(java.lang.String directory)
                       throws java.io.IOException
Creates the specified directory in the current directory. If necessary it will also create any required parent directories also.
Parameters:
directory - String containing the directory to create.
Throws:
java.io.IOException - containing errors in making the directory.

rename

public void rename(java.lang.String oldFilename,
                   java.lang.String newFilename)
            throws java.io.IOException
Renames the specified file in the current directory.
Parameters:
oldFilename - String name of the file to rename.
newFilename - String new name of the file.
Throws:
java.io.IOException - containing errors in making the file name change.

delete

public void delete(java.lang.String filename)
            throws java.io.IOException
Deletes the specified file or directory in the current directory. If the filename is a directory and the directory is not empty the function will throw an exception.
Parameters:
filename - String name of the file to delete.
Throws:
java.io.IOException - containing errors in making the file name change.

deleteDirectory

public void deleteDirectory(java.lang.String baseDirectory,
                            boolean deleteDirectory)
                     throws java.io.IOException
Deletes the specified directory. This function recurses to remove all child files/directories contained in the directory.
Parameters:
baseDirectory - String name of the directory to delete.
deleteDirectory - If this flag is true then the base directory is deleted also. If the flag is false then all children are deleted but the base directory will be left intact.
Throws:
java.io.IOException - containing errors in making the file name change.

deleteDirectoryStructure

public void deleteDirectoryStructure(java.io.File baseDirectory,
                                     boolean deleteDirectory)
                              throws java.io.IOException
Deletes the specified directory. This function recurses to remove all child files/directories contained in the directory.
Parameters:
baseDirectory - File directory to delete.
deleteDirectory - If this flag is true then the base directory is deleted also. If the flag is false then all children are deleted but the base directory will be left intact.
Throws:
java.io.IOException - containing errors in making the file name change.


Copyright © 2002 Clearfield Research Ltd. All Rights Reserved.