/** * @deprecated Use instead {@link org.apache.commons.io.IOUtils#contentEquals(java.io.InputStream, java.io.InputStream)} */ @Deprecated public static boolean contentEquals(InputStream input1, InputStream input2) throws IOException { return org.apache.commons.io.IOUtils.contentEquals(input1, input2); }
/** * @deprecated Use instead {@link org.apache.commons.io.IOUtils#contentEquals(java.io.Reader, java.io.Reader)} */ @Deprecated public static boolean contentEquals(Reader input1, Reader input2) throws IOException { return org.apache.commons.io.IOUtils.contentEquals(input1, input2); }
return IOUtils.contentEquals(input1, input2);
@Test public void testContentEquals_Reader_Reader() throws Exception { { final StringReader input1 = new StringReader(""); assertTrue(IOUtils.contentEquals(input1, input1)); } { final StringReader input1 = new StringReader("ABC"); assertTrue(IOUtils.contentEquals(input1, input1)); } assertTrue(IOUtils.contentEquals(new StringReader(""), new StringReader(""))); assertTrue(IOUtils.contentEquals(new BufferedReader(new StringReader("")), new BufferedReader(new StringReader("")))); assertTrue(IOUtils.contentEquals(new StringReader("ABC"), new StringReader("ABC"))); assertFalse(IOUtils.contentEquals(new StringReader("ABCD"), new StringReader("ABC"))); assertFalse(IOUtils.contentEquals(new StringReader("ABC"), new StringReader("ABCD"))); }
input1 = new FileInputStream(file1); input2 = new FileInputStream(file2); return IOUtils.contentEquals(input1, input2);
@Test public void testContentEquals_InputStream_InputStream() throws Exception { { final ByteArrayInputStream input1 = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); assertTrue(IOUtils.contentEquals(input1, input1)); } { final ByteArrayInputStream input1 = new ByteArrayInputStream("ABC".getBytes(StandardCharsets.UTF_8)); assertTrue(IOUtils.contentEquals(input1, input1)); } assertTrue(IOUtils .contentEquals(new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)), new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)))); assertTrue(IOUtils.contentEquals(new BufferedInputStream(new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8))), new BufferedInputStream( new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8))))); assertTrue(IOUtils.contentEquals(new ByteArrayInputStream("ABC".getBytes(StandardCharsets.UTF_8)), new ByteArrayInputStream("ABC".getBytes(StandardCharsets.UTF_8)))); assertFalse(IOUtils.contentEquals(new ByteArrayInputStream("ABCD".getBytes(StandardCharsets.UTF_8)), new ByteArrayInputStream("ABC".getBytes(StandardCharsets.UTF_8)))); assertFalse(IOUtils.contentEquals(new ByteArrayInputStream("ABC".getBytes(StandardCharsets.UTF_8)), new ByteArrayInputStream("ABCD".getBytes(StandardCharsets.UTF_8)))); }
@Test public void testCopyURLToFileWithTimeout() throws Exception { // Creates file final File file = new File(getTestDirectory(), "testCopyURLToFileWithTimeout"); file.deleteOnExit(); // Loads resource final String resourceName = "/java/lang/Object.class"; FileUtils.copyURLToFile(getClass().getResource(resourceName), file, 500, 500); // Tests that resuorce was copied correctly try (FileInputStream fis = new FileInputStream(file)) { assertTrue( "Content is not equal.", IOUtils.contentEquals( getClass().getResourceAsStream(resourceName), fis)); } //TODO Maybe test copy to itself like for copyFile() }
@Test public void testCopyURLToFile() throws Exception { // Creates file final File file = new File(getTestDirectory(), getName()); file.deleteOnExit(); // Loads resource final String resourceName = "/java/lang/Object.class"; FileUtils.copyURLToFile(getClass().getResource(resourceName), file); // Tests that resuorce was copied correctly try (FileInputStream fis = new FileInputStream(file)) { assertTrue( "Content is not equal.", IOUtils.contentEquals( getClass().getResourceAsStream(resourceName), fis)); } //TODO Maybe test copy to itself like for copyFile() }
private void validateSchemaUrl(State state, String targetSchemaFileName, boolean createConflictingFile) throws IOException { HiveAvroSerDeManager manager = new HiveAvroSerDeManager(state); HiveRegistrationUnit registrationUnit = (new HiveTable.Builder()).withDbName(TEST_DB).withTableName(TEST_TABLE).build(); // Clean up existing file String targetPathStr = new Path(this.testBasePath, targetSchemaFileName).toString(); File targetFile = new File(targetPathStr); targetFile.delete(); // create a conflicting file if (createConflictingFile) { targetFile.createNewFile(); } manager.addSerDeProperties(this.testBasePath, registrationUnit); Assert.assertNull(registrationUnit.getSerDeProps().getProp(HiveAvroSerDeManager.SCHEMA_LITERAL)); String schemaUrl = registrationUnit.getSerDeProps().getProp(HiveAvroSerDeManager.SCHEMA_URL); Assert.assertEquals(schemaUrl, targetPathStr); Assert.assertTrue(IOUtils.contentEquals(this.getClass().getResourceAsStream("/test-hive-table/hive-test.avsc"), new FileInputStream(schemaUrl))); }
contentFile = createTemplateFile( content ); if ( resultFile.exists() ) { Assert.assertTrue( IOUtils.contentEquals( resultFile.getContent().getInputStream(), contentFile.getContent() .getInputStream() ) ); } else {
protected boolean equalsStream(Blob other) { InputStream is = null; InputStream ois = null; try { is = getStream(); ois = other.getStream(); return IOUtils.contentEquals(is, ois); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(ois); } }
@Test public void testReadRootLibJarElement() throws IOException { String file = "lib" + File.separator + "test-jar-with-resources.jar"; URL url = getURL(file); InputStream actualInputStream = url.openStream(); assertThat(actualInputStream, notNullValue()); InputStream expectedInputStream = getClass().getClassLoader().getResourceAsStream(new File(MULE_MODULE_ARTIFACT_PLUGIN + separator + file).getPath()); assertThat(contentEquals(actualInputStream, expectedInputStream), is(true)); }
/** * @throws IOException * @see OpenmrsUtil#copyFile(InputStream, OutputStream) */ @Test public void copyFile_shouldCopyInputstreamToOutputstreamAndCloseTheOutputstream() throws IOException { String exampleInputStreamString = "ExampleInputStream"; ByteArrayInputStream expectedByteArrayInputStream = new ByteArrayInputStream(exampleInputStreamString.getBytes()); ByteArrayOutputStream output = spy(new ByteArrayOutputStream()); OpenmrsUtil.copyFile(expectedByteArrayInputStream, output); expectedByteArrayInputStream.reset(); ByteArrayInputStream byteArrayInputStreamFromOutputStream = new ByteArrayInputStream(output.toByteArray()); assertTrue(IOUtils.contentEquals(expectedByteArrayInputStream, byteArrayInputStreamFromOutputStream)); verify(output, times(1)).close(); }
/** * @deprecated Use instead {@link org.apache.commons.io.IOUtils#contentEquals(java.io.Reader, java.io.Reader)} */ @Deprecated public static boolean contentEquals(Reader input1, Reader input2) throws IOException { return org.apache.commons.io.IOUtils.contentEquals(input1, input2); }
/** * @deprecated Use instead {@link org.apache.commons.io.IOUtils#contentEquals(java.io.InputStream, java.io.InputStream)} */ @Deprecated public static boolean contentEquals(InputStream input1, InputStream input2) throws IOException { return org.apache.commons.io.IOUtils.contentEquals(input1, input2); }
private static void write(String string, File file) throws IOException { if (file.exists() && IOUtils.contentEquals(new FileReader(file), new StringReader(string))) { System.err .println("Not writing \"" + file.getName() + "\" as version in database is identical to local copy"); return; } BufferedWriter writer = new BufferedWriter(new FileWriter(file)); writer.write(string); writer.close(); } }
public static Object contentEquals(ActionContext actionContext) throws IOException { Thing self = actionContext.getObject("self"); Object input1 = self.doAction("getInput1", actionContext); Object input2 = self.doAction("getInput2", actionContext); if(input1 instanceof InputStream){ return IOUtils.contentEquals((InputStream) input1, (InputStream) input2); }else{ return IOUtils.contentEquals((Reader) input1, (Reader) input2); } }
private boolean equalBinaryContents(Node binaryNode, Resource binaryResource) throws RepositoryException { try (final InputStream nodeStream = binaryNode.getProperty(JcrConstants.JCR_DATA).getBinary().getStream(); final InputStream resourceStream = binaryResource.openStream()) { return IOUtils.contentEquals(nodeStream, resourceStream); } catch (IOException e) { log.error("Cannot read contents of '{}:{}'.", binaryResource.getOrigin().getName(), binaryResource.getName(), e); } return false; }
@Test public void testReadingValidFile() throws IOException, InvalidKeyException { File encryptedAttachmentBlob = TestUtils.loadFixture( "fixture/EncryptedAttachmentTest_cipherText_aes128"); File expectedPlainText = TestUtils.loadFixture( "fixture/EncryptedAttachmentTest_plainText"); InputStream encryptedInputStream = new EncryptedAttachmentInputStream( new FileInputStream(encryptedAttachmentBlob), EncryptionTestConstants.key16Byte); InputStream plainTextInputStream = new FileInputStream(expectedPlainText); Assert.assertTrue("Reading encrypted stream didn't give expected plain text", IOUtils.contentEquals(encryptedInputStream, plainTextInputStream)); }
@Test public void testContentPreparedAttachmentsTest() throws Exception { String imageAttachmentName = "bonsai-boston.jpg"; File imageFile = TestUtils.loadFixture("fixture/" + imageAttachmentName); Attachment att2 = new UnsavedFileAttachment(imageFile, "image/jpeg"); PreparedAttachment imagePatt = new PreparedAttachment(att2, datastore_manager_dir, 0, new AttachmentStreamFactory(new NullKeyProvider())); IOUtils.contentEquals( new FileInputStream(imageFile), new FileInputStream(imagePatt.tempFile)); }