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 possible.
|
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,
ByteBuffer output)
Allocates a 4096 byte[] for use as a temporary buffer and calls
copyStream(InputStream, OutputStream, byte[]) . |
static int |
copyStream(InputStream input,
ByteBuffer output,
byte[] buffer)
Copy the data from an
InputStream to a ByteBuffer , using the specified byte[] as a temporary buffer. |
static void |
copyStream(InputStream input,
ByteBuffer output,
int bufferSize)
Allocates a byte[] of the specified size for use as a temporary buffer and calls
copyStream(InputStream, ByteBuffer, byte[]) . |
static void |
copyStream(InputStream input,
OutputStream output)
Allocates a 4096 byte[] for use as a temporary buffer and calls
copyStream(InputStream, OutputStream, byte[]) . |
static void |
copyStream(InputStream input,
OutputStream output,
byte[] buffer)
Copy the data from an
InputStream to an OutputStream , using the specified byte[] as a temporary buffer. |
static void |
copyStream(InputStream input,
OutputStream output,
int bufferSize)
Allocates a byte[] of the specified size for use as a temporary buffer and calls
copyStream(InputStream, OutputStream, byte[]) . |
static byte[] |
copyStreamToByteArray(InputStream input)
Copy the data from an
InputStream to a byte array. |
static byte[] |
copyStreamToByteArray(InputStream input,
int estimatedSize)
Copy the data from an
InputStream to a byte array. |
static String |
copyStreamToString(InputStream input)
Calls
copyStreamToString(InputStream, int, String) using the input's available size
and the platform's default charset. |
static String |
copyStreamToString(InputStream input,
int estimatedSize)
Calls
copyStreamToString(InputStream, int, String) using the platform's default charset. |
static String |
copyStreamToString(InputStream input,
int estimatedSize,
String charset)
Copy the data from an
InputStream to a string using the specified charset. |
public static final int DEFAULT_BUFFER_SIZE
public static final byte[] EMPTY_BYTES
public static void copyStream(InputStream input, OutputStream output) throws IOException
copyStream(InputStream, OutputStream, byte[])
.IOException
public static void copyStream(InputStream input, OutputStream output, int bufferSize) throws IOException
copyStream(InputStream, OutputStream, byte[])
.IOException
public static void copyStream(InputStream input, OutputStream output, byte[] buffer) throws IOException
InputStream
to an OutputStream
, using the specified byte[] as a temporary buffer. The
stream is not closed.IOException
public static void copyStream(InputStream input, ByteBuffer output) throws IOException
copyStream(InputStream, OutputStream, byte[])
.IOException
public static void copyStream(InputStream input, ByteBuffer output, int bufferSize) throws IOException
copyStream(InputStream, ByteBuffer, byte[])
.IOException
public static int copyStream(InputStream input, ByteBuffer output, byte[] buffer) throws IOException
InputStream
to a ByteBuffer
, using the specified byte[] as a temporary buffer. The
buffer's limit is increased by the number of bytes copied, the position is left unchanged. The stream is not closed.output
- Must be a direct Buffer with native byte order and the buffer MUST be large enough to hold all the bytes in
the stream. No error checking is performed.IOException
public static byte[] copyStreamToByteArray(InputStream input) throws IOException
InputStream
to a byte array. The stream is not closed.IOException
public static byte[] copyStreamToByteArray(InputStream input, int estimatedSize) throws IOException
InputStream
to a byte array. The stream is not closed.estimatedSize
- Used to allocate the output byte[] to possibly avoid an array copy.IOException
public static String copyStreamToString(InputStream input) throws IOException
copyStreamToString(InputStream, int, String)
using the input's available
size
and the platform's default charset.IOException
public static String copyStreamToString(InputStream input, int estimatedSize) throws IOException
copyStreamToString(InputStream, int, String)
using the platform's default charset.IOException
public static String copyStreamToString(InputStream input, int estimatedSize, String charset) throws IOException
InputStream
to a string using the specified charset.estimatedSize
- Used to allocate the output buffer to possibly avoid an array copy.charset
- May be null to use the platform's default charset.IOException
public static void closeQuietly(Closeable c)
Copyright © 2017. All rights reserved.