public class

FileUtils

extends Object
java.lang.Object
   ↳ com.atlassian.core.util.FileUtils

Summary

Public Constructors
FileUtils()
Public Methods
static int copy(InputStream input, OutputStream output, int bufferSize)
This method is deprecated. since 3.18 use copy(InputStream, OutputStream)
static int copy(InputStream input, OutputStream output)
This method is deprecated. since 3.18 use copy(InputStream, OutputStream)
static void copyDirectory(File srcDir, File destDir, boolean overwrite)
static void copyDirectory(File srcDir, File destDir)
Copies all files from srcDir to destDir.
static void copyFile(InputStream srcStream, File destFile, boolean overwrite)
Save an input stream to a file, optionally overwriting the file if is exists.
static void copyFile(InputStream srcStream, File destFile)
Save an input stream to a file.
static void copyFile(File srcFile, File destFile, boolean overwrite)
Copies a file to a new location, optionally overwriting an existing file in the new location.
static void copyFile(File srcFile, File destFile)
Copy file from source to destination.
static void createZipFile(File baseDir, File zipFile)
Create a zip file of a given directory.
static boolean deleteDir(File dir)
safely performs a recursive delete on a directory
static void ensureFileAndPathExist(File file)
Check that a given file and its parent directories exist - will create blank file and all directories if necessary.
static String getInputStreamTextContent(InputStream is)
This method is deprecated. since 3.18 use toString(InputStream, String)
static String getResourceContent(HttpServletRequest req, String resource)
Get the contents of a servlet context resource as a String.
static String getResourceContent(String resource)
Get the contents of a classpath resource as a String.
static boolean moveDir(File dirName, File destDir)
move a directory with all it's children into another directory if destination directory already exists, it will be deleted.
static List readResourcesAsList(String resource)
Get the contents of a resource as a list, one line representing one list item.
static void recursiveDelete(File file)
Recursively delete everything beneath file then delete dir.
static void saveTextFile(String stringContent, File destFile)
Writes text to the nominated file.
static void shutdownStream(OutputStream output)
This method is deprecated. since 3.18 use closeQuietly(OutputStream)
static void shutdownStream(InputStream input)
This method is deprecated. since 3.18 use closeQuietly(OutputStream)
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public FileUtils ()

Public Methods

public static int copy (InputStream input, OutputStream output, int bufferSize)

This method is deprecated.
since 3.18 use 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
IOException In case of an I/O problem

public static int copy (InputStream input, OutputStream output)

This method is deprecated.
since 3.18 use 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
IOException In case of an I/O problem

public static void copyDirectory (File srcDir, File destDir, boolean overwrite)

Throws
IOException

public static void copyDirectory (File srcDir, File destDir)

Copies all files from srcDir to destDir. Currently it just copies the files at te root, it's not recursive.

Throws
IOException

public static void copyFile (InputStream srcStream, File destFile, boolean overwrite)

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
IOException if a problem occurs writing to the file, or the file exists and is read-only

public static void copyFile (InputStream srcStream, File destFile)

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
IOException if a problem occurs writing to the file, or the file exists and is read-only

public static void copyFile (File srcFile, File destFile, boolean overwrite)

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
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

public static void copyFile (File srcFile, File destFile)

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
IOException if source does not exist, destination cannot be written to, or an IO error occurs during copying.

public static void createZipFile (File baseDir, File zipFile)

Create a zip file of a given directory.

Throws
Exception

public static boolean deleteDir (File dir)

safely performs a recursive delete on a directory

public static void ensureFileAndPathExist (File file)

Check that a given file and its parent directories exist - will create blank file and all directories if necessary.

Throws
IOException

public static String getInputStreamTextContent (InputStream is)

This method is deprecated.
since 3.18 use toString(InputStream, String)

Get the contents of an inputstream as a String.

public static String getResourceContent (HttpServletRequest req, 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.

public static String getResourceContent (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.

public static boolean moveDir (File dirName, 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

public static List readResourcesAsList (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.

public static void recursiveDelete (File file)

Recursively delete everything beneath file then delete dir.

public static void saveTextFile (String stringContent, File destFile)

Writes text to the nominated file. If this file already exists, its content will be overwritten

Throws
IOException

public static void shutdownStream (OutputStream output)

This method is deprecated.
since 3.18 use closeQuietly(OutputStream)

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

Parameters
output A (possibly null) OutputStream

public static void shutdownStream (InputStream input)

This method is deprecated.
since 3.18 use closeQuietly(OutputStream)

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

Parameters
input A (possibly null) InputStream
Feedback?
View cookie preferences