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