org.jostraca.util
Class FileUtil

java.lang.Object
  extended byorg.jostraca.util.FileUtil

public class FileUtil
extends java.lang.Object

File handling utility methods.


Nested Class Summary
static interface FileUtil.FileNameFilter
           
 
Field Summary
static boolean BINARY_FILE
           
static java.lang.String CN
           
static boolean EMPTY_IF_IO_ERROR
           
static boolean FAIL_ON_IO_ERROR
           
static java.io.FileFilter sElideDotFolders
           
static boolean TEXT_FILE
           
 
Constructor Summary
FileUtil()
           
 
Method Summary
static void copyFile(java.io.File pFromPath, java.io.File pToPath)
           
static void copyFile(java.io.File pFromPath, java.lang.String pToPath)
           
static void copyFile(java.lang.String pFromPath, java.io.File pToPath)
           
static void copyFile(java.lang.String pFromPath, java.lang.String pToPath)
           
static void ensureFolder(java.io.File pFile)
          Ensure folder exists
static void ensureParentFolder(java.io.File pFile)
          Ensure parent folder exists
static java.io.File findFile(java.lang.String pPathRef)
          Find a file in the classpath.
static java.lang.String getExtension(java.lang.String pFileName)
          get extension suffix from file name
static java.lang.String getParent(java.io.File pPath)
           
static java.lang.String getParent(java.io.File pPath, java.lang.String pDefaultParent)
          Get parent folder of specified path.
static java.lang.String getParent(java.lang.String pPath)
           
static long lastMod(java.io.File pPath)
          get last mode time of a file
static long lastMod(java.lang.String pPath)
          get last mode time of a file
static java.lang.String readFile(java.io.File pFile)
          Read a file using File object.
static java.lang.String readFile(java.io.File pFile, boolean pFailOnIOError)
          Read a file using File onject.
static java.lang.String readFile(java.lang.String pFilePath)
          Read a file using path.
static java.lang.String readFile(java.lang.String pFilePath, boolean pFailOnIOError)
          Read a file using path.
static byte[] readRawData(java.io.File pFile)
           
static byte[] readRawData(java.lang.String pFilePath)
           
static java.io.File[] recursiveSearch(java.io.File pRootFolder, FileUtil.FileNameFilter pFileNameFilter)
           
static java.lang.String removeExtension(java.lang.String pFileName)
          remove extension suffix from file name
static void writeBinaryFile(java.io.File pFile, java.lang.String pText)
           
static void writeBinaryFile(java.lang.String pPath, java.lang.String pText)
           
static void writeFile(java.io.File pFile, java.lang.String pText)
           
static void writeFile(java.lang.String pPath, java.lang.String pText)
           
static void writeRawData(java.io.File pFile, byte[] pData)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CN

public static final java.lang.String CN

FAIL_ON_IO_ERROR

public static final boolean FAIL_ON_IO_ERROR
See Also:
Constant Field Values

EMPTY_IF_IO_ERROR

public static final boolean EMPTY_IF_IO_ERROR
See Also:
Constant Field Values

TEXT_FILE

public static final boolean TEXT_FILE
See Also:
Constant Field Values

BINARY_FILE

public static final boolean BINARY_FILE
See Also:
Constant Field Values

sElideDotFolders

public static final java.io.FileFilter sElideDotFolders
Constructor Detail

FileUtil

public FileUtil()
Method Detail

readFile

public static java.lang.String readFile(java.io.File pFile,
                                        boolean pFailOnIOError)
                                 throws java.io.IOException
Read a file using File onject. Return empty String on error if pFailOnIOError is false.

Parameters:
pFile - file to read
pFailOnIOError - true => throws IOException on IO error.
Throws:
java.io.IOException

readFile

public static java.lang.String readFile(java.io.File pFile)
                                 throws java.io.IOException
Read a file using File object.

Parameters:
pFile - File object to read.
Throws:
java.io.IOException

readFile

