StreamUtilspublic abstract class StreamUtils extends Object Provides utility methods for input and output streams. |
Fields Summary |
---|
public static final int | DEFAULT_BUFFER_SIZEDefault value is 2048. |
Methods Summary |
---|
public static void | copy(java.io.InputStream input, java.io.OutputStream output)Copies information from the input stream to the output stream using
a default buffer size of 2048 bytes.
//--------------------------------------------------------------------------
// Protected Variables:
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// Private Variables:
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// Constructors:
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
// Public Methods:
//--------------------------------------------------------------------------
copy(input, output, DEFAULT_BUFFER_SIZE);
| public static void | copy(java.io.InputStream input, java.io.OutputStream output, int bufferSize)Copies information from the input stream to the output stream using
the specified buffer size
byte[] buf = new byte[bufferSize];
int bytesRead = input.read(buf);
while (bytesRead != -1) {
output.write(buf, 0, bytesRead);
bytesRead = input.read(buf);
}
output.flush();
| public static void | copyThenClose(java.io.InputStream input, java.io.OutputStream output)Copies information between specified streams and then closes
both of the streams.
copy(input, output);
input.close();
output.close();
| public static byte[] | getBytes(java.io.InputStream input)
ByteArrayOutputStream result = new ByteArrayOutputStream();
copy(input, result);
result.close();
return result.toByteArray();
|
|