public class IOUtils extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T extends AutoCloseable,E extends Throwable> |
close(BiFunction<String,Throwable,E> constructor,
T... closeables)
Close all ofthe given closeables, and if something goes wrong, use the given constructor to create a
Throwable instance with the specific cause
attached. |
static <T extends AutoCloseable> |
closeAll(T... closeables)
Closes given array of
closeables. |
static long |
copy(InputStream input,
OutputStream output) |
static long |
copy(InputStream input,
OutputStream output,
long offset,
long limit) |
static byte[] |
toBytes(InputStream in) |
static byte[] |
toBytes(InputStream in,
long offset,
long limit) |
static String |
toString(InputStream in) |
static String |
toString(InputStream in,
long offset,
long limit) |
public static long copy(InputStream input, OutputStream output) throws IOException
IOExceptionpublic static long copy(InputStream input, OutputStream output, long offset, long limit) throws IOException
IOExceptionpublic static byte[] toBytes(InputStream in) throws IOException
IOExceptionpublic static byte[] toBytes(InputStream in, long offset, long limit) throws IOException
IOExceptionpublic static String toString(InputStream in) throws IOException
IOExceptionpublic static String toString(InputStream in, long offset, long limit) throws IOException
IOException@SafeVarargs public static <T extends AutoCloseable> void closeAll(T... closeables) throws IOException
closeables. If any AutoCloseable.close() call throws
IOException than it will be rethrown to the caller after calling AutoCloseable.close()
on other given resources. If more than one AutoCloseable.close() throw than resulting exception will
have suppressed exceptions. See Throwable.addSuppressed(Throwable)T - the type of closeablecloseables - the closeables to closeIOException - if an exception was thrown by one of the close methods.@SafeVarargs public static <T extends AutoCloseable,E extends Throwable> void close(BiFunction<String,Throwable,E> constructor, T... closeables) throws E extends Throwable
Throwable instance with the specific cause
attached. The remaining closeables will still be closed, in that case, and if they in turn throw any exceptions then these will be attached as
suppressed exceptions.T - the type of things to close.E - the type of the parent exception.constructor - The function used to construct the parent throwable that will have the first thrown exception attached as a cause, and any
remaining exceptions attached as suppressed exceptions. If this function returns null, then the exception is ignored.closeables - all the things to close, in order.E - when any AutoCloseable.close() throws exceptionE extends ThrowableCopyright © 2016–2021 MWARE SOLUTIONS. All rights reserved.