edu.rice.cs.plt.io
Class IOUtil

java.lang.Object
  extended by edu.rice.cs.plt.io.IOUtil

public final class IOUtil
extends Object

Provides additional operations on Files, InputStreams, OutputStreams, Readers, and Writers not defined in the java.io package.


Field Summary
static FilePredicate ALWAYS_ACCEPT
          A FilePredicate that always accepts.
static FilePredicate ALWAYS_REJECT
          A FilePredicate that always rejects.
static Lambda<String,File> FILE_FACTORY
          A factory for Files based on a String filename.
static FilePredicate IS_DIRECTORY
          A predicate that tests whether attemptIsDirectory(java.io.File) holds for a file.
static FilePredicate IS_FILE
          A predicate that tests whether attemptIsFile(java.io.File) holds for a file.
static File WORKING_DIRECTORY
          The current working directory, used as the base for relative paths.
 
Method Summary
static int adler32Hash(File file)
          Produce an Adler-32 hash for the given file.
static int adler32Hash(InputStream stream)
          Produce an Adler-32 hash for the contents of the given stream.
static FilePredicate and(FileFilter... filters)
          Produce a conjunction of the given FileFilters.
static FilePredicate and(Iterable<? extends FileFilter> filters)
          Produce a conjunction of the given FileFilters.
static BufferedInputStream asBuffered(InputStream in)
          If in is a BufferedInputStream, cast it as such; otherwise, wrap it in a BufferedInputStream.
static BufferedOutputStream asBuffered(OutputStream out)
          If out is a BufferedOutputStream, cast it as such; otherwise, wrap it in a BufferedOutputStream.
static BufferedReader asBuffered(Reader r)
          If r is a BufferedReader, cast it as such; otherwise, wrap it in a BufferedReader.
static BufferedWriter asBuffered(Writer w)
          If w is a BufferedWriter, cast it as such; otherwise, wrap it in a BufferedWriter.
static FilePredicate asFilePredicate(FileFilter filter)
          Define a FilePredicate in terms of a FileFilter (this provides access to predicate operations like and and or).
static FilePredicate asFilePredicate(Predicate<? super File> p)
          Define a FileFilter in terms of a Predicate.
static File attemptAbsoluteFile(File f)
          Make a best attempt at evaluating File.getAbsoluteFile().
static SizedIterable<File> attemptAbsoluteFiles(Iterable<? extends File> files)
          Apply attemptAbsoluteFile(java.io.File) to all files in a list
static File attemptCanonicalFile(File f)
          Make a best attempt at evaluating File.getCanonicalFile().
static SizedIterable<File> attemptCanonicalFiles(Iterable<? extends File> files)
          Apply attemptCanonicalFile(java.io.File) to all files in a list
static boolean attemptCanRead(File f)
          Make a best attempt at evaluating File.canRead().
static boolean attemptCanWrite(File f)
          Make a best attempt at evaluating File.canWrite().
static void attemptClose(Closeable c)
          Attempt to close the given resource, failing silently if an exception occurs.
static boolean attemptCreateNewFile(File f)
          Make a best attempt at invoking File.createNewFile().
static boolean attemptDelete(File f)
          Make a best attempt at invoking File.delete().
static void attemptDeleteOnExit(File f)
          Make a best attempt at invoking File.deleteOnExit().
static boolean attemptExists(File f)
          Make a best attempt at evaluating File.exists().
static boolean attemptIsDirectory(File f)
          Make a best attempt at evaluating File.isDirectory().
static boolean attemptIsFile(File f)
          Make a best attempt at evaluating File.isFile().
static boolean attemptIsHidden(File f)
          Make a best attempt at evaluating File.isHidden().
static long attemptLastModified(File f)
          Make a best attempt at evaluating File.lastModified().
static long attemptLength(File f)
          Make a best attempt at evaluating File.length().
static File[] attemptListFiles(File f)
          Make a best attempt at invoking File.listFiles().
static File[] attemptListFiles(File f, FileFilter filter)
          Make a best attempt at invoking File.listFiles(FileFilter).
static File[] attemptListFiles(File f, FilePredicate filter)
          Make a best attempt at invoking File.listFiles(FileFilter).
static File[] attemptListFiles(File f, Predicate<? super File> filter)
          Make a best attempt at invoking File.listFiles(FileFilter).
static SizedIterable<File> attemptListFilesAsIterable(File f)
          Similar to attemptListFiles(File), but returns a non-null Iterable rather than an array.
static SizedIterable<File> attemptListFilesAsIterable(File f, FileFilter filter)
          Similar to attemptListFiles(File, FileFilter), but returns a non-null Iterable rather than an array.
static SizedIterable<File> attemptListFilesAsIterable(File f, FilePredicate filter)
          Similar to attemptListFiles(File, FileFilter), but returns a non-null Iterable rather than an array.
static SizedIterable<File> attemptListFilesAsIterable(File f, Predicate<? super File> filter)
          Similar to attemptListFiles(File, FileFilter), but returns a non-null Iterable rather than an array.
static boolean attemptMkdir(File f)
          Make a best attempt at invoking File.mkdir().
static boolean attemptMkdirs(File f)
          Make a best attempt at invoking File.mkdirs().
static boolean attemptMove(File f, File dest)
          Like attemptRenameTo(java.io.File, java.io.File), makes a best attempt at renaming f.
static boolean attemptRenameTo(File f, File dest)
          Make a best attempt at invoking File.renameTo(java.io.File).
static boolean attemptSetLastModified(File f, long time)
          Make a best attempt at invoking File.setLastModified(long).
static boolean attemptSetReadOnly(File f)
          Make a best attempt at invoking File.setReadOnly().
static boolean attemptWriteStringToFile(File file, String text)
          Writes text to the file, overwriting whatever was there.
static boolean attemptWriteStringToFile(File file, String text, boolean append)
          Writes text to the file, ignoring any exceptions that occur.
static File canonicalCase(File f)
          Converts a File to all lowercase in case-insensitive systems; otherwise, returns the file untouched.
static SizedIterable<File> canonicalCases(Iterable<? extends File> files)
          Apply canonicalCase(java.io.File) to all files in a list
static void closeOnExit(Closeable c)
          Register the given resource to be closed on exit.
static void copyFile(File source, File dest)
          Copies the contents of one file into another.
static void copyFile(File source, File dest, byte[] buffer)
          Copies the contents of one file into another, using the given array as an intermediate buffer.
static int copyInputStream(InputStream source, OutputStream dest)
          Write the contents of in to out.
static int copyInputStream(InputStream source, OutputStream dest, byte[] buffer)
          Write the contents of in to out, using the given buffer.
static int copyReader(Reader source, Writer dest)
          Write the contents of in to out.
static int copyReader(Reader source, Writer dest, char[] buffer)
          Write the contents of in to out, using the given buffer.
static int crc32Hash(File file)
          Produce a CRC-32 hash for the given file.
