|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.lucene.util.IOUtils
public final class IOUtils
This class emulates the new Java 7 "Try-With-Resources" statement. Remove once Lucene is on Java 7.
Field Summary | |
---|---|
static Charset |
CHARSET_UTF_8
UTF-8 Charset instance to prevent repeated
Charset.forName(String) lookups |
static String |
UTF_8
UTF-8 charset string |
Method Summary | ||
---|---|---|
static void |
close(Closeable... objects)
Closes all given Closeables. |
|
static void |
close(Iterable<? extends Closeable> objects)
|
|
static void |
closeWhileHandlingException(Closeable... objects)
Closes all given Closeables, suppressing all thrown exceptions. |
|
static
|
closeWhileHandlingException(E priorException,
Closeable... objects)
Closes all given Closeables, suppressing all thrown exceptions. |
|
static
|
closeWhileHandlingException(E priorException,
Iterable<? extends Closeable> objects)
|
|
static void |
closeWhileHandlingException(Iterable<? extends Closeable> objects)
|
|
static Reader |
getDecodingReader(Class<?> clazz,
String resource,
Charset charSet)
Opens a Reader for the given resource using a CharsetDecoder . |
|
static Reader |
getDecodingReader(File file,
Charset charSet)
Opens a Reader for the given File using a CharsetDecoder . |
|
static Reader |
getDecodingReader(InputStream stream,
Charset charSet)
Wrapping the given InputStream in a reader using a CharsetDecoder . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String UTF_8
Charset.forName(String)
,
Constant Field Valuespublic static final Charset CHARSET_UTF_8
Charset
instance to prevent repeated
Charset.forName(String)
lookups
Method Detail |
---|
public static <E extends Exception> void closeWhileHandlingException(E priorException, Closeable... objects) throws E extends Exception, 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 { closeSafely(priorE, resource1, resource2, resource3); }
priorException
- null or an exception that will be rethrown after method completionobjects
- objects to call close() on
E extends Exception
IOException
public static <E extends Exception> void closeWhileHandlingException(E priorException, Iterable<? extends Closeable> objects) throws E extends Exception, IOException
E extends Exception
IOException
closeWhileHandlingException(Exception, Closeable...)
public static void close(Closeable... objects) throws IOException
objects
- objects to call close() on
IOException
public static void close(Iterable<? extends Closeable> objects) throws IOException
IOException
close(Closeable...)
public static void closeWhileHandlingException(Closeable... objects) throws IOException
objects
- objects to call close() on
IOException
public static void closeWhileHandlingException(Iterable<? extends Closeable> objects) throws IOException
IOException
closeWhileHandlingException(Closeable...)
public static Reader getDecodingReader(InputStream stream, 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 charset
public static Reader getDecodingReader(File file, Charset charSet) throws 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 charset
IOException
public static Reader getDecodingReader(Class<?> clazz, String resource, Charset charSet) throws 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 charset
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |