com.metamatrix.core.util
Class FileUtils

java.lang.Object
  extended by com.metamatrix.core.util.FileUtils

public final class FileUtils
extends java.lang.Object


Nested Class Summary
static interface FileUtils.Constants
           
 
Field Summary
static int DEFAULT_BUFFER_SIZE
           
static java.lang.String JAVA_IO_TEMP_DIR
           
static java.lang.String LINE_SEPARATOR
           
static char[] LINE_SEPARATOR_CHARS
           
static char SEPARATOR
           
static char[] SUFFIX_class
           
static char[] SUFFIX_CLASS
           
static char[] SUFFIX_jar
           
static char[] SUFFIX_JAR
           
static char[] SUFFIX_java
           
static char[] SUFFIX_JAVA
           
static char[] SUFFIX_zip
           
static char[] SUFFIX_ZIP
           
static java.lang.String TEMP_DIRECTORY
           
 
Method Summary
static java.lang.String buildDirectoryPath(java.lang.String[] paths)
          Builds a file directory path from a physical location and a location that needs to be appended to the physical.
static java.io.File convertByteArrayToFile(byte[] contents, java.lang.String parentDirectoryPath, java.lang.String fileName)
           
static void copy(java.lang.String fromFileName, java.lang.String toFileName)
          Copy a file.
static void copy(java.lang.String fromFileName, java.lang.String toFileName, boolean overwrite)
          Copy a file
static void copyDirectoriesRecursively(java.io.File sourceDirectory, java.io.File targetDirectory)
          Copy recursively the sourceDirectory and all its contents to the targetDirectory.
static void copyDirectoryContentsRecursively(java.io.File sourceDirectory, java.io.File targetDirectory)
          Copy recursively the contents of sourceDirectory to the targetDirectory.
static void copyFile(java.lang.String orginDirectory, java.lang.String destDirectory, java.lang.String fileName)
          Copy file from orginating directory to the destination directory.
static void copyFile(java.lang.String orginDirectory, java.lang.String orginFileName, java.lang.String destDirectory, java.lang.String destFileName)
          Copy file from orginating directory to the destination directory.
static java.io.File[] findAllFilesInDirectory(java.lang.String dir)
          Returns a File array that will contain all the files that exist in the directory
static java.io.File[] findAllFilesInDirectoryHavingExtension(java.lang.String dir, java.lang.String extension)
          Returns a File array that will contain all the files that exist in the directory that have the specified extension.
static java.io.File[] findAllFilesInDirectoryRecursively(java.lang.String dir)
          Returns a File array that will contain all the files that exist in the specified directory or any nested directories
static java.lang.String getBaseFileNameWithoutExtension(java.lang.String path)
           
static long getCheckSum(java.io.File f)
          Compute checksum for the given file.
static java.lang.String getExtension(java.io.File theFile)
          Obtains the file extension of the specified File.
static java.lang.String getExtension(java.lang.String theFileName)
          Obtains the file extension of the specified file name.
static java.lang.String getFilenameWithoutExtension(java.lang.String filename)
           
static boolean isArchiveFileName(java.lang.String name)
          Returns true iff str.toLowerCase().endsWith(".jar") || str.toLowerCase().endsWith(".zip") implementation is not creating extra strings.
static boolean isClassFileName(java.lang.String name)
          Returns true iff str.toLowerCase().endsWith(".class") implementation is not creating extra strings.
static boolean isFilenameValid(java.lang.String newName)
          Determine whether the specified name is valid for a file or folder on the current file system.
static boolean isJavaFileName(java.lang.String name)
          Returns true iff str.toLowerCase().endsWith(".java") implementation is not creating extra strings.
static void remove(java.lang.String filePath)
           
static void removeChildrenRecursively(java.io.File directory)
           
static void removeDirectoryAndChildren(java.io.File directory)
           