static int crc32Hash(InputStream stream)
          Produce a CRC-32 hash for the contents of the given stream.
static File createAndMarkTempDirectory(String prefix, String suffix)
          Create a temporary directory (named by File.createTempFile(java.lang.String, java.lang.String, java.io.File)) and immediately mark it for deletion.
static File createAndMarkTempDirectory(String prefix, String suffix, File location)
          Create a temporary directory (named by File.createTempFile(java.lang.String, java.lang.String, java.io.File)) and immediately mark it for deletion.
static File createAndMarkTempFile(String prefix, String suffix)
          Create a temporary file in the system temp directory (via File.createTempFile(String, String)) and immediately mark it for deletion
static File createAndMarkTempFile(String prefix, String suffix, File location)
          Create a temporary file in the specified directory (via File.createTempFile(String, String, File)) and immediately mark it for deletion
static void deleteOnExitRecursively(File f)
          Attempt to mark the given File for deletion.
static boolean deleteRecursively(File f)
          Attempt to delete the given File.
protected static int doCopyInputStream(InputStream in, OutputStream out, byte[] buffer)
          Implementation of stream copying for use by DirectInputStream and DirectOutputStream (placed here to avoid code duplication).
protected static int doCopyReader(Reader r, Writer w, char[] buffer)
          Implementation of reader-to-writer copying for use by DirectReader and DirectWriter (placed here to avoid code duplication).
protected static int doWriteFromInputStream(InputStream in, OutputStream out, int bytes, byte[] buffer)
          Implementation of stream-to-stream writing for use by DirectInputStream and DirectOutputStream (placed here to avoid code duplication).
protected static int doWriteFromReader(Reader r, Writer w, int chars, char[] buffer)
          Implementation of reader-to-writer writing for use by DirectReader and DirectWriter (placed here to avoid code duplication).
static Exception ensureSerializable(Exception e)
          Convert the given Exception to a form that will successfully serialize.
static Iterable<?> ensureSerializable(Iterable<?> iter)
          Convert the given (non-null) Iterable to a list of objects that will successfully serialize.
static Object ensureSerializable(Object obj)
          Converts the given object to a form that will successfully serialize.
static Object[] ensureSerializable(Object[] arr)
          Convert the given (non-null) array to an array of objects that will successfully serialize.
static Octet<?,?,?,?,?,?,?,?> ensureSerializable(Octet<?,?,?,?,?,?,?,?> o)
          Apply ensureSerializable() to each of the elements of the given tuple.
static Option<?> ensureSerializable(Option<?> opt)
          Apply ensureSerializable() to the given option value.
static Pair<?,?> ensureSerializable(Pair<?,?> p)
          Apply ensureSerializable() to each of the elements of the given tuple.
static Quad<?,?,?,?> ensureSerializable(Quad<?,?,?,?> q)
          Apply ensureSerializable() to each of the elements of the given tuple.
static Quint<?,?,?,?,?> ensureSerializable(Quint<?,?,?,?,?> q)
          Apply ensureSerializable() to each of the elements of the given tuple.
static RuntimeException ensureSerializable(RuntimeException e)
          Convert the given RuntimeException to a form that will successfully serialize.
static Septet<?,?,?,?,?,?,?> ensureSerializable(Septet<?,?,?,?,?,?,?> s)
          Apply ensureSerializable() to each of the elements of the given tuple.
static Sextet<?,?,?,?,?,?> ensureSerializable(Sextet<?,?,?,?,?,?> s)
          Apply ensureSerializable() to each of the elements of the given tuple.
static Throwable ensureSerializable(Throwable t)
          Convert the given Throwable to a form that will successfully serialize.
static Triple<?,?,?> ensureSerializable(Triple<?,?,?> t)
          Apply ensureSerializable() to each of the elements of the given tuple.
static Tuple ensureSerializable(Tuple t)
          Apply ensureSerializable() to each of the elements of the given tuple.
static Wrapper<?> ensureSerializable(Wrapper<?> w)
          Apply ensureSerializable() to the given wrapped value.
static FilePredicate extensionFilePredicate(String extension)
          Define a FilePredicate that accepts file objects with the given extension (that is, for extension txt, file objects whose canonical-case names (see canonicalCase(java.io.File)) end in .txt).
static FilePredicate fileKey(File f)
          Produce a FilePredicate that acts as a "key" representing the current state of the given file.
static SizedIterable<File> fullPath(File f)
          Create a list of files representing the full path of f.
static SizedIterable<File> getAbsoluteFiles(Iterable<? extends File> files)
          Apply File.getAbsoluteFile() to all files in a list
static SizedIterable<File> getCanonicalFiles(Iterable<? extends File> files)
          Apply File.getCanonicalFile() to all files in a list
static void ignoreSystemErr()
          Ignore subsequent writes to System.err until revertSystemErr() is called.
static void ignoreSystemOut()
          Ignore subsequent writes to System.out until revertSystemOut() is called.
static boolean isMember(File f, File ancestor)
          Determine if the given file is a member (as determined by File.getParentFile()) of another file.
static SizedIterable<File> listFilesRecursively(File f)
          Produce a list of the recursive contents of a file.
static SizedIterable<File> listFilesRecursively(File f, FileFilter filter)
          Produce a list of the recursive contents of a file.
static SizedIterable<File> listFilesRecursively(File f, FileFilter filter, FileFilter recursionFilter)
          Produce a list of the recursive contents of a file.
static SizedIterable<File> listFilesRecursively(File f, FilePredicate filter)
          Produce a list of the recursive contents of a file.
static SizedIterable<File> listFilesRecursively(File f, FilePredicate filter, FilePredicate recursionFilter)
          Produce a list of the recursive contents of a file.
static SizedIterable<File> listFilesRecursively(File f, Predicate<? super File> filter)
          Produce a list of the recursive contents of a file.
static SizedIterable<File> listFilesRecursively(File f, Predicate<? super File> filter, Predicate<? super File> recursionFilter)
          Produce a list of the recursive contents of a file.
static byte[] md5Hash(File file)
          Produce an MD5 hash for the given file.
static byte[] md5Hash(InputStream stream)
          Produce an MD5 hash for the contents of the given stream.
static FilePredicate negate(FileFilter filter)
          Produce the complement of the given FileFilter.
static FilePredicate or(FileFilter... filters)
          Produce a disjunction of the given FileFilters.
static FilePredicate or(Iterable<? extends FileFilter> filters)
          Produce a disjunction of the given FileFilters.
static SizedIterable<File> parsePath(String path)
          Parse a path string -- a list of file names separated by the system-dependent path separator character (':' in Unix, ';' in Windows).
static String pathToString(Iterable<? extends File> path)
          Produce a path string from a list of files.
static Iterator<String> readLines(File file)
          Get the contents of a file as a sequence of lines, accessed via an iterator.
