| Modifier and Type | Method and Description |
|---|---|
static long |
copy(InputStream
Copies all bytes from the input stream to the output stream.
|
static long |
copy(ReadableByteChannel
Copies all bytes from the readable channel to the writable channel.
|
static InputStream |
limit(InputStream
Wraps a
InputStream, limiting the number of bytes which can be read.
|
static ByteArrayDataInput |
newDataInput(byte[] bytes)
Returns a new
ByteArrayDataInput instance to read from the
bytes array from the beginning.
|
static ByteArrayDataInput |
newDataInput(byte[] bytes, int start)
Returns a new
ByteArrayDataInput instance to read from the
bytes array, starting at the given position.
|
static ByteArrayDataInput |
newDataInput(ByteArrayInputStream
Returns a new
ByteArrayDataInput instance to read from the given
ByteArrayInputStream.
|
static ByteArrayDataOutput |
newDataOutput()
Returns a new
ByteArrayDataOutput instance with a default size.
|
static ByteArrayDataOutput |
newDataOutput(ByteArrayOutputStream
Returns a new
ByteArrayDataOutput instance which writes to the given
ByteArrayOutputStream.
|
static ByteArrayDataOutput |
newDataOutput(int size)
Returns a new
ByteArrayDataOutput instance sized to hold
size bytes before resizing.
|
static OutputStream |
nullOutputStream()
Returns an
OutputStream that simply discards written bytes.
|
static int |
read(InputStream
Reads some bytes from an input stream and stores them into the buffer array
b.
|
static <T> T |
readBytes(InputStream
Process the bytes of the given input stream using the given processor.
|
static void |
readFully(InputStream
Attempts to read enough bytes from the stream to fill the given byte array, with the same behavior as
DataInput.
|
static void |
readFully(InputStream
Attempts to read
len bytes from the stream into the given array starting at
off, with the same behavior as
DataInput.
|
static void |
skipFully(InputStream
Discards
n bytes of data from the input stream.
|
static byte[] |
toByteArray(InputStream
Reads all bytes from an input stream into a byte array.
|
public static long copy(InputStreamfrom, OutputStream to) throws IOException
from - the input stream to read from
to - the output stream to write to
IOException - if an I/O error occurs
public static long copy(ReadableByteChannelfrom, WritableByteChannel to) throws IOException
from - the readable channel to read from
to - the writable channel to write to
IOException - if an I/O error occurs
public static byte[] toByteArray(InputStreamin) throws IOException
in - the input stream to read from
IOException - if an I/O error occurs
public static ByteArrayDataInputnewDataInput(byte[] bytes)
ByteArrayDataInput instance to read from the
bytes array from the beginning.
public static ByteArrayDataInputnewDataInput(byte[] bytes, int start)
ByteArrayDataInput instance to read from the
bytes array, starting at the given position.
IndexOutOfBoundsException - if
start is negative or greater than the length of the array
public static ByteArrayDataInputnewDataInput(ByteArrayInputStream byteArrayInputStream)
ByteArrayDataInput instance to read from the given
ByteArrayInputStream. The given input stream is not reset before being read from by the returned
ByteArrayDataInput.
public static ByteArrayDataOutputnewDataOutput()
ByteArrayDataOutput instance with a default size.
public static ByteArrayDataOutputnewDataOutput(int size)
ByteArrayDataOutput instance sized to hold
size bytes before resizing.
IllegalArgumentException - if
size is negative
public static ByteArrayDataOutputnewDataOutput(ByteArrayOutputStream byteArrayOutputSteam)
ByteArrayDataOutput instance which writes to the given
ByteArrayOutputStream. The given output stream is not reset before being written to by the returned
ByteArrayDataOutput and new data will be appended to any existing content.
Note that if the given output stream was not empty or is modified after the ByteArrayDataOutput is created, the contract for ByteArrayDataOutput will not be honored (the bytes returned in the byte array may not be exactly what was written via calls to ByteArrayDataOutput).
public static OutputStreamnullOutputStream()
OutputStream that simply discards written bytes.
public static InputStreamlimit(InputStream in, long limit)
InputStream, limiting the number of bytes which can be read.
in - the input stream to be wrapped
limit - the maximum number of bytes to be read
InputStream
public static void readFully(InputStreamin, byte[] b) throws IOException
DataInput.readFully(byte[]) . Does not close the stream.
in - the input stream to read from.
b - the buffer into which the data is read.
EOFException - if this stream reaches the end before reading all the bytes.
IOException - if an I/O error occurs.
public static void readFully(InputStreamin, byte[] b, int off, int len) throws IOException
len bytes from the stream into the given array starting at
off, with the same behavior as
DataInput.readFully(byte[], int, int) . Does not close the stream.
in - the input stream to read from.
b - the buffer into which the data is read.
off - an int specifying the offset into the data.
len - an int specifying the number of bytes to read.
EOFException - if this stream reaches the end before reading all the bytes.
IOException - if an I/O error occurs.
public static void skipFully(InputStreamin, long n) throws IOException
n bytes of data from the input stream. This method will block until the full amount has been skipped. Does not close the stream.
in - the input stream to read from
n - the number of bytes to skip
EOFException - if this stream reaches the end before skipping all the bytes
IOException - if an I/O error occurs, or the stream does not support skipping
public static <T> T readBytes(InputStreaminput, ByteProcessor <T> processor) throws IOException
input - the input stream to process
processor - the object to which to pass the bytes of the stream
IOException - if an I/O error occurs
public static int read(InputStreamin, byte[] b, int off, int len) throws IOException
b. This method blocks until
len bytes of input data have been read into the array, or end of file is detected. The number of bytes read is returned, possibly zero. Does not close the stream.
A caller can detect EOF if the number of bytes read is less than len. All subsequent calls on the same stream will return zero.
If b is null, a NullPointerException is thrown. If off is negative, or len is negative, or off+len is greater than the length of the array b, then an IndexOutOfBoundsException is thrown. If len is zero, then no bytes are read. Otherwise, the first byte read is stored into element b[off], the next one into b[off+1], and so on. The number of bytes read is, at most, equal to len.
in - the input stream to read from
b - the buffer into which the data is read
off - an int specifying the offset into the data
len - an int specifying the number of bytes to read
IOException - if an I/O error occurs