static void rename(java.lang.String oldFilePath, java.lang.String newFilePath, boolean overwrite)
          Rename a file.
static void testDirectoryPermissions(java.lang.String dirPath)
          Test whether it's possible to read and write files in the specified directory.
static java.lang.String toFileNameWithExtension(java.lang.String name, java.lang.String extension)
           Convert the specified file name to end with the specified extension if it doesn't already end with an extension.
static java.lang.String toFileNameWithExtension(java.lang.String name, java.lang.String extension, boolean force)
           Convert the specified file name to end with the specified extension if it doesn't already end with an extension.
static void write(byte[] data, java.io.File file)
          Write a byte array to a file.
static void write(byte[] data, java.lang.String fileName)
          Write a byte array to a file.
static void write(java.io.File f, java.io.OutputStream outputStream)
          Write an File to an OutputStream Note: this will not close the outputStream;
static void write(java.io.File f, java.io.OutputStream outputStream, int bufferSize)
          Write an File to an OutputStream Note: this will not close the outputStream;
static void write(java.io.InputStream is, java.io.File f)
          Write an InputStream to a file.
static void write(java.io.InputStream is, java.io.File f, int bufferSize)
          Write an InputStream to a file.
static void write(java.io.InputStream fis, java.io.OutputStream outputStream, int bufferSize)
          Write the given input stream to outputstream Note: this will not close in/out streams
static void write(java.io.InputStream is, java.lang.String fileName)
          Write an InputStream to a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEPARATOR

public static final char SEPARATOR
See Also:
Constant Field Values

DEFAULT_BUFFER_SIZE

public static int DEFAULT_BUFFER_SIZE

TEMP_DIRECTORY

public static java.lang.String TEMP_DIRECTORY

LINE_SEPARATOR

public static java.lang.String LINE_SEPARATOR

LINE_SEPARATOR_CHARS

public static char[] LINE_SEPARATOR_CHARS

JAVA_IO_TEMP_DIR

public static final java.lang.String JAVA_IO_TEMP_DIR
See Also:
Constant Field Values

SUFFIX_class

public static final char[] SUFFIX_class

SUFFIX_CLASS

public static final char[] SUFFIX_CLASS

SUFFIX_java

public static final char[] SUFFIX_java

SUFFIX_JAVA

public static final char[] SUFFIX_JAVA

SUFFIX_jar

public static final char[] SUFFIX_jar

SUFFIX_JAR

public static final char[] SUFFIX_JAR

SUFFIX_zip

public static final char[] SUFFIX_zip

SUFFIX_ZIP

public static final char[] SUFFIX_ZIP
Method Detail

toFileNameWithExtension

public static java.lang.String toFileNameWithExtension(java.lang.String name,
                                                       java.lang.String extension)

Convert the specified file name to end with the specified extension if it doesn't already end with an extension.

Parameters:
name - The file name.
extension - The extension to append to the file name.
Returns:
The file name with an extension.
Since:
4.0

toFileNameWithExtension

public static java.lang.String toFileNameWithExtension(java.lang.String name,
                                                       java.lang.String extension,
                                                       boolean force)

Convert the specified file name to end with the specified extension if it doesn't already end with an extension. If force is true, the specified extension will be appended to the name if the name doesn't end with that particular extension.

Parameters:
name - The file name.
extension - The extension to append to the file name.
force - Indicates whether to force the specified extension as the extension of the file name.
Returns:
The file name with an extension.
Since:
4.0

isFilenameValid

public static boolean isFilenameValid(java.lang.String newName)
Determine whether the specified name is valid for a file or folder on the current file system.

Parameters:
newName - the new name to be checked
Returns:
true if the name is null or contains no invalid characters for a folder or file, or false otherwise

copy

public static void copy(java.lang.String fromFileName,
                        java.lang.String toFileName)
                 throws java.io.IOException
Copy a file. Overwrites the destination file if it exists.

