Compare the contents of two Streams to determine if they are equal or not. This method buffers the input internally using BufferedInputStream if they are not already buffered. @param input1 the first stream @param input2 the second stream @return true if the content of the streams
(InputStream input1, InputStream input2)
| 1456 | * @throws IOException if an I/O error occurs |
| 1457 | */ |
| 1458 | public static boolean contentEquals(InputStream input1, InputStream input2) throws IOException { |
| 1459 | if (!(input1 instanceof BufferedInputStream)) { |
| 1460 | input1 = new BufferedInputStream(input1); |
| 1461 | } |
| 1462 | if (!(input2 instanceof BufferedInputStream)) { |
| 1463 | input2 = new BufferedInputStream(input2); |
| 1464 | } |
| 1465 | |
| 1466 | int ch = input1.read(); |
| 1467 | while (-1 != ch) { |
| 1468 | int ch2 = input2.read(); |
| 1469 | if (ch != ch2) { |
| 1470 | return false; |
| 1471 | } |
| 1472 | ch = input1.read(); |
| 1473 | } |
| 1474 | |
| 1475 | int ch2 = input2.read(); |
| 1476 | return (ch2 == -1); |
| 1477 | } |
| 1478 | |
| 1479 | /** |
| 1480 | * Compare the contents of two Readers to determine if they are equal or not. |