com.atlassian.core.util
Class FileUtils

java.lang.Object
  extended bycom.atlassian.core.util.FileUtils

public class FileUtils
extends java.lang.Object


Constructor Summary
FileUtils()
           
 
Method Summary
static int copy(java.io.InputStream input, java.io.OutputStream output)
          Copy bytes from an InputStream to an OutputStream.
static int copy(java.io.InputStream input, java.io.OutputStream output, int bufferSize)
          Copy bytes from an InputStream to an OutputStream.
static void copyDirectory(java.io.File srcDir, java.io.File destDir)
          Copies all files from srcDir to destDir.
static void copyDirectory(java.io.File srcDir, java.io.File destDir, boolean overwrite)
           
static void copyFile(java.io.File srcFile, java.io.File destFile)
          Copy file from source to destination.
static void copyFile(java.io.File srcFile, java.io.File destFile, boolean overwrite)
           
static void copyFile(java.io.InputStream srcStream, java.io.File destFile)
           
static void copyFile(java.io.InputStream srcStream, java.io.File destFile, boolean overwrite)
           
static void createZipFile(java.io.File baseDir, java.io.File zipFile)
          Create a zip file of a given directory.
static boolean deleteDir(java.io.File dir)
          safely performs a recursive delete on a directory
static void ensureFileAndPathExist(java.io.File file)
          Check that a given file and its parent directories exist - will create blank file and all directories if necessary.
static java.lang.String getInputStreamTextContent(java.io.InputStream is)
          Get the contents of an inputstream as a String.
static java.lang.String getResourceContent(javax.servlet.http.HttpServletRequest req, java.lang.String resource)
          Get the contents of a servlet context resource as a String.
static java.lang.String getResourceContent(java.lang.String resource)
          Get the contents of a classpath resource as a String.
static boolean moveDir(java.io.File dirName, java.io.File destDir)
          move a directory with all it's children into another directory if destination directory already exists, it will be deleted.
static java.util.List readResourcesAsList(java.lang.String resource)
          Get the contents of a resource as a list, one line representing one list item.
static void recursiveDelete(java.io.File file)
          Recursively delete everything beneath file then delete dir.
static void saveTextFile(java.lang.String stringContent, java.io.File destFile)
          Writes text to the nominated file.
static void shutdownStream(java.io.InputStream input)
          Unconditionally close an InputStream.
static void shutdownStream(java.io.OutputStream output)
          Unconditionally close an OutputStream.
 
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

copy

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

Parameters:
input - the InputStream to read from
output - the OutputStream to write to
Returns:
the number of bytes copied
Throws:
java.io.IOException - In case of an I/O problem

copy

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

Parameters:
input - the InputStream to read from
output - the OutputStream to write to
bufferSize - Size of internal buffer to use.
Returns:
the number of bytes copied
Throws:
java.io.IOException - In case of an I/O problem

shutdownStream

public static void shutdownStream(java.io.OutputStream output)
Unconditionally close an OutputStream. Equivalent to OutputStream.close(), except any exceptions will be ignored.

Parameters:
output - A (possibly null) OutputStream

shutdownStream

public static void shutdownStream(java.io.InputStream input)
Unconditionally close an InputStream. Equivalent to InputStream.close(), except any exceptions will be ignored.

Parameters:
input - A (possibly null) InputStream

deleteDir

public static boolean deleteDir(java.io.File dir)
safely performs a recursive delete on a directory

Parameters:
dir -

recursiveDelete

public static void recursiveDelete(java.io.File file)
Recursively delete everything beneath file then delete dir.


getResourceContent

public static java.lang.String getResourceContent(java.lang.String resource)
Get the contents of a classpath resource as a String.


getResourceContent

public static java.lang.String getResourceContent(javax.servlet.http.HttpServletRequest req,
                                                  java.lang.String resource)
Get the contents of a servlet context resource as a String.


getInputStreamTextContent

public static java.lang.String getInputStreamTextContent(java.io.InputStream is)
Get the contents of an inputstream as a String.


saveTextFile

public static void saveTextFile(java.lang.String stringContent,
                                java.io.File destFile)
                         throws java.io.IOException
Writes text to the nominated file. If this file already exists, its content will be overwritten

Parameters:
stringContent -
destFile -
Throws:
java.io.IOException

ensureFileAndPathExist

public static void ensureFileAndPathExist(java.io.File file)
                                   throws java.io.IOException
Check that a given file and its parent directories exist - will create blank file and all directories if necessary.

Throws:
java.io.IOException

moveDir

public static boolean moveDir(java.io.File dirName,
                              java.io.File destDir)
move a directory with all it's children into another directory if destination directory already exists, it will be deleted. e.g. rename c:/foo/bar to c:/fooz/bar

Parameters:
dirName -
destDir -

createZipFile

public static void createZipFile(java.io.File baseDir,
                                 java.io.File zipFile)
                          throws java.lang.Exception
Create a zip file of a given directory.

Throws:
java.lang.Exception

readResourcesAsList

public static java.util.List readResourcesAsList(java.lang.String resource)
Get the contents of a resource as a list, one line representing one list item.

Note: lines starting with # are deemed to be comments and not included.


copyDirectory

public static void copyDirectory(java.io.File srcDir,
                                 java.io.File destDir)
                          throws java.io.IOException
Copies all files from srcDir to destDir. Currently it just copies the files at te root, it's not recursive.

Throws:
java.io.IOException

copyDirectory

public static void copyDirectory(java.io.File srcDir,
                                 java.io.File destDir,
                                 boolean overwrite)
                          throws java.io.IOException
Throws:
java.io.IOException

copyFile

public static void copyFile(java.io.File srcFile,
                            java.io.File destFile)
                     throws java.io.IOException
Copy file from source to destination. The directories up to destination will be created if they don't already exist. destination will be overwritten if it already exists.

Parameters:
srcFile - An existing non-directory File to copy bytes from.
destFile - A non-directory File to write bytes to (possibly overwriting).
Throws:
java.io.IOException - if source does not exist, destination cannot be written to, or an IO error occurs during copying.

copyFile

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

copyFile

public static void copyFile(java.io.InputStream srcStream,
                            java.io.File destFile)
                     throws java.io.IOException
Throws:
java.io.IOException

copyFile

public static void copyFile(java.io.InputStream srcStream,
                            java.io.File destFile,
                            boolean overwrite)
                     throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2008 Atlassian Pty Ltd. All Rights Reserved.