MCPcopy Index your code
hub / github.com/antlr/codebuff / contentEquals

Method contentEquals

output/java_guava/1.4.17/ByteSource.java:358–380  ·  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

356
357
358 public boolean contentEquals(ByteSource other) throws IOException {
359 checkNotNull(other);
360 byte[] buf1 = createBuffer();
361 byte[] buf2 = createBuffer();
362 Closer closer = Closer.create();
363 try {
364 InputStream in1 = closer.register(openStream());
365 InputStream in2 = closer.register(other.openStream());
366 while (true) {
367 int read1 = ByteStreams.read(in1, buf1, 0, buf1.length);
368 int read2 = ByteStreams.read(in2, buf2, 0, buf2.length);
369 if (read1 != read2 || !Arrays.equals(buf1, buf2)) {
370 return false;
371 } else if (read1 != buf1.length) {
372 return true;
373 }
374 }
375 } catch (Throwable e) {
376 throw closer.rethrow(e);
377 } finally {
378 closer.close();
379 }
380 }
381
382 /**
383 * 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