static Iterator<String> readLines(Reader r)
          Get the contents of a reader as a sequence of lines, accessed via an iterator.
static FilePredicate regexCanonicalCaseFilePredicate(String regex)
          Define a FilePredicate that accepts files whose (simple) names in the canonical case (see canonicalCase(java.io.File)) match a regular expression.
static FilePredicate regexFilePredicate(Pattern regex)
          Define a FilePredicate that accepts files whose (simple) names match a regular expression.
static FilePredicate regexFilePredicate(String regex)
          Define a FilePredicate that accepts files whose (simple) names match a regular expression.
static void replaceSystemErr(OutputStream substitute)
          Replace System.err with the given stream and remember the current stream.
static void replaceSystemIn(InputStream substitute)
          Replace System.in with the given stream and remember the current stream.
static void replaceSystemOut(OutputStream substitute)
          Replace System.out with the given stream and remember the current stream.
static void revertSystemErr()
          Set System.err to its value before the last call to replaceSystemErr(java.io.OutputStream).
static void revertSystemIn()
          Set System.in to its value before the last call to replaceSystemIn(java.io.InputStream).
static void revertSystemOut()
          Set System.out to its value before the last call to replaceSystemOut(java.io.OutputStream).
static FilePredicate sameAttributesFilePredicate(File f)
          Define a FilePredicate that only accepts a file with the same attributes as f (at creation time).
static FilePredicate sameContentsFilePredicate(File f)
          Define a FilePredicate that only accepts files with contents matching a CRC-32 hash of f (at creation time).
static FilePredicate sameNameFilePredicate(String name)
          Define a FilePredicate that only accepts files with the given name (where both names are converted to the canonical case; see canonicalCase(java.io.File)).
static FilePredicate samePathFilePredicate(File path)
          Define a FilePredicate that only accepts files with the given path and name (where both paths are converted to the canonical case; see canonicalCase(java.io.File)).
static byte[] sha1Hash(File file)
          Produce an SHA-1 hash for the given file.
static byte[] sha1Hash(InputStream stream)
          Produce an SHA-1 hash for the contents of the given stream.
static byte[] sha256Hash(File file)
          Produce an SHA-256 hash for the given file.
static byte[] sha256Hash(InputStream stream)
          Produce an SHA-256 hash for the contents of the given stream.
static byte[] toByteArray(File file)
          Reads the entire contents of a file and return it as a byte array.
static byte[] toByteArray(InputStream stream)
          Create a byte array with the contents of the given stream.
static String toString(File file)
          Reads the entire contents of a file and return it as a String.
static String toString(Reader r)
          Create a String with the contents of the given Reader.
static StringBuffer toStringBuffer(File file)
          Reads the entire contents of a file and return it as a StringBuffer.
static StringBuffer toStringBuffer(Reader r)
          Create a StringBuffer with the contents of the given Reader.
static int writeFromInputStream(InputStream source, OutputStream dest, int bytes)
          Copy the given number of bytes from in to out.
static int writeFromInputStream(InputStream source, OutputStream dest, int bytes, byte[] buffer)
          Copy the given number of bytes from in to out, using the given buffer.
static int writeFromReader(Reader source, Writer dest, int chars)
          Copy the given number of chars from in to out.
static int writeFromReader(Reader source, Writer dest, int chars, char[] buffer)
          Copy the given number of chars from in to out, using the given buffer.
static void writeStringToFile(File file, String text)
          Writes text to the file, overwriting whatever was there.
static void writeStringToFile(File file, String text, boolean append)
          Writes text to the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WORKING_DIRECTORY

public static final File WORKING_DIRECTORY
The current working directory, used as the base for relative paths. Based on System property user.dir, if defined, converted to an absolute path.


FILE_FACTORY

public static final Lambda<String,File> FILE_FACTORY
A factory for Files based on a String filename.


IS_FILE

public static final FilePredicate IS_FILE
A predicate that tests whether attemptIsFile(java.io.File) holds for a file.


IS_DIRECTORY

public static final FilePredicate IS_DIRECTORY
A predicate that tests whether attemptIsDirectory(java.io.File) holds for a file.


ALWAYS_ACCEPT

public static final FilePredicate ALWAYS_ACCEPT
A FilePredicate that always accepts.


ALWAYS_REJECT

public static final FilePredicate ALWAYS_REJECT
A FilePredicate that always rejects.

Method Detail

attemptAbsoluteFile

public static File attemptAbsoluteFile(File f)
Make a best attempt at evaluating File.getAbsoluteFile(). In the event of a SecurityException, the result is just f. (Clients cannot assume, then, that the result is absolute.)


getAbsoluteFiles

public static SizedIterable<File> getAbsoluteFiles(Iterable<? extends File> files)
Apply File.getAbsoluteFile() to all files in a list

Throws:
SecurityException - If any of the getAbsoluteFile() invocations triggers a SecurityException

attemptAbsoluteFiles

public static SizedIterable<File> attemptAbsoluteFiles(Iterable<? extends File> files)
Apply attemptAbsoluteFile(java.io.File) to all files in a list


attemptCanonicalFile

public static File attemptCanonicalFile(File f)
Make a best attempt at evaluating File.getCanonicalFile(). In the event of an IOException or a SecurityException, the result is instead the result of attemptAbsoluteFile(java.io.File). (Clients cannot assume, then, that the result is canonical.)


getCanonicalFiles

public static SizedIterable<File> getCanonicalFiles(Iterable<? extends File> files)
                                             throws IOException
Apply File.getCanonicalFile() to all files in a list

Throws:
IOException - If any of the getCanonicalFile() invocations triggers an IOException
SecurityException - If any of the getCanonicalFile() invocations triggers a SecurityException

attemptCanonicalFiles

public static SizedIterable<File> attemptCanonicalFiles(Iterable<? extends File> files)
Apply attemptCanonicalFile(java.io.File) to all files in a list


attemptCanRead

public static boolean attemptCanRead(File f)
Make a best attempt at evaluating File.canRead(). In the event of a SecurityException, the result is false.


attemptCanWrite

public static boolean attemptCanWrite(File f)
Make a best attempt at evaluating File.canWrite(). In the event of a SecurityException, the result is false.


attemptExists

public static boolean attemptExists(File f)
Make a best attempt at evaluating File.exists(). In the event of a SecurityException, the result is false.


attemptIsDirectory

public static boolean attemptIsDirectory(File f)
Make a best attempt at evaluating File.isDirectory(). In the event of a SecurityException, the result is false.


attemptIsFile

public static boolean attemptIsFile(File f)
Make a best attempt at evaluating File.isFile(). In the event of a SecurityException, the result is false.


attemptIsHidden

public static boolean attemptIsHidden(File f)
Make a best attempt at evaluating File.isHidden(). In the event of a SecurityException, the result is false.


attemptLastModified

public static long attemptLastModified(File f)
Make a best attempt at evaluating File.lastModified(). In the event of a SecurityException, the result is 0l.


