com.myJava.file
Class FileTool

java.lang.Object
  extended by com.myJava.file.FileTool

public class FileTool
extends java.lang.Object

File handling utility

Author:
Olivier PETRUCCI

Areca Build ID : 7299034069467778562

Method Summary
 boolean checkContains(java.io.File baseFile, java.lang.String searchString)
          Return true if the file contains the string passed as argument.
 void copy(java.io.File sourceFileOrDirectory, java.io.File targetParentDirectory)
           
 void copy(java.io.File sourceFileOrDirectory, java.io.File targetParentDirectory, TaskMonitor monitor, OutputStreamListener listener)
          Copy the source file or directory in the parent destination.
 void copy(java.io.InputStream inStream, java.io.OutputStream outStream, boolean closeInputStream, boolean closeOutputStream)
           
 void copy(java.io.InputStream inStream, java.io.OutputStream outStream, boolean closeInputStream, boolean closeOutputStream, TaskMonitor monitor)
          Copy inStream into outStream.
 void copyDirectoryContent(java.io.File sourceDirectory, java.io.File targetDirectory, TaskMonitor monitor, OutputStreamListener listener)
          Copy the content of sourceDirectory into targetDirectory
Example :
- sourceDirectory = c:\toto\sourceDir
- targetDirectory = d:\myDir

The content of c:\toto\sourceDir will be copied into d:\myDir
 void copyFile(java.io.File sourceFile, java.io.File targetDirectory, java.lang.String targetShortFileName, TaskMonitor monitor, OutputStreamListener listener)
          Copy the file to the parent target directory, with the short name passed as argument.
 void copyFile(java.io.File sourceFile, java.io.OutputStream outStream, boolean closeStream, TaskMonitor monitor)
          Copy the source file to the target outputstream
 void createDir(java.io.File directory)
          Recursive creation of a directory
 void createFile(java.io.File destinationFile, java.lang.String content)
           
 void delete(java.io.File fileOrDirectory, boolean waitForAvailability)
           
 void delete(java.io.File fileOrDirectory, boolean waitForAvailability, long deletionDelay, TaskMonitor monitor)
          Delete the directory / file and all its content.
 void delete(java.io.File fileOrDirectory, boolean waitForAvailability, TaskMonitor monitor)
           
 java.io.File generateNewWorkingFile(java.lang.String subdir, java.lang.String prefix, boolean registerDeleteHook)
          Return a new - non existing - temporary file or directory in the user's main temporary directory.
 java.lang.String getFileContent(java.io.File sourceFile)
          Return the content of the file as a String.
 java.lang.String[] getFileRows(java.io.File sourceFile)
          Return the content of the file as a String array (one string by line).
 java.lang.String getFirstRow(java.io.InputStream stream, java.lang.String encoding)
           
 java.lang.String getInputStreamContent(java.io.InputStream inStream, boolean closeStreamOnExit)
           
 java.lang.String getInputStreamContent(java.io.InputStream inStream, java.lang.String encoding, boolean closeStreamOnExit)
          Return the content of the inputStream as a String.
 java.lang.String[] getInputStreamRows(java.io.InputStream inStream, java.lang.String encoding, boolean closeStreamOnExit)
          Return the content of the inputStream as a String array (one string by line).
static FileTool getInstance()
           
 long getSize(java.io.File fileOrDirectory)
          Return the file's or directory's total length.
 byte[] hashFileContent(java.io.File target, TaskMonitor monitor)
          Read the file's content and compute a hash code
 boolean isParentOf(java.io.File parent, java.io.File child)
          Return true if "parent" contains or equals to "child"
 void replaceInFile(java.io.File baseFile, java.lang.String searchString, java.lang.String newString)
          Replace all occurences or searchstring by newstring in basefile
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static FileTool getInstance()

copy

public void copy(java.io.File sourceFileOrDirectory,
                 java.io.File targetParentDirectory)
          throws java.io.IOException
Throws:
java.io.IOException

copy

public void copy(java.io.File sourceFileOrDirectory,
                 java.io.File targetParentDirectory,
                 TaskMonitor monitor,
                 OutputStreamListener listener)
          throws java.io.IOException,
                 TaskCancelledException
Copy the source file or directory in the parent destination.

Throws:
java.io.IOException
TaskCancelledException

copyFile

public void copyFile(java.io.File sourceFile,
                     java.io.File targetDirectory,
                     java.lang.String targetShortFileName,
                     TaskMonitor monitor,
                     OutputStreamListener listener)
              throws java.io.IOException,
                     TaskCancelledException
Copy the file to the parent target directory, with the short name passed as argument.

Throws:
java.io.IOException
TaskCancelledException

copyFile

public void copyFile(java.io.File sourceFile,
                     java.io.OutputStream outStream,
                     boolean closeStream,
                     TaskMonitor monitor)
              throws java.io.IOException,
                     TaskCancelledException
Copy the source file to the target outputstream

Throws:
java.io.IOException
TaskCancelledException

copy

public void copy(java.io.InputStream inStream,
                 java.io.OutputStream outStream,
                 boolean closeInputStream,
                 boolean closeOutputStream)
          throws java.io.IOException
