public final class StreamUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
StreamUtils.OptimizedByteArrayOutputStream
A ByteArrayOutputStream which avoids copying of the byte array if not necessary.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_BUFFER_SIZE |
static byte[] |
EMPTY_BYTES |
Constructor and Description |
---|
StreamUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
closeQuietly(Closeable c)
Close and ignore all errors.
|
static void |
copyStream(InputStream input,
OutputStream output)
Copy the data from an
InputStream to an OutputStream without closing the stream. |
static void |
copyStream(InputStream input,
OutputStream output,
int bufferSize)
Copy the data from an
InputStream to an OutputStream without closing the stream. |
static byte[] |
copyStreamToByteArray(InputStream input)
Copy the data from an
InputStream to a byte array without closing the stream. |
static byte[] |
copyStreamToByteArray(InputStream input,
int estimatedSize)
Copy the data from an
InputStream to a byte array without closing the stream. |
static String |
copyStreamToString(InputStream input)
Copy the data from an
InputStream to a string using the default charset without closing the stream. |
static String |
copyStreamToString(InputStream input,
int approxStringLength)
Copy the data from an
InputStream to a string using the default charset. |
public static final int DEFAULT_BUFFER_SIZE
public static final byte[] EMPTY_BYTES
public static void copyStream(InputStream input, OutputStream output) throws IOException
InputStream
to an OutputStream
without closing the stream.IOException
public static void copyStream(InputStream input, OutputStream output, int bufferSize) throws IOException
InputStream
to an OutputStream
without closing the stream.IOException
public static byte[] copyStreamToByteArray(InputStream input) throws IOException
InputStream
to a byte array without closing the stream.IOException
public static byte[] copyStreamToByteArray(InputStream input, int estimatedSize) throws IOException
InputStream
to a byte array without closing the stream.estimatedSize
- Used to preallocate a possibly correct sized byte array to avoid an array copy.IOException
public static String copyStreamToString(InputStream input) throws IOException
InputStream
to a string using the default charset without closing the stream.IOException
public static String copyStreamToString(InputStream input, int approxStringLength) throws IOException
InputStream
to a string using the default charset.approxStringLength
- Used to preallocate a possibly correct sized StringBulder to avoid an array copy.IOException
public static void closeQuietly(Closeable c)
Copyright © 2014. All rights reserved.