attemptLength

public static long attemptLength(File f)
Make a best attempt at evaluating File.length(). In the event of a SecurityException, the result is 0l.


attemptCreateNewFile

public static boolean attemptCreateNewFile(File f)
Make a best attempt at invoking File.createNewFile(). In the event of an IOException or a SecurityException, the result is false.


attemptDelete

public static boolean attemptDelete(File f)
Make a best attempt at invoking File.delete(). In the event of a SecurityException, the result is false.


attemptDeleteOnExit

public static void attemptDeleteOnExit(File f)
Make a best attempt at invoking File.deleteOnExit(). Any resulting SecurityException will be ignored.


attemptListFiles

public static File[] attemptListFiles(File f)
Make a best attempt at invoking File.listFiles(). In the event of a SecurityException, the result is null.


attemptListFiles

public static File[] attemptListFiles(File f,
                                      FileFilter filter)
Make a best attempt at invoking File.listFiles(FileFilter). In the event of a SecurityException, the result is null.


attemptListFiles

public static File[] attemptListFiles(File f,
                                      Predicate<? super File> filter)
Make a best attempt at invoking File.listFiles(FileFilter). In the event of a SecurityException, the result is null. The given predicate is converted to a FileFilter.


attemptListFiles

public static File[] attemptListFiles(File f,
                                      FilePredicate filter)
Make a best attempt at invoking File.listFiles(FileFilter). In the event of a SecurityException, the result is null. (Defined to resolve method ambiguity when a FilePredicate is used.)


attemptListFilesAsIterable

public static SizedIterable<File> attemptListFilesAsIterable(File f)
Similar to attemptListFiles(File), but returns a non-null Iterable rather than an array. Where attemptListFiles(f) returns null, the result here is an empty iterable.


attemptListFilesAsIterable

public static SizedIterable<File> attemptListFilesAsIterable(File f,
                                                             FileFilter filter)
Similar to attemptListFiles(File, FileFilter), but returns a non-null Iterable rather than an array. Where attemptListFiles(f) returns null, the result here is an empty iterable.


attemptListFilesAsIterable

public static SizedIterable<File> attemptListFilesAsIterable(File f,
                                                             Predicate<? super File> filter)
Similar to attemptListFiles(File, FileFilter), but returns a non-null Iterable rather than an array. Where attemptListFiles(f) returns null, the result here is an empty iterable. The given predicate is converted to a FileFilter.


attemptListFilesAsIterable

public static SizedIterable<File> attemptListFilesAsIterable(File f,
                                                             FilePredicate filter)
Similar to attemptListFiles(File, FileFilter), but returns a non-null Iterable rather than an array. Where attemptListFiles(f) returns null, the result here is an empty iterable. (Defined to resolve method ambiguity when called with a FilePredicate.)


attemptMkdir

public static boolean attemptMkdir(File f)
Make a best attempt at invoking File.mkdir(). In the event of a SecurityException, the result is false.


attemptMkdirs

public static boolean attemptMkdirs(File f)
Make a best attempt at invoking File.mkdirs(). In the event of a SecurityException, the result is false.


attemptRenameTo

public static boolean attemptRenameTo(File f,
                                      File dest)
Make a best attempt at invoking File.renameTo(java.io.File). In the event of a SecurityException, the result is false.


attemptMove

public static boolean attemptMove(File f,
                                  File dest)
Like attemptRenameTo(java.io.File, java.io.File), makes a best attempt at renaming f. Before doing so, however, dest, if it exists, is deleted. (On some systems, such as Windows, the rename will otherwise fail.)


attemptSetLastModified

public static boolean attemptSetLastModified(File f,
                                             long time)
Make a best attempt at invoking File.setLastModified(long). In the event of a SecurityException, the result is false.


attemptSetReadOnly

public static boolean attemptSetReadOnly(File f)
Make a best attempt at invoking File.setReadOnly(). In the event of a SecurityException, the result is false.


canonicalCase

public static File canonicalCase(File f)
Converts a File to all lowercase in case-insensitive systems; otherwise, returns the file untouched. This provides a basis for comparing files in case-insensitive file systems. Note that a canonical file (see File.getCanonicalFile() and attemptCanonicalFile(java.io.File)) is not necessarily in canonical case, and applying this function to a canonical file may create a file that is no longer canonical. Where the file doesn't exist, it's even possible that two different canonical files have the same canonical case representation.


canonicalCases

public static SizedIterable<File> canonicalCases(Iterable<? extends File> files)
Apply canonicalCase(java.io.File) to all files in a list


isMember

public static boolean isMember(File f,
                               File ancestor)
Determine if the given file is a member (as determined by File.getParentFile()) of another file. If f.equals(ancestor), the result is true.


fullPath

public static SizedIterable<File> fullPath(File f)
Create a list of files representing the full path of f. This list has at least one element -- f -- and contains all files that are produced by repeated invocations of File.getParentFile(). The outermost file appears first in the list, with f appearing last.


deleteRecursively

public static boolean deleteRecursively(File f)
Attempt to delete the given File. If f is a directory, this method will first recur on each of f's members. In all cases, attemptDelete(java.io.File) will be invoked on f, and the result of this method will be identical to that result.


deleteOnExitRecursively

public static void deleteOnExitRecursively(File f)
Attempt to mark the given File for deletion. If f is a directory, this method will also recur on each of f's members. In all cases, attemptDeleteOnExit(java.io.File) will be invoked on f. (Note that f may not actually be deleted on exit if some of its contents change after invoking this method, or if an error occurs in listing and marking its members for deletion.)


listFilesRecursively

public static SizedIterable<File> listFilesRecursively(File f)
Produce a list of the recursive contents of a file. The result is a list beginning with f, followed (if f is a directory with a canonical path) by a recursive listing of each of the files belonging to f. The recursion will halt cleanly in the presence of loops in the system. If an error occurs in listing a directory, that directory will be skipped.

Parameters:
f - A file (generally a directory) to be listed recursively

listFilesRecursively

public static SizedIterable<File> listFilesRecursively(File f,
                                                       FileFilter filter)
Produce a list of the recursive contents of a file. The result is a list beginning with f, followed (if f is a directory with a canonical path}) by a recursive listing of each of the files belonging to f. The recursion will halt cleanly in the presence of loops in the system. If an error occurs in listing a directory, that directory will be skipped.

Parameters:
f - A file (generally a directory) to be listed recursively
filter - A filter for the list -- files that do not match will not be included (but directories that do not match will still be traversed)

listFilesRecursively

public static SizedIterable<File> listFilesRecursively(File f,
                                                       Predicate<? super File> filter)
Produce a list of the recursive contents of a file. The result is a list beginning with f, followed (if f is a directory with a canonical path}) by a recursive listing of each of the files belonging to f. The recursion will halt cleanly in the presence of loops in the system. If an error occurs in listing a directory, that directory will be skipped.

