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

The following examples show how to use org.apache.commons.io.FileUtils#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: BaseDistributionAtReadPositionTest.java    From Drop-seq with MIT License 7 votes vote down vote up
@Test
public void writeOutput() {
	BaseDistributionAtReadPosition test= new BaseDistributionAtReadPosition();
	BaseDistributionMetricCollection result = test.gatherBaseQualities (TAGGED_FILE, "XC");
	File tempReportFile=getTempReportFile();

       result.writeOutput(tempReportFile);

	boolean testSuccess=false;
	try {
		testSuccess=FileUtils.contentEquals(tempReportFile, OUTPUT_EXPECTED_RESULT);
	} catch (IOException e) {
		e.printStackTrace();
	}

	Assert.assertTrue(testSuccess);
	tempReportFile.delete();

}
 
Example 2
Source File: BaseDistributionAtReadPositionTest.java    From Drop-seq with MIT License 6 votes vote down vote up
@Test
public void testDoWork () {
	BaseDistributionAtReadPosition test= new BaseDistributionAtReadPosition();
	File tempReportFile=getTempReportFile();
	test.INPUT=TAGGED_FILE;
	test.TAG="XC";
	test.OUTPUT=tempReportFile;
	test.doWork();

	boolean testSuccess=false;
	try {
		testSuccess=FileUtils.contentEquals(tempReportFile, OUTPUT_EXPECTED_RESULT);
	} catch (IOException e) {
		e.printStackTrace();
	}

	Assert.assertTrue(testSuccess);
	tempReportFile.delete();

}
 
Example 3
Source File: DependencyResolver.java    From zeppelin with Apache License 2.0 6 votes vote down vote up
public List<File> load(String artifact, Collection<String> excludes, File destPath)
    throws RepositoryException, IOException {
  List<File> libs = new LinkedList<>();

  if (StringUtils.isNotBlank(artifact)) {
    libs = load(artifact, excludes);

    for (File srcFile : libs) {
      File destFile = new File(destPath, srcFile.getName());
      if (!destFile.exists() || !FileUtils.contentEquals(srcFile, destFile)) {
        FileUtils.copyFile(srcFile, destFile);
        logger.debug("copy {} to {}", srcFile.getAbsolutePath(), destPath);
      }
    }
  }
  return libs;
}
 
Example 4
Source File: AssertFileEqualsTask.java    From aws-ant-tasks with Apache License 2.0 6 votes vote down vote up
public void execute() {
    checkParams();
    File file1 = new File(firstFile);
    if (!file1.exists()) {
        throw new BuildException("The file " + firstFile + "does not exist");
    }
    File file2 = new File(secondFile);
    if (!file2.exists()) {
        throw new BuildException("The file " + secondFile
                + "does not exist");
    }

    try {
        if (!FileUtils.contentEquals(file1, file2)) {
            throw new BuildException(
                    "The two input files are not equal in content");
        }
    } catch (IOException e) {
        throw new BuildException(
                "IOException while trying to compare content of files: "
                        + e.getMessage());
    }
}
 
Example 5
Source File: ReduceGtfTest.java    From Drop-seq with MIT License 5 votes vote down vote up
@Test
    public void testDoWork () {
    	ReduceGtf r = new ReduceGtf();
    	r.GTF=GTF_FILE5;
    	r.SEQUENCE_DICTIONARY=SD;
    	File o = getTempReportFile("ReduceGtf", ".reduced.gtf.gz");
    	// File o2 = getTempReportFile("ReduceGtf", ".reduced.gtf");
    	o.deleteOnExit();
    	// o2.deleteOnExit();
    	//r.OUTPUT=GTF_FILE5_REDUCED;
    	r.OUTPUT=o;
    	r.ENHANCE_GTF=true;
    	int ret = r.doWork();
    	Assert.assertTrue(ret==0);
//    	r.OUTPUT=o2;
//    	int ret2 = r.doWork();
//    	Assert.assertTrue(ret2==0);


    	try {
			boolean t1 = FileUtils.contentEquals(o, GTF_FILE5_REDUCED);
			Assert.assertTrue(t1);
		} catch (IOException e) {
			e.printStackTrace();
		}


    }
 
