public final class IOUtils
extends java.lang.Object
| Modifier and Type | Field and Description |
|---|---|
static java.nio.charset.Charset |
CHARSET_UTF_8
UTF-8
Charset instance to prevent repeated
Charset.forName(String) lookups |
static java.lang.String |
UTF_8
UTF-8 charset string
|
| Modifier and Type | Method and Description |
|---|---|
static void |
close(java.io.Closeable... objects)
Closes all given Closeables.
|
static void |
close(java.lang.Iterable<? extends java.io.Closeable> objects)
Closes all given Closeables.
|
static void |
closeWhileHandlingException(java.io.Closeable... objects)
Closes all given Closeables, suppressing all thrown exceptions.
|
static <E extends java.lang.Exception> |
closeWhileHandlingException(E priorException,
java.io.Closeable... objects)
Closes all given Closeables, suppressing all thrown exceptions.
|
static <E extends java.lang.Exception> |
closeWhileHandlingException(E priorException,
java.lang.Iterable<? extends java.io.Closeable> objects)
Closes all given Closeables, suppressing all thrown exceptions.
|
static void |
closeWhileHandlingException(java.lang.Iterable<? extends java.io.Closeable> objects)
Closes all given Closeables, suppressing all thrown exceptions.
|
static void |
copy(java.io.File source,
java.io.File target)
Copy one file's contents to another file.
|
static void |
deleteFilesIgnoringExceptions(Directory dir,
java.lang.String... files)
Deletes all given files, suppressing all thrown IOExceptions.
|
static java.io.Reader |
getDecodingReader(java.lang.Class<?> clazz,
java.lang.String resource,
java.nio.charset.Charset charSet)
Opens a Reader for the given resource using a
CharsetDecoder. |
static java.io.Reader |
getDecodingReader(java.io.File file,
java.nio.charset.Charset charSet)
Opens a Reader for the given
File using a CharsetDecoder. |
static java.io.Reader |
getDecodingReader(java.io.InputStream stream,
java.nio.charset.Charset charSet)
Wrapping the given
InputStream in a reader using a CharsetDecoder. |
static void |
reThrow(java.lang.Throwable th)
Simple utilty method that takes a previously caught
Throwable and rethrows either IOException or an unchecked exception. |
static void |
reThrowUnchecked(java.lang.Throwable th)
Simple utilty method that takes a previously caught
Throwable and rethrows it as an unchecked exception. |
public static final java.lang.String UTF_8
Charset.forName(String),
Constant Field Valuespublic static final java.nio.charset.Charset CHARSET_UTF_8
Charset instance to prevent repeated
Charset.forName(String) lookupspublic static <E extends java.lang.Exception> void closeWhileHandlingException(E priorException,
java.io.Closeable... objects)
throws E extends java.lang.Exception,
java.io.IOException
Closes all given Closeables, suppressing all thrown exceptions. Some of the Closeables may be null, they are ignored. After everything is closed, method either throws priorException, if one is supplied, or the first of suppressed exceptions, or completes normally.
Sample usage:
Closeable resource1 = null, resource2 = null, resource3 = null;
ExpectedException priorE = null;
try {
resource1 = ...; resource2 = ...; resource3 = ...; // Acquisition may throw ExpectedException
..do..stuff.. // May throw ExpectedException
} catch (ExpectedException e) {
priorE = e;
} finally {
closeWhileHandlingException(priorE, resource1, resource2, resource3);
}
priorException - null or an exception that will be rethrown after method completionobjects - objects to call close() onE extends java.lang.Exceptionjava.io.IOExceptionpublic static <E extends java.lang.Exception> void closeWhileHandlingException(E priorException,
java.lang.Iterable<? extends java.io.Closeable> objects)
throws E extends java.lang.Exception,
java.io.IOException
E extends java.lang.Exceptionjava.io.IOExceptioncloseWhileHandlingException(Exception, Closeable...)public static void close(java.io.Closeable... objects)
throws java.io.IOException
objects - objects to call close() onjava.io.IOExceptionpublic static void close(java.lang.Iterable<? extends java.io.Closeable> objects)
throws java.io.IOException
java.io.IOExceptionclose(Closeable...)public static void closeWhileHandlingException(java.io.Closeable... objects)
objects - objects to call close() onpublic static void closeWhileHandlingException(java.lang.Iterable<? extends java.io.Closeable> objects)
public static java.io.Reader getDecodingReader(java.io.InputStream stream,
java.nio.charset.Charset charSet)
InputStream in a reader using a CharsetDecoder.
Unlike Java's defaults this reader will throw an exception if your it detects
the read charset doesn't match the expected Charset.
Decoding readers are useful to load configuration files, stopword lists or synonym files to detect character set problems. However, its not recommended to use as a common purpose reader.
stream - the stream to wrap in a readercharSet - the expected charsetpublic static java.io.Reader getDecodingReader(java.io.File file,
java.nio.charset.Charset charSet)
throws java.io.IOException
File using a CharsetDecoder.
Unlike Java's defaults this reader will throw an exception if your it detects
the read charset doesn't match the expected Charset.
Decoding readers are useful to load configuration files, stopword lists or synonym files to detect character set problems. However, its not recommended to use as a common purpose reader.
file - the file to open a reader oncharSet - the expected charsetjava.io.IOExceptionpublic static java.io.Reader getDecodingReader(java.lang.Class<?> clazz,
java.lang.String resource,
java.nio.charset.Charset charSet)
throws java.io.IOException
CharsetDecoder.
Unlike Java's defaults this reader will throw an exception if your it detects
the read charset doesn't match the expected Charset.
Decoding readers are useful to load configuration files, stopword lists or synonym files to detect character set problems. However, its not recommended to use as a common purpose reader.
clazz - the class used to locate the resourceresource - the resource name to loadcharSet - the expected charsetjava.io.IOExceptionpublic static void deleteFilesIgnoringExceptions(Directory dir, java.lang.String... files)
Note that the files should not be null.
public static void copy(java.io.File source,
java.io.File target)
throws java.io.IOException
java.io.IOExceptionpublic static void reThrow(java.lang.Throwable th)
throws java.io.IOException
Throwable and rethrows either IOException or an unchecked exception. If the
argument is null then this method does nothing.java.io.IOExceptionpublic static void reThrowUnchecked(java.lang.Throwable th)
Throwable and rethrows it as an unchecked exception.
If the argument is null then this method does nothing.Copyright © 2010 - 2024 Adobe. All Rights Reserved