Package org.rauschig.jarchivelib
Class IOUtils
- java.lang.Object
-
- org.rauschig.jarchivelib.IOUtils
-
public final class IOUtils extends java.lang.ObjectUtility class for I/O operations.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcloseQuietly(java.io.Closeable closeable)Null-safe method that callsCloseable.close()and chokes the IOException.static voidcopy(java.io.InputStream source, java.io.File destination)Copies the content of an InputStream into a destination File.static longcopy(java.io.InputStream input, java.io.OutputStream output)Copies the content of a InputStream into an OutputStream.static longcopy(java.io.InputStream input, java.io.OutputStream output, int buffersize)Copies the entire content of the given InputStream into the given OutputStream.static java.io.File[]filesContainedIn(java.io.File source)Given a source File, return its direct descendants if the File is a directory.static java.lang.StringrelativePath(java.io.File root, java.io.File node)Computes the path name of a file node relative to a given root node.static voidrequireDirectory(java.io.File destination)Makes sure that the givenFileis either a writable directory, or that it does not exist and a directory can be created at its path.
-
-
-
Method Detail
-
copy
public static void copy(java.io.InputStream source, java.io.File destination) throws java.io.IOExceptionCopies the content of an InputStream into a destination File.- Parameters:
source- the InputStream to copydestination- the target File- Throws:
java.io.IOException- if an error occurs
-
copy
public static long copy(java.io.InputStream input, java.io.OutputStream output) throws java.io.IOExceptionCopies the content of a InputStream into an OutputStream. Uses a default buffer size of 8024 bytes.- Parameters:
input- the InputStream to copyoutput- the target Stream- Returns:
- the amount of bytes written
- Throws:
java.io.IOException- if an error occurs
-
copy
public static long copy(java.io.InputStream input, java.io.OutputStream output, int buffersize) throws java.io.IOExceptionCopies the entire content of the given InputStream into the given OutputStream.- Parameters:
input- the InputStream to copyoutput- the target Streambuffersize- the buffer size to use- Returns:
- the amount of bytes written
- Throws:
java.io.IOException- if an error occurs
-
relativePath
public static java.lang.String relativePath(java.io.File root, java.io.File node) throws java.io.IOExceptionComputes the path name of a file node relative to a given root node.
If the root is/home/cdlflex/custom-ahyand the given node is/home/cdlflex/custom-ahy/assembly/pom.xml, the returned path name will beassembly/pom.xml.- Parameters:
root- the parent nodenode- the file node to compute the relative path for- Returns:
- the path of
noderelative toroot - Throws:
java.io.IOException- when an I/O error occurs during resolving the canonical path of the files
-
requireDirectory
public static void requireDirectory(java.io.File destination) throws java.io.IOException, java.lang.IllegalArgumentExceptionMakes sure that the givenFileis either a writable directory, or that it does not exist and a directory can be created at its path.
Will throw an exception if the givenFileis actually an existing file, or the directory is not writable- Parameters:
destination- the directory which to ensure its existence for- Throws:
java.io.IOException- if an I/O error occurs e.g. when attempting to create the destination directoryjava.lang.IllegalArgumentException- if the destination is an existing file, or the directory is not writable
-
closeQuietly
public static void closeQuietly(java.io.Closeable closeable)
Null-safe method that callsCloseable.close()and chokes the IOException.- Parameters:
closeable- the object to close
-
filesContainedIn
public static java.io.File[] filesContainedIn(java.io.File source)
Given a source File, return its direct descendants if the File is a directory. Otherwise return the File itself.- Parameters:
source- File or folder to be examined- Returns:
- a File[] array containing the files inside this folder, or a size-1 array containing the file itself.
-
-