com.adobe.idml
Class FileUtils

java.lang.Object
  extended by com.adobe.idml.FileUtils

public abstract class FileUtils
extends java.lang.Object

File specific utility methods used by other classes in the package.


Constructor Summary
FileUtils()
           
 
Method Summary
static void CopyDir(java.io.File src, java.io.File dest)
          Copies the contents of a source directory into a destination directory.
static void CopyFile(java.io.File src, java.io.File dest)
          Copy a file
static java.io.File createFile(java.lang.String filePath)
          Creates a text file at the location specified.
static java.io.File CreateTempDir()
          Creates a temporary directory.
static java.io.File CreateTempFile()
          Creates a temp file that is deleted on exit.
static boolean DeleteDirectory(java.io.File dir)
          Deletes the directory specified by dir.
static boolean deleteFile(java.lang.String filePath)
          Deletes a file.
static void ensureDirectory(java.io.File dir)
          Creates the directory if it does not already exist.
static void ensureDirectory(java.lang.String dirPath)
          Creates the directory if it does not already exist.
static void ensureParentDirectory(java.lang.String filePath)
          Ensures that the directory containing the file specified exists.
static java.io.File getDirectory(java.lang.String dirPath)
          Returns a file object representing the path given.
static java.io.File getFile(java.lang.String filePath)
          Returns a file object representing the path given.
static java.lang.String getFileSize(java.io.File file)
          Get the size of a file in Kilobytes.
static java.lang.String getFileType(java.lang.String filePath)
          Get the file extension for a file.
static java.io.BufferedWriter getFileWriter(java.io.File txtFile)
          Gets a buffered writer for a text file.
static java.io.File getIdmlReferencedFile(java.lang.String filePath)
          Returns a file object representing the path given.
static java.io.File getParentDirectory(java.io.File file)
          Returns the parent directory for the file provided.
static java.io.File getParentDirectory(java.lang.String filePath)
          Returns the parent directory for the file provided.
static java.lang.String getParentDirectoryPath(java.lang.String filePath)
          Given a file path this method returns the parent directory path.
static java.lang.String getRelativePath(java.io.File fromDir, java.io.File toFile)
          Returns a relative path from the directory provided to the file specified.
static java.lang.String getRelativePath(java.lang.String fromDirPath, java.lang.String toFilePath)
          Returns a relative path from the directory provided to the file specified.
static void verifyDirectory(java.io.File dir)
          Throws an error if the file object representing the directory is invalid.
static void verifyDirectory(java.lang.String dirPath)
          Throws an error if the file object is invalid.
static void verifyFile(java.io.File file)
          Throws an error if the file object is invalid.
static void verifyFile(java.lang.String filePath)
          Throws an error if the file object is invalid.
 
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

getFileType

public static java.lang.String getFileType(java.lang.String filePath)
Get the file extension for a file.

Parameters:
filePath - The path to the file.
Returns:
The three character extension for the file.

getFileSize

public static java.lang.String getFileSize(java.io.File file)
Get the size of a file in Kilobytes.

Parameters:
file - The file object to obtain the size of.
Returns:
The size of the file in Kilobytes.

getFile

public static java.io.File getFile(java.lang.String filePath)
                            throws java.io.IOException
Returns a file object representing the path given.

Parameters:
filePath - The path to the file.
Returns:
A file object representing the file path given.
Throws:
java.io.IOException

getIdmlReferencedFile

public static java.io.File getIdmlReferencedFile(java.lang.String filePath)
                                          throws PackageException
Returns a file object representing the path given.

Parameters:
filePath - The path to the file.
Returns:
A file object representing the file path given.
Throws:
PackageException

createFile

public static java.io.File createFile(java.lang.String filePath)
                               throws java.io.IOException
Creates a text file at the location specified.

Parameters:
filePath - The location of the file to be created.
Returns:
Returns true if the file was created and false if not.
Throws:
java.io.IOException

getFileWriter

public static java.io.BufferedWriter getFileWriter(java.io.File txtFile)
                                            throws java.io.IOException
Gets a buffered writer for a text file.

Parameters:
txtFile - The file to obtain a buffered writer for.
Returns:
A BufferedWriter object for the file specified.
Throws:
java.io.IOException

getDirectory

public static java.io.File getDirectory(java.lang.String dirPath)
                                 throws java.io.IOException
Returns a file object representing the path given.

Parameters:
dirPath - The path to the directory.
Returns:
A file object representing the file path given.
Throws:
java.io.IOException

verifyFile