Parameters:
f - A file (generally a directory) to be listed recursively
filter - A filter for the list -- files that do not match will not be included (but directories that do not match will still be traversed)

listFilesRecursively

public static SizedIterable<File> listFilesRecursively(File f,
                                                       FilePredicate filter)
Produce a list of the recursive contents of a file. The result is a list beginning with f, followed (if f is a directory with a canonical path}) by a recursive listing of each of the files belonging to f. The recursion will halt cleanly in the presence of loops in the system. If an error occurs in listing a directory, that directory will be skipped. (Defined to resolve method ambiguity when a FilePredicate is used.)

Parameters:
f - A file (generally a directory) to be listed recursively
filter - A filter for the list -- files that do not match will not be included (but directories that do not match will still be traversed)

listFilesRecursively

public static SizedIterable<File> listFilesRecursively(File f,
                                                       FileFilter filter,
                                                       FileFilter recursionFilter)
Produce a list of the recursive contents of a file. The result is a list beginning with f, followed (if f is a directory with a canonical path}) by a recursive listing of each of the files belonging to f. The recursion will halt cleanly in the presence of loops in the system.

Parameters:
f - A file (generally a directory) to be listed recursively
filter - A filter for the list -- files that do not match will not be included (but directories that do not match will still be traversed)
recursionFilter - A filter controlling recursion -- directories that are rejected will not be traversed.

listFilesRecursively

public static SizedIterable<File> listFilesRecursively(File f,
                                                       Predicate<? super File> filter,
                                                       Predicate<? super File> recursionFilter)
Produce a list of the recursive contents of a file. The result is a list beginning with f, followed (if f is a directory with a canonical path}) by a recursive listing of each of the files belonging to f. The recursion will halt cleanly in the presence of loops in the system.

Parameters:
f - A file (generally a directory) to be listed recursively
filter - A filter for the list -- files that do not match will not be included (but directories that do not match will still be traversed)
recursionFilter - A filter controlling recursion -- directories that are rejected will not be traversed.

listFilesRecursively

public static SizedIterable<File> listFilesRecursively(File f,
                                                       FilePredicate filter,
                                                       FilePredicate recursionFilter)
Produce a list of the recursive contents of a file. The result is a list beginning with f, followed (if f is a directory with a canonical path}) by a recursive listing of each of the files belonging to f. The recursion will halt cleanly in the presence of loops in the system. (Defined to resolve method ambiguity where two FilePredicates are used.)

Parameters:
f - A file (generally a directory) to be listed recursively
filter - A filter for the list -- files that do not match will not be included (but directories that do not match will still be traversed)
recursionFilter - A filter controlling recursion -- directories that are rejected will not be traversed.

toByteArray

public static byte[] toByteArray(File file)
                          throws IOException
Reads the entire contents of a file and return it as a byte array.

Throws:
IOException - If the file does not exist or cannot be opened, or if an error occurs during reading
SecurityException - If read access to the file is denied

toStringBuffer

public static StringBuffer toStringBuffer(File file)
                                   throws IOException
Reads the entire contents of a file and return it as a StringBuffer. (We use a StringBuffer rather than a StringBuilder because that is what StringWriter supports.)

Throws:
IOException - If the file does not exist or cannot be opened, or if an error occurs during reading
SecurityException - If read access to the file is denied

toString

public static String toString(File file)
                       throws IOException
Reads the entire contents of a file and return it as a String.

Throws:
IOException - If the file does not exist or cannot be opened, or if an error occurs during reading
SecurityException - If read access to the file is denied

readLines

public static Iterator<String> readLines(File file)
                                  throws IOException
Get the contents of a file as a sequence of lines, accessed via an iterator. Lines are broken as determined by BufferedReader.readLine(boolean). The result iterator's next() method throws a WrappedException wrapping an IOException if an error occurs while reading.

Throws:
IOException - If the file can't be found or an error occurs when reading the first line (for lookahead)

adler32Hash

public static int adler32Hash(File file)
                       throws IOException
Produce an Adler-32 hash for the given file. The result is an int (32 bits).

Throws:
IOException - If the file does not exist or cannot be opened, or if an error occurs during reading
SecurityException - If read access to the file is denied

crc32Hash

public static int crc32Hash(File file)
                     throws IOException
Produce a CRC-32 hash for the given file. The result is an int (32 bits).

Throws:
IOException - If the file does not exist or cannot be opened, or if an error occurs during reading
SecurityException - If read access to the file is denied

md5Hash

public static byte[] md5Hash(File file)
                      throws IOException
Produce an MD5 hash for the given file. The result is 16 bytes (128 bits) long.

Throws:
IOException - If the file does not exist or cannot be opened, or if an error occurs during reading
SecurityException - If read access to the file is denied

sha1Hash

public static byte[] sha1Hash(File file)
                       throws IOException
Produce an SHA-1 hash for the given file. The result is 20 bytes (160 bits) long.

Throws:
IOException - If the file does not exist or cannot be opened, or if an error occurs during reading
SecurityException - If read access to the file is denied

sha256Hash

public static byte[] sha256Hash(File file)
                         throws IOException
Produce an SHA-256 hash for the given file. The result is 32 bytes (256 bits) long.

Throws:
IOException - If the file does not exist or cannot be opened, or if an error occurs during reading
SecurityException - If read access to the file is denied

copyFile

public static void copyFile(File source,
                            File dest)
                     throws IOException
Copies the contents of one file into another.

Parameters:
source - the file to be copied
dest - the file to be copied to
Throws:
IOException - If one of the files does not exist or cannot be opened, or if an error occurs during reading or writing
SecurityException - If read or write access, respectively, to the file is denied

copyFile

public static void copyFile(File source,
                            File dest,
                            byte[] buffer)
                     throws IOException
Copies the contents of one file into another, using the given array as an intermediate buffer.

Parameters:
source - The file to be copied
dest - The file to be copied to
buffer - A buffer to use in copying
Throws:
IOException - If one of the files does not exist or cannot be opened, or if an error occurs during reading or writing
SecurityException - If read or write access, respectively, to the file is denied

writeStringToFile

public static void writeStringToFile(File file,
                                     String text)
                              throws IOException
Writes text to the file, overwriting whatever was there.

Parameters:
file - File to write to
text - Text to write
Throws:
IOException - If the file does not exist or cannot be opened, or if an error occurs during writing
SecurityException - If write access to the file is denied

attemptWriteStringToFile

public static boolean attemptWriteStringToFile(File file,
                                               String text)
Writes text to the file, overwriting whatever was there. Ignores any exceptions that occur.

Parameters:
file - File to write to
text - Text to write
Returns:
true iff the operation succeeded without an exception.

writeStringToFile

public static void writeStringToFile(File file,
                                     String text,
                                     boolean append)
                              throws IOException
Writes text to the file.

