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.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Class ByteStreams (2.0.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.0.0 (latest)](/java/docs/reference/google-http-client/latest/com.google.api.client.util.ByteStreams)\n- [1.47.1](/java/docs/reference/google-http-client/1.47.1/com.google.api.client.util.ByteStreams)\n- [1.46.3](/java/docs/reference/google-http-client/1.46.3/com.google.api.client.util.ByteStreams)\n- [1.45.3](/java/docs/reference/google-http-client/1.45.3/com.google.api.client.util.ByteStreams)\n- [1.44.2](/java/docs/reference/google-http-client/1.44.2/com.google.api.client.util.ByteStreams)\n- [1.43.2](/java/docs/reference/google-http-client/1.43.2/com.google.api.client.util.ByteStreams)\n- [1.42.3](/java/docs/reference/google-http-client/1.42.3/com.google.api.client.util.ByteStreams)\n- [1.41.8](/java/docs/reference/google-http-client/1.41.8/com.google.api.client.util.ByteStreams) \n\n public final class ByteStreams\n\n**Deprecated.** *use Guava's com.google.common.io.ByteStreams*\n\nProvides utility methods for working with byte arrays and I/O streams. \n\nInheritance\n-----------\n\n[java.lang.Object](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html) \\\u003e ByteStreams \n\nInherited Members\n-----------------\n\n[Object.clone()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#clone--) \n[Object.equals(Object)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#equals-java.lang.Object-) \n[Object.finalize()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#finalize--) \n[Object.getClass()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#getClass--) \n[Object.hashCode()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#hashCode--) \n[Object.notify()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notify--) \n[Object.notifyAll()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#notifyAll--) \n[Object.toString()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#toString--) \n[Object.wait()](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait--) \n[Object.wait(long)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-) \n[Object.wait(long,int)](https://docs.oracle.com/javase/8/docs/api/java/lang/Object.html#wait-long-int-)\n\nStatic Methods\n--------------\n\n### copy(InputStream from, OutputStream to) (deprecated)\n\n public static long copy(InputStream from, OutputStream to)\n\nCopies all bytes from the input stream to the output stream. Does not close or flush either\nstream.\n\n### limit(InputStream in, long limit) (deprecated)\n\n public static InputStream limit(InputStream in, long limit)\n\nWraps an input stream, limiting the number of bytes which can be read.\n\n### read(InputStream in, byte\\[\\] b, int off, int len) (deprecated)\n\n public static int read(InputStream in, byte[] b, int off, int len)\n\nReads some bytes from an input stream and stores them into the buffer array `b`.\n\nThis method blocks until `len` bytes of input data have been read into the array, or\nend of file is detected. The number of bytes read is returned, possibly zero. Does not close\nthe stream.\n\nA caller can detect EOF if the number of bytes read is less than `len`. All subsequent\ncalls on the same stream will return zero.\n\nIf `b` is null, a `NullPointerException` is thrown. If `off` is negative,\nor `len` is negative, or `off+len` is greater than the length of the array `\nb`, then an `IndexOutOfBoundsException` is thrown. If `len` is zero, then no bytes\nare read. Otherwise, the first byte read is stored into element `b[off]`, the next one\ninto `b[off+1]`, and so on. The number of bytes read is, at most, equal to `len`."]]