Example 6
Source File: FSSliceReaderTest.java    From attic-apex-malhar with Apache License 2.0 5 votes vote down vote up
@Test
public void testBytesReceived() throws IOException
{
  long blockSize = 1500;
  int noOfBlocks = (int)((testMeta.dataFile.length() / blockSize) + (((testMeta.dataFile.length() % blockSize) == 0) ?
      0 : 1));

  testMeta.blockReader.beginWindow(1);

  for (int i = 0; i < noOfBlocks; i++) {
    BlockMetadata.FileBlockMetadata blockMetadata = new BlockMetadata.FileBlockMetadata(
        testMeta.dataFile.getAbsolutePath(), i, i * blockSize,
        i == noOfBlocks - 1 ? testMeta.dataFile.length() : (i + 1) * blockSize,
        i == noOfBlocks - 1, i - 1);
    testMeta.blockReader.blocksMetadataInput.process(blockMetadata);
  }

  testMeta.blockReader.endWindow();

  List<Object> messages = testMeta.messageSink.collectedTuples;
  long totatBytesReceived = 0;

  File outputFile = new File(testMeta.output + "/reader_test_data.csv");
  FileOutputStream outputStream = new FileOutputStream(outputFile);

  for (Object message : messages) {
    @SuppressWarnings("unchecked")
    AbstractBlockReader.ReaderRecord<Slice> msg = (AbstractBlockReader.ReaderRecord<Slice>)message;
    totatBytesReceived += msg.getRecord().length;
    outputStream.write(msg.getRecord().buffer);
  }
  outputStream.close();

  Assert.assertEquals("number of bytes", testMeta.dataFile.length(), totatBytesReceived);
  FileUtils.contentEquals(testMeta.dataFile, outputFile);
}
 
Example 7
Source File: JarContentsManager.java    From flow with Apache License 2.0 5 votes vote down vote up
private void copyJarEntryTrimmingBasePath(JarFile jarFile,
        ZipEntry jarEntry, String basePath, File outputDirectory) {
    String fullPath = jarEntry.getName();
    String relativePath = fullPath
            .substring(fullPath.toLowerCase(Locale.ENGLISH)
                    .indexOf(basePath.toLowerCase(Locale.ENGLISH))
                    + basePath.length());
    File target = new File(outputDirectory, relativePath);
    try {
        if (target.exists()) {
            File tempFile = File.createTempFile(fullPath, null);
            FileUtils.copyInputStreamToFile(
                    jarFile.getInputStream(jarEntry), tempFile);
            if (!FileUtils.contentEquals(tempFile, target)) {
                FileUtils.forceDelete(target);
                FileUtils.moveFile(tempFile, target);
            } else {
                tempFile.delete();
            }
        } else {
            FileUtils.copyInputStreamToFile(
                    jarFile.getInputStream(jarEntry), target);
        }
    } catch (IOException e) {
        throw new UncheckedIOException(String.format(
                "Failed to extract jar entry '%s' from jarFile '%s'",
                jarEntry, outputDirectory), e);
    }
}
 
Example 8
Source File: DependencyResolver.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
public synchronized void copyLocalDependency(String srcPath, File destPath)
    throws IOException {
  if (StringUtils.isBlank(srcPath)) {
    return;
  }

  File srcFile = new File(srcPath);
  File destFile = new File(destPath, srcFile.getName());

  if (!destFile.exists() || !FileUtils.contentEquals(srcFile, destFile)) {
    FileUtils.copyFile(srcFile, destFile);
    logger.debug("copy {} to {}", srcFile.getAbsolutePath(), destPath);
  }
}
 
Example 9
Source File: ExtractorUtils.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/****
 * Checks if the DDL file is same for stat1 and stat2
 * @param stat1
 * @param stat2
 * @return true if the files are same
 */