Parameters:
fromFileName -
toFileName -
Throws:
java.lang.Exception
java.io.IOException
Since:
4.3

copy

public static void copy(java.lang.String fromFileName,
                        java.lang.String toFileName,
                        boolean overwrite)
                 throws java.io.IOException
Copy a file

Parameters:
fromFileName -
toFileName -
overwrite - whether to overwrite the destination file if it exists.
Throws:
MetaMatrixCoreException
java.io.IOException
Since:
4.3

copyDirectoryContentsRecursively

public static void copyDirectoryContentsRecursively(java.io.File sourceDirectory,
                                                    java.io.File targetDirectory)
                                             throws java.lang.Exception
Copy recursively the contents of sourceDirectory to the targetDirectory. Note that sourceDirectory will NOT be copied. If targetDirectory does not exist, it will be created.

Parameters:
sourceDirectory - The source directory to copy
targetDirectory - The target directory to copy to
Throws:
java.lang.Exception - If the source directory does not exist.
Since:
4.3

copyFile

public static void copyFile(java.lang.String orginDirectory,
                            java.lang.String destDirectory,
                            java.lang.String fileName)
                     throws java.lang.Exception
Copy file from orginating directory to the destination directory.

Parameters:
orginDirectory -
destDirectory -
fileName -
Throws:
java.lang.Exception
Since:
4.4

copyFile

public static void copyFile(java.lang.String orginDirectory,
                            java.lang.String orginFileName,
                            java.lang.String destDirectory,
                            java.lang.String destFileName)
                     throws java.lang.Exception
Copy file from orginating directory to the destination directory.

Parameters:
orginDirectory -
orginFileName -
destDirectory -
destFileName -
Throws:
java.lang.Exception
Since:
4.4

copyDirectoriesRecursively

public static void copyDirectoriesRecursively(java.io.File sourceDirectory,
                                              java.io.File targetDirectory)
                                       throws java.lang.Exception
Copy recursively the sourceDirectory and all its contents to the targetDirectory. If targetDirectory does not exist, it will be created.

Parameters:
sourceDirectory - The source directory to copy
targetDirectory - The target directory to copy to
Throws:
java.lang.Exception - If the source directory does not exist.
Since:
4.3

write

public static void write(java.io.InputStream is,
                         java.lang.String fileName)
                  throws java.io.IOException
Write an InputStream to a file.

Throws:
java.io.IOException

write

public static void write(java.io.InputStream is,
                         java.io.File f)
                  throws java.io.IOException
Write an InputStream to a file.

Throws:
java.io.IOException

write

public static void write(java.io.InputStream is,
                         java.io.File f,
                         int bufferSize)
                  throws java.io.IOException
Write an InputStream to a file.

Throws:
java.io.IOException

write

public static void write(java.io.File f,
                         java.io.OutputStream outputStream)
                  throws java.io.IOException
Write an File to an OutputStream Note: this will not close the outputStream;

Throws:
java.io.IOException

write

public static void write(java.io.File f,
                         java.io.OutputStream outputStream,
                         int bufferSize)
                  throws java.io.IOException
Write an File to an OutputStream Note: this will not close the outputStream;

Throws:
java.io.IOException

write

public static void write(java.io.InputStream fis,
                         java.io.OutputStream outputStream,
                         int bufferSize)
                  throws java.io.IOException
Write the given input stream to outputstream Note: this will not close in/out streams

Throws:
java.io.IOException

write

public static void write(byte[] data,
                         java.lang.String fileName)
                  throws java.io.IOException
Write a byte array to a file.

Throws:
java.io.IOException

write

public static void write(byte[] data,
                         java.io.File file)
                  throws java.io.IOException
Write a byte array to a file.

Throws:
java.io.IOException

findAllFilesInDirectoryRecursively

public static java.io.File[] findAllFilesInDirectoryRecursively(java.lang.String dir)
Returns a File array that will contain all the files that exist in the specified directory or any nested directories