Parameters:
file - File to write to
text - Text to write
append - true iff the file should be opened in "append" mode (rather than "overwrite" mode)
Throws:
IOException - If the file does not exist or cannot be opened, or if an error occurs during writing
SecurityException - If write access to the file is denied

attemptWriteStringToFile

public static boolean attemptWriteStringToFile(File file,
                                               String text,
                                               boolean append)
Writes text to the file, ignoring any exceptions that occur.

Parameters:
file - File to write to
text - Text to write
append - true iff the file should be opened in "append" mode (rather than "overwrite" mode)
Returns:
true iff the operation succeeded without an exception.

createAndMarkTempFile

public static File createAndMarkTempFile(String prefix,
                                         String suffix)
                                  throws IOException
Create a temporary file in the system temp directory (via File.createTempFile(String, String)) and immediately mark it for deletion

Throws:
IOException - If an exception occurs in File.createTempFile(String, String)
SecurityException - If write or delete access to the system temp directory is denied

createAndMarkTempFile

public static File createAndMarkTempFile(String prefix,
                                         String suffix,
                                         File location)
                                  throws IOException
Create a temporary file in the specified directory (via File.createTempFile(String, String, File)) and immediately mark it for deletion

Throws:
IOException - If an exception occurs in File.createTempFile(String, String, File)
SecurityException - If write or delete access to location is denied

createAndMarkTempDirectory

public static File createAndMarkTempDirectory(String prefix,
                                              String suffix)
                                       throws IOException
Create a temporary directory (named by File.createTempFile(java.lang.String, java.lang.String, java.io.File)) and immediately mark it for deletion. (Deletion will only actually occur if the directory is empty on exit, or if all files created in the directory are also marked for deletion.)

Throws:
IOException - If an exception occurs in File.createTempFile(java.lang.String, java.lang.String, java.io.File), or if the attempt to create the directory is unsuccessful
SecurityException - If write access to the system temp directory is denied

createAndMarkTempDirectory

public static File createAndMarkTempDirectory(String prefix,
                                              String suffix,
                                              File location)
                                       throws IOException
Create a temporary directory (named by File.createTempFile(java.lang.String, java.lang.String, java.io.File)) and immediately mark it for deletion. (Deletion will only actually occur if the directory is empty on exit, or if all files created in the directory are also marked for deletion.)

Throws:
IOException - If an exception occurs in File.createTempFile(java.lang.String, java.lang.String, java.io.File), or if the attempt to create the directory is unsuccessful
SecurityException - If write access to location is denied

parsePath

public static SizedIterable<File> parsePath(String path)
Parse a path string -- a list of file names separated by the system-dependent path separator character (':' in Unix, ';' in Windows). Filename strings in the path are interpreted according to the File constructor.


pathToString

public static String pathToString(Iterable<? extends File> path)
Produce a path string from a list of files. Filenames in the result are delimited by the system-dependent path separator character (':' in Unix, ';' in Windows).


copyReader

public static int copyReader(Reader source,
                             Writer dest)
                      throws IOException
Write the contents of in to out. Processing will continue (or block) until the end of stream is reached.

Returns:
The number of chars written, or -1 if the end of stream has already been reached, or Integer.MAX_VALUE if the number cannot be represented as an int.
Throws:
IOException - If an IOException occurs during reading or writing

copyReader

public static int copyReader(Reader source,
                             Writer dest,
                             char[] buffer)
                      throws IOException
Write the contents of in to out, using the given buffer. Processing will continue (or block) until the end of stream is reached.

Returns:
The number of chars written, or -1 if the end of stream has already been reached, or Integer.MAX_VALUE if the number cannot be represented as an int.
Throws:
IOException - If an IOException occurs during reading or writing

writeFromReader

public static int writeFromReader(Reader source,
                                  Writer dest,
                                  int chars)
                           throws IOException
Copy the given number of chars from in to out.

Returns:
The number of chars written, or -1 if the end of stream has already been reached. May be less than chars if source does not provide all the requested data.
Throws:
IOException - If an IOException occurs during reading or writing

writeFromReader

public static int writeFromReader(Reader source,
                                  Writer dest,
                                  int chars,
                                  char[] buffer)
                           throws IOException
Copy the given number of chars from in to out, using the given buffer.

Returns:
The number of chars written, or -1 if the end of stream has already been reached. May be less than chars if source does not provide all the requested data.
Throws:
IOException - If an IOException occurs during reading or writing

copyInputStream

public static int copyInputStream(InputStream source,
                                  OutputStream dest)
                           throws IOException
Write the contents of in to out. Processing will continue (or block) until the end of stream is reached.

Returns:
The number of bytes written, or -1 if the end of stream has already been reached, or Integer.MAX_VALUE if the number cannot be represented as an int.
Throws:
IOException - If an IOException occurs during reading or writing

copyInputStream

public static int copyInputStream(InputStream source,
                                  OutputStream dest,
                                  byte[] buffer)
                           throws IOException
Write the contents of in to out, using the given buffer. Processing will continue (or block) until the end of stream is reached.

Returns:
The number of bytes written, or -1 if the end of stream has already been reached, or Integer.MAX_VALUE if the number cannot be represented as an int.
Throws:
IOException - If an IOException occurs during reading or writing

writeFromInputStream

public static int writeFromInputStream(InputStream source,
                                       OutputStream dest,
                                       int bytes)
                                throws IOException
Copy the given number of bytes from in to out.

Returns:
The number of bytes written, or -1 if the end of stream has already been reached. May be less than bytes if source does not provide all the requested data.
Throws:
IOException - If an IOException occurs during reading or writing

writeFromInputStream

public static int writeFromInputStream(InputStream source,
                                       OutputStream dest,
                                       int bytes,
                                       byte[] buffer)
                                throws IOException
Copy the given number of bytes from in to out, using the given buffer.

Returns:
The number of bytes written, or -1 if the end of stream has already been reached. May be less than bytes if source does not provide all the requested data.
Throws:
IOException - If an IOException occurs during reading or writing

doCopyReader

protected static int doCopyReader(Reader r,
                                  Writer w,
                                  char[] buffer)
                           throws IOException
Implementation of reader-to-writer copying for use by DirectReader and DirectWriter (placed here to avoid code duplication). The method will block until an end-of-file is reached.

Returns:
-1 if the reader is at the end of file; otherwise, the number of characters read (or, if the number is too large, Integer.MAX_VALUE)
Throws:
IOException - If an error occurs during reading or writing
IllegalArgumentException - If buffer has size 0

doCopyInputStream

protected static int doCopyInputStream(InputStream in,
                                       OutputStream out,
                                       byte[] buffer)
                                throws IOException
Implementation of stream copying for use by DirectInputStream and DirectOutputStream (placed here to avoid code duplication). The method will block until an end-of-file is reached.