public static boolean isDDLFileSame(GFXDSnapshotExportStat stat1, GFXDSnapshotExportStat stat2)  {
  File ddlFile1  = new File(stat1.getFileName());
  File ddlFile2 = new File(stat2.getFileName());
  try {
    return FileUtils.contentEquals(ddlFile1, ddlFile2);
  }catch (Exception e) {
    GemFireXDDataExtractorImpl.logInfo("Exception occurred while comparing the DDL", e);
  }
  return false;
}
 
Example 10
Source File: ExtractorUtils.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/****
 * Checks if the DDL file is same for stat1 and stat2
 * @param stat1
 * @param stat2
 * @return true if the files are same
 */
public static boolean isDDLFileSame(GFXDSnapshotExportStat stat1, GFXDSnapshotExportStat stat2)  {
  File ddlFile1  = new File(stat1.getFileName());
  File ddlFile2 = new File(stat2.getFileName());
  try {
    return FileUtils.contentEquals(ddlFile1, ddlFile2);
  }catch (Exception e) {
    GemFireXDDataExtractorImpl.logInfo("Exception occurred while comparing the DDL", e);
  }
  return false;
}
 
Example 11
Source File: ManageCertificateAction.java    From oxTrust with MIT License 5 votes vote down vote up
/**
 * Updates certificates from temporary working directory to production and
 * restarts services.
 * 
 * @return true if update was successful. false if update was aborted due to
 *         some error (perhaps permissions issue.)
 */
private boolean updateCertificates() {
	if (!compare(tomcatCertFN) || !compare(idpCertFN)) {
		facesMessages.add(FacesMessage.SEVERITY_ERROR,
				"Certificates and private keys should match. Certificate update aborted.");
		return false;
	}
	String tempDirFN = appConfiguration.getTempCertDir();
	String dirFN = appConfiguration.getCertDir();
	File certDir = new File(dirFN);
	File tempDir = new File(tempDirFN);
	if (tempDirFN == null || dirFN == null || !certDir.isDirectory() || !tempDir.isDirectory()) {
		facesMessages.add(FacesMessage.SEVERITY_ERROR, "Certificate update aborted due to filesystem error");
		return false;
	} else {
		File[] files = tempDir.listFiles();
		for (File file : files) {
			try {
				if (file.isFile()
						&& !FileUtils.contentEquals(file, new File(dirFN + File.separator + file.getName()))) {
					FileHelper.copy(file, new File(dirFN + File.separator + file.getName()));
					this.wereAnyChanges = true;
				}
			} catch (IOException e) {
				facesMessages.add(FacesMessage.SEVERITY_FATAL,
						"Certificate update failed. Certificates may have been corrupted. Please contact a Gluu administrator for help.");
				log.error("Error occured on certificates update:", e);
			}
		}
	}
	return true;
}
 
Example 12
Source File: CompareFiles.java    From butterfly with MIT License 5 votes vote down vote up
@Override
protected boolean compare(File baselineFile, File comparisonFile) {
    try {
        return FileUtils.contentEquals(baselineFile, comparisonFile);
    } catch (IOException e) {
        throw new TransformationUtilityException("An exception has happened when comparing files", e);
    }
}
 
