com.ebasetech.xi.services
Class FileServices

java.lang.Object
  extended by com.ebasetech.xi.services.FileServices
All Implemented Interfaces:
java.io.Serializable

public class FileServices
extends java.lang.Object
implements java.io.Serializable

File services

Since:
V4.4
See Also:
Serialized Form

Constructor Summary
FileServices()
           
 
Method Summary
static boolean copyFile(java.lang.String fromPath, java.lang.String toPath)
          Copies the contents of the file represented by fromPath to toPath.
static boolean createNewDirectory(java.lang.String filePath)
          Creates a new directory with this path name so long as a file or directory doesn't already exist with the same name.
static boolean createNewFile(java.lang.String filePath)
          Creates a new file with this path name so long as a file or directory doesn't already exist with the same name.
static boolean deleteFile(java.lang.String filePath)
          Deletes the file or directory with this path name.
static boolean existsFile(java.lang.String filePath)
          Returns true if a file or directory with this path name exists.
static java.lang.String getAbsoluteFilePath(java.lang.String filePath)
          Returns an absolute file path for the specified relative or absolute file path.
static java.lang.String getParentPath(java.lang.String filePath)
          Returns the path name of this file's parent directory or null if no parent exists.
static java.lang.String getSeparator()
          Returns the system dependent file separator character.
static java.lang.String getWebAppRootFilePath()
          Returns the file path for the root directory served by Http requests for the web application.
static boolean isDirectory(java.lang.String filePath)
          Returns true if file path represents a directory.
static boolean isFile(java.lang.String filePath)
          Returns true if file path represents a file.
static java.lang.String[] listFilesInDirectory(java.lang.String filePath)
          Returns an array of file paths for all files and directories within the directory represented by file path.
static boolean moveFile(java.lang.String fromPath, java.lang.String toPath)
          Moves the file specified by fromPath to the path specified by toPath.
static java.lang.String readFile(java.lang.String filePath)
          Returns a String value representing the contents of the file specified by file path.
static java.lang.String readFile(java.lang.String filePath, java.lang.String encoding)
          Returns a String value representing the contents of the file specified by file path decoded using the specified encoding.
static void writeFile(java.lang.String filePath, java.lang.String text)
          Creates a new file if necessary with the specified file path and saves the file with the specified text.
static void writeFile(java.lang.String filePath, java.lang.String text, java.lang.String encoding)
          Creates a new file if necessary with the specified file path and saves the file with the specified text decoded using the specified encoding.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileServices

public FileServices()
Method Detail

createNewDirectory

public static boolean createNewDirectory(java.lang.String filePath)
Creates a new directory with this path name so long as a file or directory doesn't already exist with the same name.

Parameters:
filePath - for the new directory
Returns:
true if the new directory was created, false if the file name already exists
Throws:
java.io.IOException - if an error occurs
Since:
V4.4

createNewFile

public static boolean createNewFile(java.lang.String filePath)
                             throws java.io.IOException
Creates a new file with this path name so long as a file or directory doesn't already exist with the same name.

Parameters:
filePath - file path for the new file
Returns:
true if the new file was created, false if the file name already exists
Throws:
java.io.IOException - if an error occurs
Since:
V4.4

deleteFile

public static boolean deleteFile(java.lang.String filePath)
Deletes the file or directory with this path name. If the path specifies a directory, the directory must be empty.

Parameters:
filePath - to be deleted
Returns:
true if the file or directory was deleted, false otherwise
Throws:
java.io.IOException - if an error occurs
Since:
V4.4

existsFile

public static boolean existsFile(java.lang.String filePath)
Returns true if a file or directory with this path name exists.

Parameters:
filePath -
Returns:
true if a file or directory with this path name exists, false otherwise
Since:
V4.4

getParentPath

public static java.lang.String getParentPath(java.lang.String filePath)
Returns the path name of this file's parent directory or null if no parent exists.

Parameters:
filePath -
Returns:
path of parent directory or null if no parent exists
Since:
V4.4

isDirectory

public static boolean isDirectory(java.lang.String filePath)
Returns true if file path represents a directory.

Parameters:
filePath -
Returns:
true if the file path represents a directory, false otherwise
Since:
V4.4

isFile

public static boolean isFile(java.lang.String filePath)
Returns true if file path represents a file.

Parameters:
filePath -
Returns:
true if the file path represents a file, false otherwise
Since:
V4.4

listFilesInDirectory

public static java.lang.String[] listFilesInDirectory(java.lang.String filePath)
Returns an array of file paths for all files and directories within the directory represented by file path.

Parameters:
filePath -
Returns:
an array of file paths, or null if file path does not specify a directory
Since:
V4.4

readFile

public static java.lang.String readFile(java.lang.String filePath)
                                 throws java.io.IOException
Returns a String value representing the contents of the file specified by file path.

Parameters:
filePath -
Returns:
file contents
Throws:
java.io.IOException - if an error occurs
Since:
V4.4

readFile

public static java.lang.String readFile(java.lang.String filePath,
                                        java.lang.String encoding)
                                 throws java.io.IOException
Returns a String value representing the contents of the file specified by file path decoded using the specified encoding.

Parameters:
filePath -
encoding - character set name
Returns:
file contents
Throws:
java.io.IOException - if an error occurs
Since:
V4.4

moveFile

public static boolean moveFile(java.lang.String fromPath,
                               java.lang.String toPath)
                        throws java.io.IOException
Moves the file specified by fromPath to the path specified by toPath. Returns false if either fromPath does not exist or toPath does exist. This operation is equivalent to a rename.

Parameters:
fromPath - the file to be renamed
toPath - the new name
Returns:
true if the operation was succesful, false otherwise
Throws:
java.io.IOException - if an error occurs
Since:
V4.4

writeFile

public static void writeFile(java.lang.String filePath,
                             java.lang.String text)
                      throws java.io.IOException
Creates a new file if necessary with the specified file path and saves the file with the specified text. If the file already exists, it's contents are replaced.

Parameters:
filePath -
text - text to be saved
Throws:
java.io.IOException - if an error occurs
Since:
V4.4

writeFile

public static void writeFile(java.lang.String filePath,
                             java.lang.String text,
                             java.lang.String encoding)
                      throws java.io.IOException
Creates a new file if necessary with the specified file path and saves the file with the specified text decoded using the specified encoding. If the file already exists, it's contents are replaced.

Parameters:
filePath -
text - text to be saved
encoding - character set name
Throws:
java.io.IOException - if an error occurs
Since:
V4.4

copyFile

public static boolean copyFile(java.lang.String fromPath,
                               java.lang.String toPath)
                        throws java.io.IOException
Copies the contents of the file represented by fromPath to toPath. Creates a new file for toPath if a file does not already exist. Returns false if the file represented by fromPath does not exist.

Parameters:
fromPath - the file to be copied
toPath - the target file
Returns:
true if the operation was succesful, false if the file represented by fromPath does not exist
Throws:
java.io.IOException - if an error occurs
Since:
V4.4

getSeparator

public static java.lang.String getSeparator()
Returns the system dependent file separator character. For Unix and Linux systems this will be '/', for Windows systems it will be '\'.

Returns:
file separator character
Since:
V4.4

getWebAppRootFilePath

public static java.lang.String getWebAppRootFilePath()
Returns the file path for the root directory served by Http requests for the web application.

Returns:
file path
Since:
V4.4

getAbsoluteFilePath

public static java.lang.String getAbsoluteFilePath(java.lang.String filePath)
                                            throws java.io.IOException
Returns an absolute file path for the specified relative or absolute file path. For example '/usr/myproduct/deployed/xyz.txt' might be returned for '../../xyz.txt'.

Parameters:
filePath -
Returns:
an absolute file path
Throws:
java.io.IOException
Since:
V4.4