MCPcopy Create free account
hub / github.com/antlr/codebuff / contentEquals

Method contentEquals

corpus/java/training/guava/io/ByteSource.java:338–362  ·  view source on GitHub ↗

Checks that the contents of this byte source are equal to the contents of the given byte source. @throws IOException if an I/O error occurs in the process of reading from this source or other

(ByteSource other)

Source from the content-addressed store, hash-verified

336 * {@code other}
337 */
338 public boolean contentEquals(ByteSource other) throws IOException {
339 checkNotNull(other);
340
341 byte[] buf1 = createBuffer();
342 byte[] buf2 = createBuffer();
343
344 Closer closer = Closer.create();
345 try {
346 InputStream in1 = closer.register(openStream());
347 InputStream in2 = closer.register(other.openStream());
348 while (true) {
349 int read1 = ByteStreams.read(in1, buf1, 0, buf1.length);
350 int read2 = ByteStreams.read(in2, buf2, 0, buf2.length);
351 if (read1 != read2 || !Arrays.equals(buf1, buf2)) {
352 return false;
353 } else if (read1 != buf1.length) {
354 return true;
355 }
356 }
357 } catch (Throwable e) {
358 throw closer.rethrow(e);
359 } finally {
360 closer.close();
361 }
362 }
363
364 /**
365 * Concatenates multiple {@link ByteSource} instances into a single source. Streams returned from

Callers 1

equalMethod · 0.45

Calls 9

createMethod · 0.95
registerMethod · 0.95
openStreamMethod · 0.95
readMethod · 0.95
rethrowMethod · 0.95
closeMethod · 0.95
equalsMethod · 0.65
checkNotNullMethod · 0.45
createBufferMethod · 0.45

Tested by

no test coverage detected