Returns:
File[] of files in the directory

findAllFilesInDirectory

public static java.io.File[] findAllFilesInDirectory(java.lang.String dir)
Returns a File array that will contain all the files that exist in the directory

Returns:
File[] of files in the directory

findAllFilesInDirectoryHavingExtension

public static java.io.File[] findAllFilesInDirectoryHavingExtension(java.lang.String dir,
                                                                    java.lang.String extension)
Returns a File array that will contain all the files that exist in the directory that have the specified extension.

Returns:
File[] of files having a certain extension

getFilenameWithoutExtension

public static java.lang.String getFilenameWithoutExtension(java.lang.String filename)
Parameters:
string -
Returns:

getBaseFileNameWithoutExtension

public static java.lang.String getBaseFileNameWithoutExtension(java.lang.String path)

getExtension

public static java.lang.String getExtension(java.io.File theFile)
Obtains the file extension of the specified File. The extension is considered to be all the characters after the last occurrence of FileUtils.Constants.FILE_EXTENSION_SEPARATOR_CHAR in the pathname of the input.

Parameters:
theFile - the file whose extension is being requested
Returns:
the extension or null if not found
Since:
4.2

getExtension

public static java.lang.String getExtension(java.lang.String theFileName)
Obtains the file extension of the specified file name. The extension is considered to be all the characters after the last occurrence of FileUtils.Constants.FILE_EXTENSION_SEPARATOR_CHAR.

Parameters:
theFileName - the file whose extension is being requested
Returns:
the extension or null if not found
Since:
4.2

isArchiveFileName

public static final boolean isArchiveFileName(java.lang.String name)
Returns true iff str.toLowerCase().endsWith(".jar") || str.toLowerCase().endsWith(".zip") implementation is not creating extra strings.


isClassFileName

public static final boolean isClassFileName(java.lang.String name)
Returns true iff str.toLowerCase().endsWith(".class") implementation is not creating extra strings.


isJavaFileName

public static final boolean isJavaFileName(java.lang.String name)
Returns true iff str.toLowerCase().endsWith(".java") implementation is not creating extra strings.


convertByteArrayToFile

public static java.io.File convertByteArrayToFile(byte[] contents,
                                                  java.lang.String parentDirectoryPath,
                                                  java.lang.String fileName)

removeDirectoryAndChildren

public static void removeDirectoryAndChildren(java.io.File directory)

removeChildrenRecursively

public static void removeChildrenRecursively(java.io.File directory)

buildDirectoryPath

public static java.lang.String buildDirectoryPath(java.lang.String[] paths)
Builds a file directory path from a physical location and a location that needs to be appended to the physical. This is used so that the correct File.separator is used and that no additional separator is added when not needed.

Parameters:
physicalDirectory -
appendLocation -
Returns:
Since:
4.3

getCheckSum

public static long getCheckSum(java.io.File f)
                        throws java.lang.Exception
Compute checksum for the given file.

Parameters:
f - The file for which checksum needs to be computed
Returns:
The checksum
Throws:
java.lang.Exception
Since:
4.3

testDirectoryPermissions

public static void testDirectoryPermissions(java.lang.String dirPath)
                                     throws MetaMatrixCoreException
Test whether it's possible to read and write files in the specified directory.

Parameters:
dirPath - Name of the directory to test
Throws:
MetaMatrixException
MetaMatrixCoreException
Since:
4.3

rename

public static void rename(java.lang.String oldFilePath,
                          java.lang.String newFilePath,
                          boolean overwrite)
                   throws java.io.IOException
Rename a file.

Parameters:
oldFilePath -
newFilePath -
overwrite - If true, overwrite the old file if it exists. If false, throw an exception if the old file exists.
Throws:
MetaMatrixCoreException
java.io.IOException
Since:
4.3

remove

public static void remove(java.lang.String filePath)
                   throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2009. All Rights Reserved.