Returns:
-1 if the reader is at the end of file; otherwise, the number of characters read (or, if the number is too large, Integer.MAX_VALUE)
Throws:
IOException - If an error occurs during reading or writing
IllegalArgumentException - If buffer has size 0

doWriteFromReader

protected static int doWriteFromReader(Reader r,
                                       Writer w,
                                       int chars,
                                       char[] buffer)
                                throws IOException
Implementation of reader-to-writer writing for use by DirectReader and DirectWriter (placed here to avoid code duplication).

Returns:
-1 if this reader is at the end of file; otherwise, the number of characters read
Throws:
IOException - If an error occurs during reading or writing
IllegalArgumentException - If buffer has size 0

doWriteFromInputStream

protected static int doWriteFromInputStream(InputStream in,
                                            OutputStream out,
                                            int bytes,
                                            byte[] buffer)
                                     throws IOException
Implementation of stream-to-stream writing for use by DirectInputStream and DirectOutputStream (placed here to avoid code duplication).

Returns:
-1 if this reader is at the end of file; otherwise, the number of characters read
Throws:
IOException - If an error occurs during reading or writing
IllegalArgumentException - If buffer has size 0

toByteArray

public static byte[] toByteArray(InputStream stream)
                          throws IOException
Create a byte array with the contents of the given stream. The method will not return until an end of stream has been reached.

Throws:
IOException

toStringBuffer

public static StringBuffer toStringBuffer(Reader r)
                                   throws IOException
Create a StringBuffer with the contents of the given Reader. The method will not return until an end of stream has been reached. (We use a StringBuffer rather than a StringBuilder because that is what StringWriter supports.)

Throws:
IOException

toString

public static String toString(Reader r)
                       throws IOException
Create a String with the contents of the given Reader. The method will not return until an end of stream has been reached.

Throws:
IOException

readLines

public static Iterator<String> readLines(Reader r)
                                  throws IOException
Get the contents of a reader as a sequence of lines, accessed via an iterator. Lines are broken as determined by BufferedReader.readLine(boolean). The Reader is closed once iteration has been completed. The result iterator's next() method throws a WrappedException wrapping an IOException if an error occurs while reading.

Throws:
IOException - If an error occurs when reading the first line (for lookahead).

adler32Hash

public static int adler32Hash(InputStream stream)
                       throws IOException
Produce an Adler-32 hash for the contents of the given stream. The result is an int (32 bits). The method will not return until an end of stream has been reached.

Throws:
IOException

crc32Hash

public static int crc32Hash(InputStream stream)
                     throws IOException
Produce a CRC-32 hash for the contents of the given stream. The result is an int (32 bits). The method will not return until an end of stream has been reached.

Throws:
IOException

md5Hash

public static byte[] md5Hash(InputStream stream)
                      throws IOException
Produce an MD5 hash for the contents of the given stream. The result is 16 bytes (128 bits) long. The method will not return until an end of stream has been reached.

Throws:
IOException

sha1Hash

public static byte[] sha1Hash(InputStream stream)
                       throws IOException
Produce an SHA-1 hash for the contents of the given stream. The result is 20 bytes (160 bits) long. The method will not return until an end of stream has been reached.

Throws:
IOException

sha256Hash

public static byte[] sha256Hash(InputStream stream)
                         throws IOException
Produce an SHA-256 hash for the contents of the given stream. The result is 32 bytes (256 bits) long. The method will not return until an end of stream has been reached.

Throws:
IOException

asBuffered

public static BufferedReader asBuffered(Reader r)
If r is a BufferedReader, cast it as such; otherwise, wrap it in a BufferedReader.


asBuffered

public static BufferedWriter asBuffered(Writer w)
If w is a BufferedWriter, cast it as such; otherwise, wrap it in a BufferedWriter.


asBuffered

public static BufferedInputStream asBuffered(InputStream in)
If in is a BufferedInputStream, cast it as such; otherwise, wrap it in a BufferedInputStream.


asBuffered

public static BufferedOutputStream asBuffered(OutputStream out)
If out is a BufferedOutputStream, cast it as such; otherwise, wrap it in a BufferedOutputStream.


closeOnExit

public static void closeOnExit(Closeable c)
Register the given resource to be closed on exit. Closeable.close() will be invoked from a shutdown hook.


attemptClose

public static void attemptClose(Closeable c)
Attempt to close the given resource, failing silently if an exception occurs.


asFilePredicate

public static FilePredicate asFilePredicate(Predicate<? super File> p)
Define a FileFilter in terms of a Predicate.


asFilePredicate

public static FilePredicate asFilePredicate(FileFilter filter)
Define a FilePredicate in terms of a FileFilter (this provides access to predicate operations like and and or).


regexFilePredicate

public static FilePredicate regexFilePredicate(String regex)
Define a FilePredicate that accepts files whose (simple) names match a regular expression.


regexFilePredicate

public static FilePredicate regexFilePredicate(Pattern regex)
Define a FilePredicate that accepts files whose (simple) names match a regular expression.


regexCanonicalCaseFilePredicate

public static FilePredicate regexCanonicalCaseFilePredicate(String regex)
Define a FilePredicate that accepts files whose (simple) names in the canonical case (see canonicalCase(java.io.File)) match a regular expression.


extensionFilePredicate

public static FilePredicate extensionFilePredicate(String extension)
Define a FilePredicate that accepts file objects with the given extension (that is, for extension txt, file objects whose canonical-case names (see canonicalCase(java.io.File)) end in .txt).


sameNameFilePredicate

public static FilePredicate sameNameFilePredicate(String name)
Define a FilePredicate that only accepts files with the given name (where both names are converted to the canonical case; see canonicalCase(java.io.File)).


samePathFilePredicate

public static FilePredicate samePathFilePredicate(File path)
Define a FilePredicate that only accepts files with the given path and name (where both paths are converted to the canonical case; see canonicalCase(java.io.File)). If path is relative, any file with an absolute path that ends with path will be accepted. Otherwise, only a file with the exact same path is accepted.


sameAttributesFilePredicate

public static FilePredicate sameAttributesFilePredicate(File f)
                                                 throws FileNotFoundException
Define a FilePredicate that only accepts a file with the same attributes as f (at creation time). This is useful in detecting changes being made to a file. The files' modification dates, lengths, and read/write permissions are compared.

Throws:
FileNotFoundException - If f is not a normal file, or if access to its attributes is not available.

sameContentsFilePredicate

public static FilePredicate sameContentsFilePredicate(File f)
                                               throws IOException
Define a FilePredicate that only accepts files with contents matching a CRC-32 hash of f (at creation time). This is useful in detecting changes being made to a file.

Throws:
IOException - If f cannot be read.

and

public static FilePredicate and(FileFilter... filters)
Produce a conjunction of the given FileFilters.


and

public static FilePredicate and(Iterable<? extends FileFilter> filters)
Produce a conjunction of the given FileFilters.


or

public static FilePredicate or(FileFilter... filters)
Produce a disjunction of the given FileFilters.


