public class IoUtils
extends java.lang.Object
Shared IO utility operations.
Constructor and Description |
---|
IoUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
copyAsString(java.io.BufferedInputStream inputStream)
Safely copies the contents of the
BufferedInputStream to a String and resets the stream. |
static byte[] |
streamToBytes(java.io.InputStream inputStream)
Reads all bytes from the stream into a byte array.
|
static byte[] |
streamToBytes(java.io.InputStream inputStream,
boolean close) |
static void |
transfer(java.io.InputStream istream,
java.io.OutputStream ostream,
boolean close)
Transfers the contents of the
InputStream into the OutputStream , optionally closing the stream. |
public static byte[] streamToBytes(java.io.InputStream inputStream) throws java.io.IOException
Reads all bytes from the stream into a byte array.
inputStream
- the InputStream
java.io.IOException
- if there is a problem reading the streampublic static byte[] streamToBytes(java.io.InputStream inputStream, boolean close) throws java.io.IOException
java.io.IOException
public static java.lang.String copyAsString(java.io.BufferedInputStream inputStream) throws java.io.IOException, java.lang.IllegalStateException
Safely copies the contents of the BufferedInputStream
to a String
and resets the stream.
This method is generally only useful for testing and logging purposes.
inputStream
- the BufferedInputStreamjava.io.IOException
- if something goes wrong with the streamjava.lang.IllegalStateException
- if the stream cannot be resetpublic static void transfer(java.io.InputStream istream, java.io.OutputStream ostream, boolean close)
Transfers the contents of the InputStream
into the OutputStream
, optionally closing the stream.
istream
- the input streamostream
- the output streamclose
- whether or not to close the output stream