MCPcopy
hub / github.com/google/guava / read

Method read

guava/src/com/google/common/io/ByteStreams.java:933–952  ·  view source on GitHub ↗

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

(InputStream in, byte[] b, int off, int len)

Source from the content-addressed store, hash-verified

931 * {@code off + len} is greater than {@code b.length}
932 */
933 @CanIgnoreReturnValue
934 // Sometimes you don't care how many bytes you actually read, I guess.
935 // (You know that it's either going to read len bytes or stop at EOF.)
936 public static int read(InputStream in, byte[] b, int off, int len) throws IOException {
937 checkNotNull(in);
938 checkNotNull(b);
939 if (len < 0) {
940 throw new IndexOutOfBoundsException(String.format("len (%s) cannot be negative", len));
941 }
942 checkPositionIndexes(off, off + len, b.length);
943 int total = 0;
944 while (total < len) {
945 int result = in.read(b, off + total, len - total);
946 if (result == -1) {
947 break;
948 }
949 total += result;
950 }
951 return total;
952 }
953
954 /** Compares the contents of the two {@link InputStream}s for equality. */
955 static boolean contentsEqual(InputStream in1, InputStream in2) throws IOException {

Callers 9

readFullyMethod · 0.95
contentsEqualMethod · 0.95
copyMethod · 0.45
toByteArrayInternalMethod · 0.45
toByteArrayMethod · 0.45
exhaustMethod · 0.45
readMethod · 0.45
skipUpToMethod · 0.45
readBytesMethod · 0.45

Calls 3

checkNotNullMethod · 0.45
formatMethod · 0.45
checkPositionIndexesMethod · 0.45

Tested by

no test coverage detected