- * Copied from Apache Commons IO 2.5. - *
- * - * @param inputStream the InputStream to wrap or return (not {@code null}) - * @return the given InputStream or a new {@link BufferedInputStream} for the - * given InputStream - * @throws NullPointerException if the input parameter is {@code null} - */ - @SuppressWarnings("resource") - private static BufferedInputStream buffer(final InputStream inputStream) { - // reject null early on rather than waiting for IO operation to fail - // not checked by BufferedInputStream - Objects.requireNonNull(inputStream, "inputStream"); - return inputStream instanceof BufferedInputStream ? (BufferedInputStream) inputStream - : new BufferedInputStream(inputStream); - } - - /** - * Checks whether in1 and in2 is equal. - *- * Copied from Apache Commons IO 2.5. - *
- * - * @param input1 the input1. - * @param input2 the input2. - * @return {@code true} if in1 and in2 is equal, else {@code false}. - * @throws IOException if an I/O error occurs. - */ - @SuppressWarnings("resource") - private static boolean contentsEquals(final InputStream input1, final InputStream input2) throws IOException { - if (input1 == input2) { - return true; - } - if (input1 == null ^ input2 == null) { - return false; - } - final BufferedInputStream bufferedInput1 = buffer(input1); - final BufferedInputStream bufferedInput2 = buffer(input2); - int ch = bufferedInput1.read(); - while (EOF != ch) { - final int ch2 = bufferedInput2.read(); - if (ch != ch2) { - return false; - } - ch = bufferedInput1.read(); - } - return bufferedInput2.read() == EOF; - } - /** * Logs debug messages. * @@ -185,7 +126,7 @@ private static File extractLibraryFile(final String libFolderForCurrentOS, final try (InputStream nativeInputStream = NativeCodeLoader.class.getResourceAsStream(nativeLibraryFilePath)) { try (InputStream extractedLibIn = Files.newInputStream(path)) { debug("Validating '%s'...", extractedLibFile); - if (!contentsEquals(nativeInputStream, extractedLibIn)) { + if (!IOUtils.contentEquals(nativeInputStream, extractedLibIn)) { throw new IllegalStateException(String.format("Failed to write a native library file %s to %s", nativeLibraryFilePath, extractedLibFile)); }