webcore.utilities
Class FileUtils

java.lang.Object
  |
  +--webcore.utilities.FileUtils

public class FileUtils
extends java.lang.Object

FileUtils class contains several static utility functions that are helpful for use with files.


Constructor Summary
FileUtils()
           
 
Method Summary
 java.io.FileFilter createFileDirFilter(boolean isDirectory)
          Returns a FileFilter which will filter based on whether the file is a directory or not
 java.io.FilenameFilter createFilenameExtentionFilter(java.lang.String ext)
          Returns a FilenameFilter which will filter based on the extension of the file.
static boolean doesFileExist(java.lang.String filePath)
          Determines if a file exists
static java.lang.String extractKey(java.lang.String propertyString)
          Extracts the key value of a property String of the form: = This method is used internally to read property files.
static java.lang.String extractValue(java.lang.String propertyString)
          Extracts the value value of a property String of the form: = This method is used internally to read property files.
static java.util.Properties loadPropertiesFile(java.io.File file)
          Loads the contents of a properties file which may contain import statements for other properties files and returns a new java.util.Properties object.
static java.util.Properties loadPropertiesFile(java.io.File file, java.util.Properties defaults)
          Loads the contents of a properties file which may contain import statements for other properties files and returns a new java.util.Properties object.
static java.util.Properties loadPropertiesFile(java.lang.String filePath)
          Loads the contents of a properties file which may contain import statements for other properties files and returns a new java.util.Properties object.
static java.util.Properties loadPropertiesFile(java.lang.String filePath, java.util.Properties defaults)
          Loads the contents of a properties file which may contain import statements for other properties files and returns a new java.util.Properties object.
static java.lang.String readFileAsString(java.io.File file)
          Reads the entire contents of a file and returns the contents as a String This function should not be used on large files, because it reads the entire contents into memory as a String.
static java.lang.String readFileAsString(java.lang.String filePath)
          Reads the entire contents of a file and returns the contents as a String This function should not be used on large files, because it reads the entire contents into memory as a String.
static void writeFileAsString(java.io.File file, java.lang.String filedata)
          Writes the String filedata to a file.
static void writeFileAsString(java.lang.String filePath, java.lang.String filedata)
          Writes the String filedata to a 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

doesFileExist

public static boolean doesFileExist(java.lang.String filePath)
Determines if a file exists

Returns:
true if file exists
false if file does not exist

readFileAsString

public static java.lang.String readFileAsString(java.lang.String filePath)
                                         throws java.io.IOException
Reads the entire contents of a file and returns the contents as a String

This function should not be used on large files, because it reads the entire contents into memory as a String. It is meant to be used on very small text files.

Its counterpart is writeFileAsString();

Returns:
the entire contents of the file as a String
java.io.IOException

readFileAsString

public static java.lang.String readFileAsString(java.io.File file)
                                         throws java.io.IOException
Reads the entire contents of a file and returns the contents as a String

This function should not be used on large files, because it reads the entire contents into memory as a String. It is meant to be used on very small text files.

Its counterpart is writeFileAsString();

Returns:
the entire contents of the file as a String
java.io.IOException

writeFileAsString

public static void writeFileAsString(java.lang.String filePath,
                                     java.lang.String filedata)
                              throws java.io.IOException
Writes the String filedata to a file. This is a convenience function to to write a a short text file.

Its counterpart is readFileAsString();

java.io.IOException

writeFileAsString

public static void writeFileAsString(java.io.File file,
                                     java.lang.String filedata)
                              throws java.io.IOException
Writes the String filedata to a file. This is a convenience function to to write a a short text file.

Its counterpart is readFileAsString();

java.io.IOException

extractKey

public static java.lang.String extractKey(java.lang.String propertyString)
Extracts the key value of a property String of the form: =

This method is used internally to read property files.

If the String contains no "=" the entire String is returned.
If the String starts with "=" a zero length String is returned.

Returns:
the key of a property String

extractValue

public static java.lang.String extractValue(java.lang.String propertyString)
Extracts the value value of a property String of the form: =

This method is used internally to read property files.

If the String contains no "=" a zero length String is returned.
If the String starts with "=" the entire String is after the "=" is returned.

Returns:
the value of a property String

loadPropertiesFile

public static java.util.Properties loadPropertiesFile(java.lang.String filePath)
                                               throws java.io.IOException
Loads the contents of a properties file which may contain import statements for other properties files and returns a new java.util.Properties object. The properties file must be of the form created by java.util.Properties.save(). The file is read using the same rules as java.util.Properties.load() method with the addition of File Input Statements.

File Input Statements:
If a line starts with "<<" the line is interpreted as a file import statement. A file import statement is of the form <<

Returns:
java.util.Properties read from the file
java.io.IOException

loadPropertiesFile

public static java.util.Properties loadPropertiesFile(java.io.File file)
                                               throws java.io.IOException
Loads the contents of a properties file which may contain import statements for other properties files and returns a new java.util.Properties object. The properties file must be of the form created by java.util.Properties.save(). The file is read using the same rules as java.util.Properties.load() method with the addition of File Input Statements.

File Input Statements:
If a line starts with "<<" the line is interpreted as a file import statement. A file import statement is of the form <<

Returns:
java.util.Properties read from the file
java.io.IOException

loadPropertiesFile

public static java.util.Properties loadPropertiesFile(java.lang.String filePath,
                                                      java.util.Properties defaults)
                                               throws java.io.IOException
Loads the contents of a properties file which may contain import statements for other properties files and returns a new java.util.Properties object. The properties file must be of the form created by java.util.Properties.save(). The file is read using the same rules as java.util.Properties.load() method with the addition of File Input Statements.

File Input Statements:
If a line starts with "<<" the line is interpreted as a file import statement. A file import statement is of the form <<

Returns:
java.util.Properties read from the file
java.io.IOException

loadPropertiesFile

public static java.util.Properties loadPropertiesFile(java.io.File file,
                                                      java.util.Properties defaults)
                                               throws java.io.IOException
Loads the contents of a properties file which may contain import statements for other properties files and returns a new java.util.Properties object. The properties file must be of the form created by java.util.Properties.save(). The file is read using the same rules as java.util.Properties.load() method with the addition of File Input Statements.

File Input Statements:
If a line starts with "<<" the line is interpreted as a file import statement. A file import statement is of the form <<

Returns:
java.util.Properties read from the file
java.io.IOException

createFilenameExtentionFilter

public java.io.FilenameFilter createFilenameExtentionFilter(java.lang.String ext)
Returns a FilenameFilter which will filter based on the extension of the file.


createFileDirFilter

public java.io.FileFilter createFileDirFilter(boolean isDirectory)
Returns a FileFilter which will filter based on whether the file is a directory or not