Example 13
Source File: SelectCellsByNumTranscriptsTest.java    From Drop-seq with MIT License 5 votes vote down vote up
@Test
public void testDoWorkDualOrganism () throws IOException {

	File outFile = File.createTempFile("SelectCellsByNumTranscripts.", ".cellBarcodes");
	File outFileMinReads = File.createTempFile("SelectCellsByNumTranscripts.", ".minReads");
	outFile.deleteOnExit();
	outFileMinReads.deleteOnExit();

	List<String> organisms = Arrays.asList("HUMAN", "MOUSE");
	SelectCellsByNumTranscripts s = new SelectCellsByNumTranscripts();
	s.INPUT=this.DUAL_ORGANISM_BAM;
	s.ORGANISM=organisms;
	s.MIN_TRANSCRIPTS_PER_CELL=100;
	s.OUTPUT=outFile;
	s.MIN_READS_PER_CELL=null;
	s.OUTPUT_INTERIM_CELLS=outFileMinReads;
	s.READ_MQ=0;
	s.METRICS = File.createTempFile("SelectCellsByNumTranscripts.", ".metrics");
	s.METRICS.deleteOnExit();
	int success = s.doWork();

	try {
		boolean t1 = FileUtils.contentEquals(outFileMinReads, DUAL_ORGANISM_BAM_EXPECTED_CB_100_READS);
		boolean t2 = FileUtils.contentEquals(outFile, DUAL_ORGANISM_BAM_EXPECTED_CB_100_TRANSCRIPTS);
		Assert.assertTrue(t1);
		Assert.assertTrue(t2);
	} catch (IOException e) {
		e.printStackTrace();
	}

	Assert.assertEquals(0, success);

}
 
Example 14
Source File: ShaderJobFileOperations.java    From graphicsfuzz with Apache License 2.0 5 votes vote down vote up
public boolean areImagesOfShaderResultsIdentical(
    File referenceShaderResultFile,
    File variantShaderResultFile) throws IOException {

  //noinspection deprecation: OK in this class.
  File reference = getUnderlyingImageFileFromShaderJobResultFile(referenceShaderResultFile);
  //noinspection deprecation: OK in this class.
  File variant = getUnderlyingImageFileFromShaderJobResultFile(variantShaderResultFile);

  LOGGER.info("Comparing: {} and {}.", reference, variant);
  boolean identical = FileUtils.contentEquals(reference, variant);
  LOGGER.info("Identical? {}", identical);

  return identical;
}
 
Example 15
Source File: FileSystemTest.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
protected boolean checkContentEquals(File expected, String actual) throws IOException, CoreException {
	File actualContent = EFS.getStore(makeLocalPathAbsolute(actual)).toLocalFile(EFS.NONE, null);
	return FileUtils.contentEquals(expected, actualContent);
}
 
Example 16
Source File: RemoteLocalFilesystemTest.java    From cloudsync with GNU General Public License v2.0 4 votes vote down vote up
public static boolean hierarchieEquals(File root1,File root2) throws IOException {
    File[] files1 = root1.listFiles();
    File[] files2 = root2.listFiles();
    if(files1.length != files2.length) {
        return false;
    }
    
    Map<String,File> mapFiles2 = new HashMap<>();
    for(File f : files2) {
        mapFiles2.put(f.getName(), f);
    }
    
    for(File f1 : files1) {
        if(!mapFiles2.containsKey(f1.getName())) {
            return false;
        }
        
        File f2 = mapFiles2.get(f1.getName());
        if(f1.isDirectory() && f2.isDirectory()) {
            if(!hierarchieEquals(f1,f2)) {
                return false;
            }
        }
        else if(f1.isFile() && f2.isFile()) {
            if(!FileUtils.contentEquals(f1, f2)) {
                return false;
            }
        }
        else {
            return false;
        }
        
        mapFiles2.remove(f1.getName());
    }
    
    if(!mapFiles2.isEmpty()) {
        return false;
    }
    
    return true;
}
 
Example 17
Source File: TransformationOperationTest.java    From butterfly with MIT License 4 votes vote down vote up
@Test
public void readFileTest() throws IOException {
    TransformationOperation transformationOperation = getNewTestTransformationOperation().relative("pom.xml");
    File readFile = transformationOperation.getOrCreateReadFile(transformedAppFolder, transformationContext);
    FileUtils.contentEquals(new File(transformedAppFolder, "pom.xml"), readFile);
}
 
