public enum IOUtils extends Enum<IOUtils>
Modifier and Type | Method and Description |
---|---|
static void |
closeQuietly(Closeable is,
Log log)
Closes the given Closeable quietly.
|
static long |
copy(InputStream in,
OutputStream out)
Copies all bytes from the given input stream to the given output stream.
|
static void |
release(Closeable is,
Log log)
Releases the given
Closeable especially if it was an instance of
Releasable . |
static byte[] |
toByteArray(InputStream is)
Reads and returns the rest of the given input stream as a byte array,
closing the input stream afterwards.
|
static String |
toString(InputStream is)
Reads and returns the rest of the given input stream as a string, closing
the input stream afterwards.
|
static IOUtils |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static IOUtils[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static IOUtils[] values()
for (IOUtils c : IOUtils.values()) System.out.println(c);
public static IOUtils valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic static byte[] toByteArray(InputStream is) throws IOException
is
- the input stream.IOException
public static String toString(InputStream is) throws IOException
is
- the input stream.IOException
public static void closeQuietly(Closeable is, Log log)
is
- the given closeablelog
- logger used to log any failure should the close failpublic static void release(Closeable is, Log log)
Closeable
especially if it was an instance of
Releasable
.
For example, the creation of a ResettableInputStream
would
entail physically opening a file. If the opened file is meant to be
closed only (in a finally block) by the very same code block that created
it, then it is necessary that the release method must not be called while
the execution is made in other stack frames. In such case, as other stack
frames may inadvertently or indirectly call the close method of the
stream, the creator of the stream would need to explicitly disable the
accidental closing via ResettableInputStream#disableClose()
,
so that the release method becomes the only way to truly close the opened
file.
is
- the closeable.log
- the log.public static long copy(InputStream in, OutputStream out) throws IOException
in
- the input stream.out
- the output stream.IOException
- if there is any IO exception during read or write.Copyright © 2019. All rights reserved.