org.jlog2.util
Class FileLoader

java.lang.Object
  extended by org.jlog2.util.FileLoader

public class FileLoader
extends java.lang.Object

This class can be used to load in a file from a local or remote location.


Constructor Summary
FileLoader()
          Create a new instance of FileLoader
 
Method Summary
static void copyStream(java.io.File sourceFile, java.io.File destFile)
          Copy the source input stream contents to the destination file.
static void deleteFile(java.lang.String fileName)
          Delete the file at the specified file path.
static java.io.BufferedReader getBufferedInputStream(java.lang.String fileName)
          Get the contents of the file as a buffered reader.
static java.lang.String getCurrentDirectory()
          Get the current directory the program is running in.
static java.util.Vector getDirectoryList(java.lang.String dirPath)
          Get the list of directories stored in the specified directory.
static java.util.Vector getFileList(java.lang.String dirPath)
          Get the list of files stored in the specified directory.
static java.util.Vector getFileList(java.lang.String dirPath, boolean subFolders)
          Get the list of files stored in the specified directory.
static java.util.Vector getFullFileListPaths(java.lang.String dirPath)
          Get the list of files stored in the specified directory.
static java.util.Vector getFullFileListPaths(java.lang.String dirPath, boolean subFolders)
          Get the list of files stored in the specified directory.
static java.lang.String getInputStream(java.lang.String fileName)
          Get the contents of the file as a String.
static java.io.BufferedReader loadFile(java.io.File filePath)
          Load a file and store in a buffer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileLoader

public FileLoader()
Create a new instance of FileLoader

Method Detail

getInputStream

public static java.lang.String getInputStream(java.lang.String fileName)
                                       throws java.lang.Exception
Get the contents of the file as a String.

Parameters:
fileName - the name and location of the file to load.
Returns:
the input stream read into a String, not a direct connection.
Throws:
java.lang.Exception - any error.

getBufferedInputStream

public static java.io.BufferedReader getBufferedInputStream(java.lang.String fileName)
                                                     throws java.lang.Exception
Get the contents of the file as a buffered reader.

Parameters:
fileName - the name and location of the file to load. This could be at a remote location.
Returns:
the input stream read into a buffered reader.
Throws:
java.lang.Exception - any error.

loadFile

public static java.io.BufferedReader loadFile(java.io.File filePath)
                                       throws java.lang.Exception
Load a file and store in a buffer. This is for a local text-based file only.

Parameters:
filePath - the path of the file to read.
Returns:
the buffer that can read the file.
Throws:
java.lang.Exception - any error.

getCurrentDirectory

public static java.lang.String getCurrentDirectory()
                                            throws java.lang.Exception
Get the current directory the program is running in.

Returns:
the directory path in String format.
Throws:
java.lang.Exception - any error

getDirectoryList

public static java.util.Vector getDirectoryList(java.lang.String dirPath)
                                         throws java.lang.Exception
Get the list of directories stored in the specified directory.

Parameters:
dirPath - the directory path.
Returns:
a list of all directories stored under this directory.
Throws:
java.lang.Exception - any error.

getFileList

public static java.util.Vector getFileList(java.lang.String dirPath)
                                    throws java.lang.Exception
Get the list of files stored in the specified directory.

Parameters:
dirPath - the directory path.
Returns:
a list of all files in the directory. This is file names only, not paths.
Throws:
java.lang.Exception - any error.

getFileList

public static java.util.Vector getFileList(java.lang.String dirPath,
                                           boolean subFolders)
                                    throws java.lang.Exception
Get the list of files stored in the specified directory.

Parameters:
dirPath - the directory path.
subFolders - if true include all files in all sub-folders, if false include files in the current folder only.
Returns:
a list of all files in the directory. This is file names only, not paths.
Throws:
java.lang.Exception - any error.

getFullFileListPaths

public static java.util.Vector getFullFileListPaths(java.lang.String dirPath)
                                             throws java.lang.Exception
Get the list of files stored in the specified directory.

Parameters:
dirPath - the directory path.
Returns:
a list of all files in the directory. This is the full file names, with paths.
Throws:
java.lang.Exception - any error.

getFullFileListPaths

public static java.util.Vector getFullFileListPaths(java.lang.String dirPath,
                                                    boolean subFolders)
                                             throws java.lang.Exception
Get the list of files stored in the specified directory.

Parameters:
dirPath - the directory path.
subFolders - if true include all files in all sub-folders, if false include files in the current folder only.
Returns:
a list of all files in the directory. This is the full file names, with paths.
Throws:
java.lang.Exception - any error.

copyStream

public static void copyStream(java.io.File sourceFile,
                              java.io.File destFile)
                       throws java.lang.Exception
Copy the source input stream contents to the destination file.

Parameters:
sourceFile - the file to copy.
destFile - the file path to copy to
Throws:
java.lang.Exception - any error.

deleteFile

public static void deleteFile(java.lang.String fileName)
                       throws java.lang.Exception
Delete the file at the specified file path.

Parameters:
fileName - the name of the file to delete.
Throws:
java.lang.Exception - any error