Example 18
Source File: DetectBeadSynthesisErrorsTest.java    From Drop-seq with MIT License 4 votes vote down vote up
@Test
public void testDoWork() {
	DetectBeadSynthesisErrors gbse = new DetectBeadSynthesisErrors();

	File report = getTempReportFile("DetectBeadSynthesisErrorsTest", ".report");
	File stats = getTempReportFile("DetectBeadSynthesisErrorsTest", ".stats");
	File summary = getTempReportFile("DetectBeadSynthesisErrorsTest", ".summary");
	File cleanBAM = getTempReportFile("DetectBeadSynthesisErrorsTest", ".bam");

	report.deleteOnExit();
	stats.deleteOnExit();
	summary.deleteOnExit();
	cleanBAM.deleteOnExit();

	gbse.INPUT=Arrays.asList(TEST_INDEL);
	gbse.NUM_BARCODES=1000; // more than the BAM has.
	gbse.SUMMARY=summary;
    gbse.OUTPUT=cleanBAM;
	gbse.REPORT=report;
	gbse.OUTPUT_STATS=stats;

	// test custom command line validation
	gbse.MAX_BARCODE_ERRORS_IN_RAM=5;  // i want to test serialization/deserialization.

	int result = gbse.doWork();
	Assert.assertEquals(0, result);

	try {
		boolean t1 = FileUtils.contentEquals(report, EXPECTED_REPORT);
		boolean t2 = FileUtils.contentEquals(stats, EXPECTED_STATS);
		boolean t3 = FileUtils.contentEquals(summary, EXPECTED_SUMMARY);
		Assert.assertTrue(t1);
		Assert.assertTrue(t2);
		Assert.assertTrue(t3);
	} catch (IOException e) {
		e.printStackTrace();
	}

	// test BAM
	CompareBAMTagValues cbtv = new CompareBAMTagValues();
	cbtv.INPUT_1=EXPECTED_BAM;
	cbtv.INPUT_2=cleanBAM;
	List<String> tags = new ArrayList<>();
	tags.add("XC");
	cbtv.TAGS=tags;
	int r = cbtv.doWork();
	Assert.assertTrue(r==0);




}
 
Example 19
Source File: AzureStorageGetReaderTestIT.java    From components with Apache License 2.0 4 votes vote down vote up
public Boolean fileExistsAndHasTheGoodSize(String file) throws Exception {
    File dl = new File(FOLDER_PATH_GET + "/" + file);
    File or = new File(FOLDER_PATH_PUT + "/" + file);
    return (dl.exists() && FileUtils.contentEquals(dl, or));
}
 
Example 20
Source File: CommandLineIT.java    From robot with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Compare each file in the example/results/ directory, to the corresponding file in the examples/
 * directory.
 *
 * @throws Exception on IO problems or file differences
 */
private void compareResults() throws Exception {
  IOHelper ioHelper = new IOHelper();
  File resultsDir = new File(resultsPath);
  for (File resultFile : resultsDir.listFiles()) {
    if (!resultFile.isFile()) {
      continue;
    }

    // Find the corresponding example file
    String examplePath = examplesPath + resultFile.getName();
    File exampleFile = new File(examplePath);
    if (!exampleFile.exists() || !exampleFile.isFile()) {
      throw new Exception(
          "Integration test file '"
              + resultsPath
              + resultFile.getName()
              + "' does not have a corresponding example file '"
              + examplePath
              + "'");
    }

    if (resultFile.getName().endsWith(".owl")) {
      // Compare OWL files using DiffOperation
      OWLOntology exampleOnt = ioHelper.loadOntology(exampleFile);
      OWLOntology resultOnt = ioHelper.loadOntology(resultFile);
      if (!DiffOperation.equals(exampleOnt, resultOnt)) {
        throw new Exception(
            "Integration test ontology '"
                + resultsPath
                + resultFile.getName()
                + "' is different from example ontology '"
                + examplePath
                + "'");
      }
    } else {
      // Compare all other files
      if (!FileUtils.contentEquals(exampleFile, resultFile)) {
        throw new Exception(
            "Integration test file '"
                + resultsPath
                + resultFile.getName()
                + "' is different from example file '"
                + examplePath
                + "'");
      }
    }
  }
}