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)
          Deprecated. since 3.18 use IOUtils.copy(InputStream, OutputStream)
static int copy(java.io.InputStream input, java.io.OutputStream output, int bufferSize)
          Deprecated. since 3.18 use IOUtils.copy(InputStream, 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)
          Copies a file to a new location, optionally overwriting an existing file in the new location.
static void copyFile(java.io.InputStream srcStream, java.io.File destFile)
          Save an input stream to a file.
static void copyFile(java.io.InputStream srcStream, java.io.File destFile, boolean overwrite)
          Save an input stream to a file, optionally overwriting the file if is exists.
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)
          Deprecated. since 3.18 use IOUtils.toString(InputStream, 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)
          Deprecated. since 3.18 use IOUtils.closeQuietly(OutputStream)
static void shutdownStream(java.io.OutputStream output)
          Deprecated. since 3.18 use IOUtils.closeQuietly(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
Deprecated. since 3.18 use IOUtils.copy(InputStream, OutputStream)

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
See Also:
IOUtils.copy(InputStream, OutputStream)

copy

public static int copy(java.io.InputStream input,
                       java.io.OutputStream output,
                       int bufferSize)
                throws java.io.IOException
Deprecated. since 3.18 use IOUtils.copy(InputStream, OutputStream)

Copy bytes from an InputStream to an OutputStream.

Parameters:
input - the InputStream to read from
output - the OutputStream to write to
bufferSize - ignored
Returns:
the number of bytes copied
Throws:
java.io.IOException - In case of an I/O problem
See Also:
IOUtils.copy(InputStream, OutputStream)

shutdownStream

public static void shutdownStream(java.io.OutputStream output)
Deprecated. since 3.18 use IOUtils.closeQuietly(OutputStream)

Unconditionally close an OutputStream. Equivalent to OutputStream.close(), except any exceptions will be ignored.

Parameters:
output - A (possibly null) OutputStream
See Also:
IOUtils.closeQuietly(OutputStream)

shutdownStream

public static void shutdownStream(java.io.InputStream input)
Deprecated. since 3.18 use IOUtils.closeQuietly(OutputStream)

Unconditionally close an InputStream. Equivalent to InputStream.close(), except any exceptions will be ignored.

Parameters:
input - A (possibly null) InputStream
See Also:
IOUtils.closeQuietly(OutputStream)

deleteDir

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


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. Returns null if the resource cannot be found or an error occurs reading the resource.


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. Returns an empty String ("") if the resource cannot be found or an error occurs reading the resource.


getInputStreamTextContent

public static java.lang.String getInputStreamTextContent(java.io.InputStream is)
Deprecated. since 3.18 use IOUtils.toString(InputStream, String)

Get the contents of an inputstream as a String.

See Also:
IOUtils.toString(InputStream, 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

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


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
Copies a file to a new location, optionally overwriting an existing file in the new location.

If overwrite is false and the file already exists, this method logs a warning and returns. If the parent directory of the destination file does not exist, it is created.

If the source file does not exist, this method throws an IOException. If the length of the two files are not the same after the copy completes,

Parameters:
srcFile - the file to copy
destFile - the file to be saved, which can already exist if overwrite is set
overwrite - true if an existing file should be overwritten
Throws:
java.io.IOException - if the source file does not exist, a problem occurs writing to the destination file, or the destination file exists and is read-only

copyFile

public static void copyFile(java.io.InputStream srcStream,
                            java.io.File destFile)
                     throws java.io.IOException
Save an input stream to a file. The client is responsible for opening and closing the provided InputStream. If the file already exists, a warning will be logged and the method will not ovewrite it.

If the parent directory of the destination file does not exist, it is created.

Parameters:
srcStream - the input stream to save
destFile - the file to be saved
Throws:
java.io.IOException - if a problem occurs writing to the file, or the file exists and is read-only

copyFile

public static void copyFile(java.io.InputStream srcStream,
                            java.io.File destFile,
                            boolean overwrite)
                     throws java.io.IOException
Save an input stream to a file, optionally overwriting the file if is exists. The client is responsible for opening and closing the provided InputStream.

If overwrite is false and the file already exists, this method logs a warning and returns. If the parent directory of the destination file does not exist, it is created.

Parameters:
srcStream - the input stream to save
destFile - the file to be saved, which can already exist if overwrite is set
overwrite - true if an existing file should be overwritten
Throws:
java.io.IOException - if a problem occurs writing to the file, or the file exists and is read-only


Copyright © 2008 Atlassian Pty Ltd. All Rights Reserved.