public static void verifyFile(java.lang.String filePath)
                       throws java.io.IOException
Throws an error if the file object is invalid.

Parameters:
filePath - The path to the file to be tested.
Throws:
java.io.IOException

verifyFile

public static void verifyFile(java.io.File file)
                       throws java.io.IOException
Throws an error if the file object is invalid.

Parameters:
file - The file to be tested.
Throws:
java.io.IOException

verifyDirectory

public static void verifyDirectory(java.lang.String dirPath)
                            throws java.io.IOException
Throws an error if the file object is invalid.

Parameters:
dirPath - The path to the directory to be tested.
Throws:
java.io.IOException

verifyDirectory

public static void verifyDirectory(java.io.File dir)
                            throws java.io.IOException
Throws an error if the file object representing the directory is invalid.

Parameters:
dir - The directory object to be tested.
Throws:
java.io.IOException

ensureParentDirectory

public static void ensureParentDirectory(java.lang.String filePath)
                                  throws java.io.IOException
Ensures that the directory containing the file specified exists. If it does not, the directory will be created.

Parameters:
filePath - The path the to a file.
Throws:
java.io.IOException

DeleteDirectory

public static boolean DeleteDirectory(java.io.File dir)
Deletes the directory specified by dir.

Parameters:
dir - The directory to delete.
Returns:
Returns true if successful, otherwise false.

deleteFile

public static boolean deleteFile(java.lang.String filePath)
Deletes a file.

Parameters:
filePath - The location of the file to be deleted.
Returns:
Returns true if the file was deleted and false if not.

CreateTempFile

public static java.io.File CreateTempFile()
Creates a temp file that is deleted on exit.

Returns:
a non-null File object reference on success.

CreateTempDir

public static java.io.File CreateTempDir()
Creates a temporary directory. It's up to the caller to delete this directory when it's no longer needed.

Returns:
a non-null File object for the directory upon success.

CopyFile

public static void CopyFile(java.io.File src,
                            java.io.File dest)
                     throws java.lang.Exception
Copy a file

Parameters:
src - The source file.
dest - The destination file.
Throws:
java.lang.Exception

CopyDir

public static void CopyDir(java.io.File src,
                           java.io.File dest)
                    throws java.lang.Exception
Copies the contents of a source directory into a destination directory.

Parameters:
src - The directory to copy.
dest - The destination directory to copy the files into.
Throws:
java.lang.Exception

getRelativePath

public static java.lang.String getRelativePath(java.lang.String fromDirPath,
                                               java.lang.String toFilePath)
                                        throws java.io.IOException
Returns a relative path from the directory provided to the file specified.

Parameters:
fromDirPath - The starting point of the relative path. Note: it needs to be a directory not a file.
toFilePath - The target file of the relative path.
Returns:
The relative path.
Throws:
java.io.IOException

getRelativePath

public static java.lang.String getRelativePath(java.io.File fromDir,
                                               java.io.File toFile)
                                        throws java.io.IOException
Returns a relative path from the directory provided to the file specified.

Parameters:
fromDir - The starting point of the relative path. Note: it needs to be a directory not a file.
toFile - The target file of the relative path.
Returns:
The relative path.
Throws:
java.io.IOException

getParentDirectory

public static java.io.File getParentDirectory(java.io.File file)
                                       throws java.io.IOException
Returns the parent directory for the file provided.

Parameters:
file - A file object for the file.
Returns:
A file object for the parent directory.
Throws:
java.io.IOException

getParentDirectory

public static java.io.File getParentDirectory(java.lang.String filePath)
                                       throws java.io.IOException
Returns the parent directory for the file provided.

Parameters:
filePath - The path to a file.
Returns:
A file object for the parent directory.
Throws:
java.io.IOException

getParentDirectoryPath

public static java.lang.String getParentDirectoryPath(java.lang.String filePath)
Given a file path this method returns the parent directory path.

Parameters:
filePath - The absolute or relative path to a file
Returns:
The path to the parent directory

ensureDirectory

public static void ensureDirectory(java.lang.String dirPath)
                            throws java.io.IOException
Creates the directory if it does not already exist.

Parameters:
dirPath - The location of the directory to ensure.
Throws:
java.io.IOException

ensureDirectory

public static void ensureDirectory(java.io.File dir)
                            throws java.io.IOException
Creates the directory if it does not already exist.

Parameters:
dir - The file object representing the directory to ensure.
Throws:
java.io.IOException


Copyright © 2008 Adobe Systems Incorporated. All Rights Reserved.