or

public static FilePredicate or(Iterable<? extends FileFilter> filters)
Produce a disjunction of the given FileFilters.


negate

public static FilePredicate negate(FileFilter filter)
Produce the complement of the given FileFilter.


fileKey

public static FilePredicate fileKey(File f)
                             throws IOException
Produce a FilePredicate that acts as a "key" representing the current state of the given file. A file will match only if it has the same name, absolute path, attributes, and contents as f. This is useful for detecting background changes to a file.

Throws:
IOException - If the given file does not exist, is not a normal file, or does not allow its attributes or contents to be accessed.

replaceSystemOut

public static void replaceSystemOut(OutputStream substitute)
Replace System.out with the given stream and remember the current stream. This call should always be matched by a subsequent call to revertSystemOut().


ignoreSystemOut

public static void ignoreSystemOut()
Ignore subsequent writes to System.out until revertSystemOut() is called. A matching revert call should be made.


revertSystemOut

public static void revertSystemOut()
Set System.out to its value before the last call to replaceSystemOut(java.io.OutputStream). This call should always follow a call to replaceSystemOut(). Assuming all calls are properly paired, and that multiple threads do not concurrently invoke these methods, the stream after this call will be the stream that was replaced by replaceSystemOut().


replaceSystemErr

public static void replaceSystemErr(OutputStream substitute)
Replace System.err with the given stream and remember the current stream. This call should always be matched by a subsequent call to revertSystemErr().


ignoreSystemErr

public static void ignoreSystemErr()
Ignore subsequent writes to System.err until revertSystemErr() is called. A matching revert call should be made.


revertSystemErr

public static void revertSystemErr()
Set System.err to its value before the last call to replaceSystemErr(java.io.OutputStream). This call should always follow a call to replaceSystemErr(). Assuming all calls are properly paired, and that multiple threads do not concurrently invoke these methods, the stream after this call will be the stream that was replaced by replaceSystemErr().


replaceSystemIn

public static void replaceSystemIn(InputStream substitute)
Replace System.in with the given stream and remember the current stream. This call should always be matched by a subsequent call to revertSystemIn().


revertSystemIn

public static void revertSystemIn()
Set System.in to its value before the last call to replaceSystemIn(java.io.InputStream). This call should always follow a call to replaceSystemIn(). Assuming all calls are properly paired, and that multiple threads do not concurrently invoke these methods, the stream after this call will be the stream that was replaced by replaceSystemIn().


ensureSerializable

public static Object ensureSerializable(Object obj)
Converts the given object to a form that will successfully serialize. Typical serializable primitives like null, Strings and Files are left untouched; tuples, Iterables, Throwables, and arrays are processed recursively; and other types are handled by invoking obj.toString(). Note that subsequent (or concurrent) mutation of the object may prevent successful serialization.


ensureSerializable

public static Object[] ensureSerializable(Object[] arr)
Convert the given (non-null) array to an array of objects that will successfully serialize. If the type of the array guarantees this property, or if none of the current elements requires conversion, returns arr unchanged. Otherwise, makes a converted copy. Note that subsequent (or concurrent) mutation of the array may prevent successful serialization.


ensureSerializable

public static Iterable<?> ensureSerializable(Iterable<?> iter)
Convert the given (non-null) Iterable to a list of objects that will successfully serialize. Discards any problematic fields by copying the Iterable into a List (recursively converting the elements). Infinite Iterables are handled by truncating the list with a "..." string. Note that subsequent (or concurrent) mutation of the elements may prevent successful serialization.


ensureSerializable

public static Throwable ensureSerializable(Throwable t)
Convert the given Throwable to a form that will successfully serialize. If necessary, copies the throwable into a SerializableException. Note that subsequent (or concurrent) mutation of the cause may prevent successful serialization.


ensureSerializable

public static Exception ensureSerializable(Exception e)
Convert the given Exception to a form that will successfully serialize. If necessary, copies the exception into a SerializableException. Note that subsequent (or concurrent) mutation of the cause may prevent successful serialization.


ensureSerializable

public static RuntimeException ensureSerializable(RuntimeException e)
Convert the given RuntimeException to a form that will successfully serialize. If necessary, copies the exception into a SerializableException. Note that subsequent (or concurrent) mutation of the cause may prevent successful serialization.


ensureSerializable

public static Tuple ensureSerializable(Tuple t)
Apply ensureSerializable() to each of the elements of the given tuple. If the elements are unchanged and the tuple's class is known to serialize safely, returns the tuple unchanged.


ensureSerializable

public static Option<?> ensureSerializable(Option<?> opt)
Apply ensureSerializable() to the given option value. If the value is unchanged and the option's class is known to serialize safely, returns the option unchanged.


ensureSerializable

public static Wrapper<?> ensureSerializable(Wrapper<?> w)
Apply ensureSerializable() to the given wrapped value. If the value is unchanged and the wrapper's class is known to serialize safely, returns the wrapper unchanged.


ensureSerializable

public static Pair<?,?> ensureSerializable(Pair<?,?> p)
Apply ensureSerializable() to each of the elements of the given tuple. If the elements are unchanged and the tuple's class is known to serialize safely, returns the tuple unchanged.


ensureSerializable

public static Triple<?,?,?> ensureSerializable(Triple<?,?,?> t)
Apply ensureSerializable() to each of the elements of the given tuple. If the elements are unchanged and the tuple's class is known to serialize safely, returns the tuple unchanged.


ensureSerializable

public static Quad<?,?,?,?> ensureSerializable(Quad<?,?,?,?> q)
Apply ensureSerializable() to each of the elements of the given tuple. If the elements are unchanged and the tuple's class is known to serialize safely, returns the tuple unchanged.


ensureSerializable

public static Quint<?,?,?,?,?> ensureSerializable(Quint<?,?,?,?,?> q)
Apply ensureSerializable() to each of the elements of the given tuple. If the elements are unchanged and the tuple's class is known to serialize safely, returns the tuple unchanged.


ensureSerializable

public static Sextet<?,?,?,?,?,?> ensureSerializable(Sextet<?,?,?,?,?,?> s)
Apply ensureSerializable() to each of the elements of the given tuple. If the elements are unchanged and the tuple's class is known to serialize safely, returns the tuple unchanged.


ensureSerializable

public static Septet<?,?,?,?,?,?,?> ensureSerializable(Septet<?,?,?,?,?,?,?> s)
Apply ensureSerializable() to each of the elements of the given tuple. If the elements are unchanged and the tuple's class is known to serialize safely, returns the tuple unchanged.


ensureSerializable

public static Octet<?,?,?,?,?,?,?,?> ensureSerializable(Octet<?,?,?,?,?,?,?,?> o)
Apply ensureSerializable() to each of the elements of the given tuple. If the elements are unchanged and the tuple's class is known to serialize safely, returns the tuple unchanged.