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)
| 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 |
no test coverage detected