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

Method contentsEqual

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

Compares the contents of the two {@link InputStream}s for equality.

(InputStream in1, InputStream in2)

Source from the content-addressed store, hash-verified

953
954 /** Compares the contents of the two {@link InputStream}s for equality. */
955 static boolean contentsEqual(InputStream in1, InputStream in2) throws IOException {
956 byte[] buf1 = createBuffer();
957 byte[] buf2 = createBuffer();
958 while (true) {
959 int read1 = read(in1, buf1, 0, BUFFER_SIZE);
960 int read2 = read(in2, buf2, 0, BUFFER_SIZE);
961 if (read1 != read2 || !arraysEqual(buf1, buf2, read1)) {
962 return false;
963 } else if (read1 != BUFFER_SIZE) {
964 return true;
965 }
966 }
967 }
968
969 // The Arrays.equals(<arraytype>, int, int, <arraytype>, int, int) methods were not added until
970 // Java 9. This function is just returns the same result that

Callers 1

contentEqualsMethod · 0.95

Calls 3

createBufferMethod · 0.95
readMethod · 0.95
arraysEqualMethod · 0.95

Tested by

no test coverage detected