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,
DataSize maxDataToRead)
Limit the number of bytes to be read from an
InputStream. |
static InputStream |
limit(InputStream inputStream,
DataSize maxDataToRead,
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, DataSize maxDataToRead)
InputStream. The returned stream silently ends reading, i.e. returns
-1 from .read(), if the read bytes exceeds the given threshold. This behavior is appropriate
when it is actually not desireable to consume the entire stream, typically for processing some data known to be located in the leading
part of the stream, and it is imperative to protect against accidentally consuming an entire (potentially large) stream.inputStream - The InputStream to limit bytes to read from.maxDataToRead - The limit of data to read.limit(InputStream, DataSize, Supplier)public static InputStream limit(InputStream inputStream, DataSize maxDataToRead, 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.maxDataToRead - The limit of data to read.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 © 2018 Digipost. All rights reserved.