org.wso2.carbon.server.util
Class FileUtils

java.lang.Object
  extended by org.wso2.carbon.server.util.FileUtils

public class FileUtils
extends Object

taken from the commons file utils class. we didnt want to use the library. hence copied the source


Constructor Summary
FileUtils()
           
 
Method Summary
static void closeQuietly(InputStream input)
          Unconditionally close an InputStream.
static void closeQuietly(OutputStream output)
          Unconditionally close an OutputStream.
static int copy(InputStream input, OutputStream output)
          Copy bytes from an InputStream to an OutputStream.
static void copyDirectory(File srcDir, File destDir)
          Copies a whole directory to a new location preserving the file dates.
static void copyDirectory(File srcDir, File destDir, boolean preserveFileDate)
          Copies a whole directory to a new location.
static void copyFile(File srcFile, File destFile, boolean preserveFileDate)
          Copy file method.
static boolean deleteDir(File dir)
          Deletes all files and subdirectories under dir.
static File getFile(File parentFile, String fileName)
           
static Map<String,String> readJarsWithMD5(BufferedReader bufferedReader)
           
static List<String> readLinesToList(BufferedReader bufferedReader)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtils

public FileUtils()
Method Detail

copyDirectory

public static void copyDirectory(File srcDir,
                                 File destDir)
                          throws IOException
Copies a whole directory to a new location preserving the file dates.

This method copies the specified directory and all its child directories and files to the specified destination. The destination is the new location and name of the directory.

The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.

Parameters:
srcDir - an existing directory to copy, must not be null
destDir - the new directory, must not be null
Throws:
NullPointerException - if source or destination is null
IOException - if source or destination is invalid
Since:
Commons IO 1.1

copyDirectory

public static void copyDirectory(File srcDir,
                                 File destDir,
                                 boolean preserveFileDate)
                          throws IOException
Copies a whole directory to a new location.

This method copies the contents of the specified source directory to within the specified destination directory.

The destination directory is created if it does not exist. If the destination directory did exist, then this method merges the source with the destination, with the source taking precedence.

Parameters:
srcDir - an existing directory to copy, must not be null
destDir - the new directory, must not be null
preserveFileDate - true if the file date of the copy should be the same as the original
Throws:
NullPointerException - if source or destination is null
IOException - if source or destination is invalid
Since:
Commons IO 1.1

copyFile

public static void copyFile(File srcFile,
                            File destFile,
                            boolean preserveFileDate)
                     throws IOException
Copy file method.

Parameters:
srcFile - the validated source file, not null
destFile - the validated destination file, not null
preserveFileDate - whether to preserve the file date
Throws:
IOException - if an error occurs

closeQuietly

public static void closeQuietly(OutputStream output)
Unconditionally close an OutputStream.

Equivalent to OutputStream.close(), except any exceptions will be ignored. This is typically used in finally blocks.

Parameters:
output - the OutputStream to close, may be null or already closed

closeQuietly

public static void closeQuietly(InputStream input)
Unconditionally close an InputStream.

Equivalent to InputStream.close(), except any exceptions will be ignored. This is typically used in finally blocks.

Parameters:
input - the InputStream to close, may be null or already closed

copy

public static int copy(InputStream input,
                       OutputStream output)
                throws IOException
Copy bytes from an InputStream to an OutputStream.

This method buffers the input internally, so there is no need to use a BufferedInputStream.

Parameters:
input - the InputStream to read from
output - the OutputStream to write to
Returns:
the number of bytes copied
Throws:
NullPointerException - if the input or output is null
IOException - if an I/O error occurs
Since:
Commons IO 1.1

deleteDir

public static boolean deleteDir(File dir)
Deletes all files and subdirectories under dir. Returns true if all deletions were successful. If a deletion fails, the method stops attempting to delete and returns false.

Parameters:
dir - The directory to be deleted
Returns:
true if the directory and its descendents were deleted

getFile

public static File getFile(File parentFile,
                           String fileName)

readLinesToList

public static List<String> readLinesToList(BufferedReader bufferedReader)
                                    throws IOException
Throws:
IOException

readJarsWithMD5

public static Map<String,String> readJarsWithMD5(BufferedReader bufferedReader)
                                          throws IOException
Throws:
IOException


Copyright © 2014 WSO2 Inc. All rights reserved.