org.browsecode.helpers
Class FileHelper

java.lang.Object
  extended by org.browsecode.helpers.FileHelper

public class FileHelper
extends java.lang.Object


Constructor Summary
FileHelper()
           
 
Method Summary
static void copyDir(java.io.File srcDir, java.io.File dstDir, boolean overwrite)
          Utility method to copy one directory to another via NIO.
static void copyFile(java.io.File inputFile, java.io.File outputFile, boolean overwrite)
           
static boolean deleteDir(java.io.File dir)
          Utility method to recursively delete an entire directory (a la "rm -rf").
static java.lang.String getTextFromFile(java.io.File file)
           
static java.lang.String getTextFromStream(java.io.InputStream inputStream)
           
static boolean saveTextToFile(java.io.File file, java.lang.String text)
           
static java.lang.Exception unzip(java.io.InputStream inputStream, java.io.File unzipTo)
           
static java.lang.Exception unzip(java.io.InputStream inputStream, java.io.File unzipTo, java.lang.String[] filesToIgnore)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileHelper

public FileHelper()
Method Detail

getTextFromFile

public static java.lang.String getTextFromFile(java.io.File file)

getTextFromStream

public static java.lang.String getTextFromStream(java.io.InputStream inputStream)

saveTextToFile

public static boolean saveTextToFile(java.io.File file,
                                     java.lang.String text)

unzip

public static java.lang.Exception unzip(java.io.InputStream inputStream,
                                        java.io.File unzipTo,
                                        java.lang.String[] filesToIgnore)
Parameters:
inputStream -
unzipTo -
filesToIgnore - files that should not be unzipped. Directories that should not be unzipped should end in "/", so it's clear that they are directories (otherwise, the files in them will be unzipped).
Returns:

unzip

public static java.lang.Exception unzip(java.io.InputStream inputStream,
                                        java.io.File unzipTo)

copyDir

public static void copyDir(java.io.File srcDir,
                           java.io.File dstDir,
                           boolean overwrite)
                    throws java.io.IOException
Utility method to copy one directory to another via NIO. If the destination directory doesn't exist, it will be created. Duplicate files in the destination directory will be overwritten if overwrite is true. The existing contents of the destination will not be deleted unless overwritten. NOTE: This method is not safe for directory structures containing cycles.

Parameters:
srcDir - the source directory
dstDir - the destination directory
overwrite - if true, duplicate files will be overwritten
Throws:
java.io.IOException

copyFile

public static void copyFile(java.io.File inputFile,
                            java.io.File outputFile,
                            boolean overwrite)
                     throws java.io.IOException
Throws:
java.io.IOException

deleteDir

public static boolean deleteDir(java.io.File dir)
                         throws java.io.IOException
Utility method to recursively delete an entire directory (a la "rm -rf").

Parameters:
dir - the directory to delete
Throws:
java.io.IOException - if there is any problem with file manipulation
java.lang.IllegalArgumentException - if dir is not a directory