java.lang.Object | |
↳ | com.facebook.common.internal.ByteStreams |
Provides utility methods for working with byte arrays and I/O streams.
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
static long |
copy(InputStream from, OutputStream to)
Copies all bytes from the input stream to the output stream.
| ||||||||||
static int |
read(InputStream in, byte[] b, int off, int len)
Reads some bytes from an input stream and stores them into the buffer array
b . | ||||||||||
static void |
readFully(InputStream in, byte[] b, int off, int len)
Attempts to read
len bytes from the stream into the given array starting at off , with the same behavior as readFully(byte[], int, int) . | ||||||||||
static byte[] |
toByteArray(InputStream in, int expectedSize)
Reads all bytes from an input stream into a byte array.
| ||||||||||
static byte[] |
toByteArray(InputStream in)
Reads all bytes from an input stream into a byte array.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Copies all bytes from the input stream to the output stream. Does not close or flush either stream.
from | the input stream to read from |
---|---|
to | the output stream to write to |
IOException | if an I/O error occurs |
---|
Reads some bytes from an input stream and stores them into the buffer array 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 |
---|
Attempts to read len
bytes from the stream into the given array starting at off
, with the same behavior as 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. |
Reads all bytes from an input stream into a byte array. The given expected size is used to create an initial byte array, but if the actual number of bytes read from the stream differs, the correct result will be returned anyway.
IOException |
---|
Reads all bytes from an input stream into a byte array. Does not close the stream.
in | the input stream to read from |
---|
IOException | if an I/O error occurs |
---|