public class StreamOps
extends java.lang.Object
Constructor and Description |
---|
StreamOps() |
Modifier and Type | Method and Description |
---|---|
static void |
close(java.io.Closeable stream)
Closes the given stream, silently swallowing any
IOException . |
static byte[] |
readAll(java.io.InputStream input)
Reads the whole input stream into a byte array.
|
static <T> T |
readLines(java.io.InputStream input,
util.lambda.FunctionE<java.util.stream.Stream<java.lang.String>,T> reader,
java.nio.charset.Charset... encoding)
Builds a stream of lines out of the input data and passes the stream on
to the given reader to convert them into a value of type
T . |
static java.lang.String |
readLinesIntoString(java.io.InputStream input)
Reads the whole input stream into a string using the default character
encoding.
|
public static <T> T readLines(java.io.InputStream input, util.lambda.FunctionE<java.util.stream.Stream<java.lang.String>,T> reader, java.nio.charset.Charset... encoding)
T
.T
- the value type.input
- the input data.reader
- converts the stream of lines into a T-
value.encoding
- character encoding to use to read the input data; if not
given, then the default character encoding is used.java.lang.NullPointerException
- if any argument is null
.
The following checked exceptions are rethrown as unchecked (i.e.
the exception is masked as a runtime exception and thrown as is without
wrapping it in a RuntimeException
):
IOException
if an I/O occurs.
public static java.lang.String readLinesIntoString(java.io.InputStream input)
input
- the data to read.java.lang.NullPointerException
- if the argument is null
.
The following checked exceptions are rethrown as unchecked (i.e.
the exception is masked as a runtime exception and thrown as is without
wrapping it in a RuntimeException
):
IOException
if an I/O occurs.
public static byte[] readAll(java.io.InputStream input)
input
- the data to read.java.lang.NullPointerException
- if the argument is null
.
The following checked exceptions are rethrown as unchecked (i.e.
the exception is masked as a runtime exception and thrown as is without
wrapping it in a RuntimeException
):
IOException
if an I/O occurs.
public static void close(java.io.Closeable stream)
IOException
.stream
- the stream to close.java.lang.NullPointerException
- if the argument is null
.