Throws:
java.io.IOException

copy

public void copy(java.io.InputStream inStream,
                 java.io.OutputStream outStream,
                 boolean closeInputStream,
                 boolean closeOutputStream,
                 TaskMonitor monitor)
          throws java.io.IOException,
                 TaskCancelledException
Copy inStream into outStream.

Throws:
java.io.IOException
TaskCancelledException

copyDirectoryContent

public void copyDirectoryContent(java.io.File sourceDirectory,
                                 java.io.File targetDirectory,
                                 TaskMonitor monitor,
                                 OutputStreamListener listener)
                          throws java.io.IOException,
                                 TaskCancelledException
Copy the content of sourceDirectory into targetDirectory
Example :
- sourceDirectory = c:\toto\sourceDir
- targetDirectory = d:\myDir

The content of c:\toto\sourceDir will be copied into d:\myDir

Throws:
java.io.IOException
TaskCancelledException

delete

public void delete(java.io.File fileOrDirectory,
                   boolean waitForAvailability,
                   long deletionDelay,
                   TaskMonitor monitor)
            throws java.io.IOException,
                   TaskCancelledException
Delete the directory / file and all its content.
If "waitForAvailability" is true, the process will wait - for each file or directory - until it is available. (the thread will be paused) and will make an attempt every "deletionDelay" milliseconds.

Throws:
java.io.IOException
TaskCancelledException

delete

public void delete(java.io.File fileOrDirectory,
                   boolean waitForAvailability)
            throws java.io.IOException
Throws:
java.io.IOException

delete

public void delete(java.io.File fileOrDirectory,
                   boolean waitForAvailability,
                   TaskMonitor monitor)
            throws java.io.IOException,
                   TaskCancelledException
Throws:
java.io.IOException
TaskCancelledException

createFile

public void createFile(java.io.File destinationFile,
                       java.lang.String content)
                throws java.io.IOException
Throws:
java.io.IOException

getFileContent

public java.lang.String getFileContent(java.io.File sourceFile)
                                throws java.io.IOException
Return the content of the file as a String.

Throws:
java.io.IOException

getInputStreamContent

public java.lang.String getInputStreamContent(java.io.InputStream inStream,
                                              boolean closeStreamOnExit)
                                       throws java.io.IOException
Throws:
java.io.IOException

getInputStreamContent

public java.lang.String getInputStreamContent(java.io.InputStream inStream,
                                              java.lang.String encoding,
                                              boolean closeStreamOnExit)
                                       throws java.io.IOException
Return the content of the inputStream as a String.

Throws:
java.io.IOException

getFileRows

public java.lang.String[] getFileRows(java.io.File sourceFile)
                               throws java.io.IOException
Return the content of the file as a String array (one string by line).
The lines are trimmed and empty lines are ignored.

Throws:
java.io.IOException

getInputStreamRows

public java.lang.String[] getInputStreamRows(java.io.InputStream inStream,
                                             java.lang.String encoding,
                                             boolean closeStreamOnExit)
                                      throws java.io.IOException
Return the content of the inputStream as a String array (one string by line).
The lines are trimmed and empty lines are ignored.

Throws:
java.io.IOException

getFirstRow

public java.lang.String getFirstRow(java.io.InputStream stream,
                                    java.lang.String encoding)
                             throws java.io.IOException
Throws:
java.io.IOException

replaceInFile

public void replaceInFile(java.io.File baseFile,
                          java.lang.String searchString,
                          java.lang.String newString)
                   throws java.io.IOException
Replace all occurences or searchstring by newstring in basefile

Throws:
java.io.IOException

checkContains

public boolean checkContains(java.io.File baseFile,
                             java.lang.String searchString)
                      throws java.io.IOException
Return true if the file contains the string passed as argument.

Throws:
java.io.IOException

isParentOf

public boolean isParentOf(java.io.File parent,
                          java.io.File child)
Return true if "parent" contains or equals to "child"


getSize

public long getSize(java.io.File fileOrDirectory)
             throws java.io.FileNotFoundException
Return the file's or directory's total length.

Throws:
java.io.FileNotFoundException

createDir

public void createDir(java.io.File directory)
               throws java.io.IOException
Recursive creation of a directory

Throws:
java.io.IOException

hashFileContent

public byte[] hashFileContent(java.io.File target,
                              TaskMonitor monitor)
                       throws java.io.IOException,
                              java.security.NoSuchAlgorithmException,
                              TaskCancelledException
Read the file's content and compute a hash code

Throws:
java.io.IOException
java.security.NoSuchAlgorithmException
TaskCancelledException

generateNewWorkingFile

public java.io.File generateNewWorkingFile(java.lang.String subdir,
                                           java.lang.String prefix,
                                           boolean registerDeleteHook)
                                    throws java.io.IOException
Return a new - non existing - temporary file or directory in the user's main temporary directory.

This method also registers a security shutdown hook that destroys the temporary file.
However, it is strongly advised to handle the created file's destruction explicitly as soon as it is not needed anymore and avoid using hooks

Throws:
java.io.IOException