public final class DiggIO extends Object
| Modifier and Type | Method and Description |
|---|---|
static <T extends AutoCloseable> |
autoClosing(ThrowingConsumer<T,? extends Exception> consumer)
Wrap a consumer which processes an
AutoCloseable
(typically an InputStream or similar) into a new Consumer which will always close
the AutoCloseable when the given consumer returns, successfully or throwing an exception. |
static <T extends AutoCloseable,R> |
autoClosing(ThrowingFunction<T,R,? extends Exception> function)
Wrap a function which yields a result from processing an
AutoCloseable
(typically an InputStream or similar) into a new Function which will always close
the AutoCloseable when the given function returns, successfully or throwing an exception. |
static InputStream |
limit(InputStream inputStream,
long maxBytesToRead,
Supplier<? extends Exception> throwIfTooManyBytes)
Limit the number of bytes to be read from an
InputStream. |
public static <T extends AutoCloseable> Consumer<T> autoClosing(ThrowingConsumer<T,? extends Exception> consumer)
AutoCloseable
(typically an InputStream or similar) into a new Consumer which will always close
the AutoCloseable when the given consumer returns, successfully or throwing an exception.consumer - the ThrowingConsumer taking an AutoCloseable as argument.Consumer which will handle closing of the passed AutoCloseable.public static <T extends AutoCloseable,R> Function<T,R> autoClosing(ThrowingFunction<T,R,? extends Exception> function)
AutoCloseable
(typically an InputStream or similar) into a new Function which will always close
the AutoCloseable when the given function returns, successfully or throwing an exception.function - the ThrowingFunction taking an AutoCloseable as argument.Function which will handle closing of the passed AutoCloseable.public static InputStream limit(InputStream inputStream, long maxBytesToRead, Supplier<? extends Exception> throwIfTooManyBytes)
InputStream. If the number of bytes exceeds the given threshold, an exception
will be thrown.inputStream - The InputStream to limit bytes to read from.maxBytesToRead - The limit in bytes.throwIfTooManyBytes - Supplier of exception to throw if more bytes are read than the max allowed. If the supplier returns
a non-RuntimeException which is not an IOException, it will be wrapped in a RuntimeException.Copyright © 2016 Digipost. All rights reserved.