public static java.lang.String readFile(java.lang.String pFilePath,
                                        boolean pFailOnIOError)
                                 throws java.io.IOException
Read a file using path. Return empty String on error if pFailOnIOError is false.

Parameters:
pFilePath - Path to file.
pFailOnIOError - true => throws IOException on IO error.
Throws:
java.io.IOException

readFile

public static java.lang.String readFile(java.lang.String pFilePath)
                                 throws java.io.IOException
Read a file using path.

Parameters:
pFilePath - Path to file.
Throws:
java.io.IOException

readRawData

public static byte[] readRawData(java.lang.String pFilePath)
                          throws java.io.IOException
Throws:
java.io.IOException

readRawData

public static byte[] readRawData(java.io.File pFile)
                          throws java.io.IOException
Throws:
java.io.IOException

lastMod

public static final long lastMod(java.lang.String pPath)
                          throws java.io.IOException
get last mode time of a file

Throws:
java.io.IOException

lastMod

public static final long lastMod(java.io.File pPath)
                          throws java.io.IOException
get last mode time of a file

Throws:
java.io.IOException

writeBinaryFile

public static void writeBinaryFile(java.io.File pFile,
                                   java.lang.String pText)
                            throws java.io.IOException
Throws:
java.io.IOException

writeFile

public static void writeFile(java.io.File pFile,
                             java.lang.String pText)
                      throws java.io.IOException
Throws:
java.io.IOException

writeBinaryFile

public static void writeBinaryFile(java.lang.String pPath,
                                   java.lang.String pText)
                            throws java.io.IOException
Throws:
java.io.IOException

writeFile

public static void writeFile(java.lang.String pPath,
                             java.lang.String pText)
                      throws java.io.IOException
Throws:
java.io.IOException

writeRawData

public static void writeRawData(java.io.File pFile,
                                byte[] pData)
                         throws java.io.IOException
Throws:
java.io.IOException

copyFile

public static void copyFile(java.lang.String pFromPath,
                            java.lang.String pToPath)
                     throws java.io.IOException
Throws:
java.io.IOException

copyFile

public static void copyFile(java.lang.String pFromPath,
                            java.io.File pToPath)
                     throws java.io.IOException
Throws:
java.io.IOException

copyFile

public static void copyFile(java.io.File pFromPath,
                            java.lang.String pToPath)
                     throws java.io.IOException
Throws:
java.io.IOException

copyFile

public static void copyFile(java.io.File pFromPath,
                            java.io.File pToPath)
                     throws java.io.IOException
Throws:
java.io.IOException

getParent

public static java.lang.String getParent(java.io.File pPath)
See Also:
getParent( File, String )

getParent

public static java.lang.String getParent(java.lang.String pPath)
See Also:
getParent( File, String )

getParent

public static java.lang.String getParent(java.io.File pPath,
                                         java.lang.String pDefaultParent)
Get parent folder of specified path.

Parameters:
pPath - file path
pDefaultParent - default parent file path if no parent

ensureParentFolder

public static final void ensureParentFolder(java.io.File pFile)
                                     throws java.io.IOException
Ensure parent folder exists

Throws:
java.io.IOException

ensureFolder

public static final void ensureFolder(java.io.File pFile)
                               throws java.io.IOException
Ensure folder exists

Throws:
java.io.IOException

getExtension

public static final java.lang.String getExtension(java.lang.String pFileName)
get extension suffix from file name


removeExtension

public static final java.lang.String removeExtension(java.lang.String pFileName)
remove extension suffix from file name


findFile

public static java.io.File findFile(java.lang.String pPathRef)
                             throws java.lang.Exception
Find a file in the classpath.

Parameters:
pPathRef - relative path reference
Throws:
java.lang.Exception

recursiveSearch

public static java.io.File[] recursiveSearch(java.io.File pRootFolder,
                                             FileUtil.FileNameFilter pFileNameFilter)
                                      throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2000-2002 Richard Rodger