Java Code Examples for org.apache.commons.io.IOUtils#contentEquals()

The following examples show how to use org.apache.commons.io.IOUtils#contentEquals() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileStep.java    From data-prep with Apache License 2.0 6 votes vote down vote up
@Then("^I check that \"(.*)\" temporary file equals \"(.*)\" file$")
public void thenICheckThatTheFileIsTheExpectedOne(String temporaryFilename, String expectedFilename)
        throws IOException {
    LOG.debug("I check that {} temporary file equals {} file", temporaryFilename, expectedFilename);

    Path tempFile = Objects.requireNonNull(context.getTempFile(temporaryFilename)).toPath();

    try (InputStream tempFileStream = Files.newInputStream(tempFile);
            InputStream expectedFileStream = DataPrepStep.class.getResourceAsStream(expectedFilename)) {

        if (FileSystems.getDefault().getPathMatcher("glob:*.xlsx").matches(tempFile.getFileName())) {
            if (!ExcelComparator.compareTwoFile(new XSSFWorkbook(tempFileStream),
                    new XSSFWorkbook(expectedFileStream))) {
                failFileComparatorAlert(temporaryFilename, expectedFilename, tempFile);
            }
        } else if (!IOUtils.contentEquals(tempFileStream, expectedFileStream)) {
            failFileComparatorAlert(temporaryFilename, expectedFilename, tempFile);
        }
    }
}
 
Example 2
Source File: IOUtil.java    From celerio with Apache License 2.0 5 votes vote down vote up
public boolean contentEquals(Reader reader1, Reader reader2) {
    try {
        return IOUtils.contentEquals(reader1, reader2);
    } catch (Exception e) {
        return false;
    } finally {
        closeQuietly(reader1);
        closeQuietly(reader2);
    }
}
 
Example 3
Source File: DataFile.java    From mr4c with Apache License 2.0 5 votes vote down vote up
private static boolean compareContent(DataFile file1, DataFile file2) throws IOException {
	if ( file1.hasContent()!=file2.hasContent() ) {
		return false;
	} else if ( !file1.hasContent() ) {
		return true; // neither has content
	} else {
		return IOUtils.contentEquals(
			file1.getInputStream(),
			file2.getInputStream()
		);
	}
}
 
Example 4
Source File: AttachmentTest.java    From sync-android with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example 5
Source File: JScpWorkerTest.java    From celos with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetFileObjectByUri() throws Exception {
    JScpWorker worker = new JScpWorker("uname");
    URL res = Thread.currentThread().getContextClassLoader().getResource("com/collective/celos/ci/testing/config/target.json");
    FileObject object = worker.getFileObjectByUri(res.toURI());
    IOUtils.contentEquals(object.getContent().getInputStream(), new FileInputStream(res.getFile()));
}
 
Example 6
Source File: JScpWorkerTest.java    From celos with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetFileObjectByUriStringParam() throws Exception {
    JScpWorker worker = new JScpWorker("uname");
    URL res = Thread.currentThread().getContextClassLoader().getResource("com/collective/celos/ci/testing/config/target.json");
    FileObject object = worker.getFileObjectByUri(res.toURI().toString());
    IOUtils.contentEquals(object.getContent().getInputStream(), new FileInputStream(res.getFile()));
}
 
Example 7
Source File: TestFileUtils.java    From ontopia with Apache License 2.0 4 votes vote down vote up
/**
  * INTERNAL: Compares the contents of a file and a resource that will be loaded from classpath
  */
public static boolean compareFileToResource(String fileName, String resourceName) throws IOException {
  try (FileInputStream in1 = new FileInputStream(fileName); InputStream in2 = StreamUtils.getInputStream(resourceName)) {
    return IOUtils.contentEquals(in1, in2);
  }
}
 
Example 8
Source File: TestFileUtils.java    From ontopia with Apache License 2.0 4 votes vote down vote up
/**
  * INTERNAL: Compares the contents of a file and a resource that will be loaded from classpath
  */
public static boolean compareFileToResource(File file, String resourceName) throws IOException {
  try (FileInputStream in1 = new FileInputStream(file); InputStream in2 = StreamUtils.getInputStream(resourceName)) {
    return IOUtils.contentEquals(in1, in2);
  }
}
 
Example 9
Source File: PlainFileComparer.java    From celos with Apache License 2.0 4 votes vote down vote up
public FixObjectCompareResult check(TestRun testRun) throws Exception {
    if (!IOUtils.contentEquals(content, file.getContent())) {
        return FixObjectCompareResult.failed("File contents differed");
    }
    return FixObjectCompareResult.SUCCESS;
}