Back to Fresco

ByteStreams

docs/javadoc/reference/com/facebook/common/internal/ByteStreams.html

3.6.015.4 KB
Original Source

Fresco

|

|

Packages | Classes

Interfaces

Classes

Annotations

Packages | Classes

Summary: Methods | Inherited Methods | [Expand All]

public final class

ByteStreams

extends Object

| java.lang.Object | | ↳ | com.facebook.common.internal.ByteStreams |

Class Overview

Provides utility methods for working with byte arrays and I/O streams.

Summary

Public Methods
static long
Copies all bytes from the input stream to the output stream.
static int
Reads some bytes from an input stream and stores them into the buffer array b.
static void
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[]
Reads all bytes from an input stream into a byte array.
static byte[]
Reads all bytes from an input stream into a byte array.

| [Expand] Inherited Methods | | --- | | From class java.lang.Object

| Object | clone() | | boolean | equals(Object arg0) | | void | finalize() | | final Class<?> | getClass() | | int | hashCode() | | final void | notify() | | final void | notifyAll() | | String | toString() | | final void | wait(long arg0, int arg1) | | final void | wait(long arg0) | | final void | wait() |

|

Public Methods

public static long copy(InputStream from, OutputStream to)

Copies all bytes from the input stream to the output stream. Does not close or flush either stream.

Parameters

| from | the input stream to read from | | to | the output stream to write to |

Returns
  • the number of bytes copied
Throws

| IOException | if an I/O error occurs |

public 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. 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.

Parameters

| 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 |

Returns
  • the number of bytes read
Throws

| IOException | if an I/O error occurs |

public 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). Does not close the stream.

Parameters

| 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. |

Throws

| EOFException | if this stream reaches the end before reading all the bytes. | | IOException | if an I/O error occurs. |

public static byte[] toByteArray(InputStream in, int expectedSize)

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.

Throws

| IOException | |

public static byte[] toByteArray(InputStream in)

Reads all bytes from an input stream into a byte array. Does not close the stream.

Parameters

| in | the input stream to read from |

Returns
  • a byte array containing all the bytes from the stream
Throws

| IOException | if an I/O error occurs |

<!-- ========= METHOD DETAIL ======== --><!-- ========= END OF CLASS DATA ========= -->

+Generated by Doclava. +

<!-- end footer - @generated --> <!-- jd-content --> <!-- end doc-content --> <!-- end body-content -->