List of usage examples for org.apache.commons.io FileUtils checksumCRC32
public static long checksumCRC32(File file) throws IOException
From source file:au.com.borner.salesforce.util.FileUtilities.java
public static boolean createLocalFile(String path, AbstractSourceCode sObject) { String fileNameWithExtension = sObject.getFullyQualifiedFileName(sObject.getName()); File localFile = new File(path + File.separator + fileNameWithExtension); double crcResult; try {/*from w w w . j a v a 2 s . co m*/ FileUtils.writeStringToFile(localFile, sObject.getBody()); crcResult = FileUtils.checksumCRC32(localFile); } catch (IOException e) { logger.error("Error creating file " + localFile.getPath()); return false; } if (sObject.getBodyCRC() != null && !sObject.getBodyCRC().equals(crcResult)) { logger.error("Body CRC does not match for class " + localFile.getPath()); localFile.delete(); return false; } try { createMetadataFile(path, fileNameWithExtension, sObject); } catch (Exception e) { logger.error("Error creating metadata file " + path + File.separator + fileNameWithExtension + ".sfmd", e); localFile.delete(); return false; } return true; }
From source file:com.chingo247.structureapi.SchematicData.java
public static SchematicData load(File schematic) throws IOException, DataException { CuboidClipboard cc = SchematicFormat.MCEDIT.load(schematic); long checksum = FileUtils.checksumCRC32(schematic); int blocks = SchematicUtil.count(cc, true); return new SchematicData(checksum, cc.getWidth(), cc.getHeight(), cc.getLength(), blocks); }
From source file:ca.uviccscu.lp.persistence.GamelistStorage.java
public static synchronized boolean checkGameChanged(Game g) throws IOException { l.trace("Checking if game same: " + g.gameName); File f = new File(g.gameAbsoluteFolderPath); lastFileNumber = FileUtils.listFiles(f, null, true).size(); boolean a = (g.gameFileNumber == lastFileNumber); lastCRC = FileUtils.checksumCRC32(new File(g.gameAbsoluteExecPath)); boolean b = (g.gameExecCRC32 == lastCRC); lastSize = FileUtils.sizeOfDirectory(f); boolean c = (g.gameSize == lastSize); l.trace("File number same: " + a + "| Exec CRC32 same: " + b + "| Size same: " + c); return !(a && b && c); }
From source file:mase.evorbc.KdTreeRepertoire.java
@Override public void load(File repo, File coordinates) throws IOException { repFile = repo;//from w ww . ja va 2 s .co m repFileHash = FileUtils.checksumCRC32(repFile); if (coordinates != null) { coordsFile = coordinates; coordsFileHash = FileUtils.checksumCRC32(coordsFile); } List<PersistentSolution> solutions; try { solutions = SolutionPersistence.readSolutionsFromTar(repo); } catch (Exception ex) { Logger.getLogger(ArbitratorFactory.class.getName()).log(Level.SEVERE, null, ex); return; } Map<Integer, double[]> coords = null; if (coordinates != null) { coords = fileCoordinates(coordinates); if (coords.size() != solutions.size()) { throw new IOException("Number of solutions in repertoire does not match number of coordinates"); } } else { coords = encodedCoordinates(solutions); } int n = coords.get(solutions.get(0).getIndex()).length; bounds = new Pair[n]; for (int i = 0; i < n; i++) { double min = Double.POSITIVE_INFINITY; double max = Double.NEGATIVE_INFINITY; for (double[] c : coords.values()) { min = Math.min(min, c[i]); max = Math.max(max, c[i]); } bounds[i] = Pair.of(min, max); } tree = new KdTree.Euclidean<>(n); for (int i = 0; i < solutions.size(); i++) { PersistentSolution sol = solutions.get(i); AgentController ac = sol.getController().getAgentControllers(1)[0]; double[] c = coords.get(sol.getIndex()); if (c == null) { throw new IOException("Coordinate not found for index " + sol.getIndex()); } tree.addPoint(c, ac); } }
From source file:com.chingo247.structureapi.plan.schematic.Schematic.java
public static Schematic load(File schematic) throws IOException, DataException { CuboidClipboard cc = SchematicFormat.MCEDIT.load(schematic); long checksum = FileUtils.checksumCRC32(schematic); int blocks = SchematicUtil.count(cc, true); return new Schematic(schematic, cc.getWidth(), cc.getHeight(), cc.getLength(), checksum, blocks); }
From source file:algorithm.QRCodeWatermarkingTest.java
@Test public void separateFileTest() { try {//from ww w . j a v a 2 s.c o m File carrier = TestDataProvider.PNG_FILE; File payload = TestDataProvider.TXT_FILE_2; QRCodeWatermarking algorithm = new QRCodeWatermarking(); // Test encapsulation: List<File> payloadList = new ArrayList<File>(); payloadList.add(payload); // separate file encapsulation: algorithm.setCarrierEncapsulation(false); File outputFile = algorithm.encapsulate(carrier, payloadList); assertNotNull(outputFile); // Test restore - separate file encapsulation: List<RestoredFile> restoredFiles = algorithm.restore(outputFile); assertEquals(1, restoredFiles.size()); RestoredFile restoredPayload = restoredFiles.get(0); assertNotNull(restoredPayload); assertEquals(FileUtils.checksumCRC32(payload), FileUtils.checksumCRC32(restoredPayload)); // check restoration metadata: assertEquals(payload.getName(), restoredPayload.getName()); assertEquals(algorithm, restoredPayload.algorithm); assertTrue(restoredPayload.checksumValid); assertTrue(restoredPayload.wasPayload); assertFalse(restoredPayload.wasCarrier); assertFalse(restoredPayload.relatedFiles.contains(restoredPayload)); } catch (IOException e) { e.printStackTrace(); } }
From source file:model.PayloadSegment.java
/** * A payload segment consists of: START_SEQ, restoration metadata, * END_HEADER_SEQ, payload bytes, END_SEQ. * /*from w ww . ja v a 2 s.c om*/ * The restoration metadata is saved in a {@link Properties} class, and * keeps the name of carrier and payload, as well as their checksums and the * name of the algorithm used to encapsulate. * * @param carrier * @param payload * @param algorithm */ public PayloadSegment(File carrier, File payload, AbstractAlgorithm algorithm) { String payloadChecksum = ""; String carrierChecksum = ""; try { this.payload = FileUtils.readFileToByteArray(payload); payloadChecksum += FileUtils.checksumCRC32(payload); carrierChecksum += FileUtils.checksumCRC32(carrier); } catch (IOException e) { } properties.put("carrierName", carrier.getName()); properties.put("carrierChecksum", carrierChecksum); properties.put("payloadName", payload.getName()); properties.put("payloadChecksum", payloadChecksum); properties.put("algorithm", algorithm.getClass().getName()); properties.put("carrierPath", "" + carrier.getAbsolutePath()); properties.put("payloadPath", "" + payload.getAbsolutePath()); }
From source file:de.vibee.releaselister.control.CRCChecker.java
/** * Verifies an MP3 Release/*w ww .ja v a2s . c o m*/ * @param release Release to verify */ public void checkSfv(Release release) { if (Thread.currentThread().isInterrupted()) { return; } if (!release.isReleaseComplete()) { release.setReleaseIsValid(false); return; } boolean isValid = true; for (AudioFileWithChecksum m : release.getAudioFiles()) { if (!m.getAudioFileExists()) { isValid = false; } else { try { if (m.getChecksum() == FileUtils.checksumCRC32(m.getAudioFile())) { m.setAudioFileIsValid(true); } else { m.setAudioFileIsValid(false); isValid = false; } } catch (IOException ex) { Logger.getLogger(CRCChecker.class.getName()).log(Level.SEVERE, null, ex); } } } release.setReleaseIsValid(isValid); }
From source file:model.RestoredFile.java
/** * Pass the checksum string from the restoration metadata to validate if * this file was restored correctly// w ww . j a v a2 s. com * * @param checksum * @return validity of the restoration * @throws IOException */ public boolean validateChecksum(String checksum) throws IOException { checksumValid = checksum.equals("" + FileUtils.checksumCRC32(this)); return checksumValid; }
From source file:algorithm.F5SteganographyTest.java
@Test public void f5SteganographyAlgorithmTest() { try {/* w w w. j a v a2 s.co m*/ File carrier = TestDataProvider.JPG_FILE; File payload = TestDataProvider.TXT_FILE; F5Steganography algorithm = new F5Steganography(); // Test encapsulation: List<File> payloadList = new ArrayList<File>(); payloadList.add(payload); File outputFile = algorithm.encapsulate(carrier, payloadList); assertNotNull(outputFile); // Test restore: Hashtable<String, RestoredFile> outputHash = new Hashtable<String, RestoredFile>(); for (RestoredFile file : algorithm.restore(outputFile)) { outputHash.put(file.getName(), file); } assertEquals(outputHash.size(), 2); RestoredFile restoredCarrier = outputHash.get(carrier.getName()); RestoredFile restoredPayload = outputHash.get(payload.getName()); assertNotNull(restoredCarrier); assertNotNull(restoredPayload); // only original payload can be restored, not carrier assertEquals(FileUtils.checksumCRC32(payload), FileUtils.checksumCRC32(restoredPayload)); assertEquals(FileUtils.checksumCRC32(outputFile), FileUtils.checksumCRC32(restoredCarrier)); // check restoration metadata: assertEquals("" + carrier.getAbsolutePath(), restoredCarrier.originalFilePath); assertEquals("" + payload.getAbsolutePath(), restoredPayload.originalFilePath); assertEquals(algorithm, restoredCarrier.algorithm); // This can't be true for steganography algorithms: // assertTrue(restoredCarrier.checksumValid); assertTrue(restoredPayload.checksumValid); assertTrue(restoredCarrier.wasCarrier); assertFalse(restoredCarrier.wasPayload); assertTrue(restoredPayload.wasPayload); assertFalse(restoredPayload.wasCarrier); assertTrue(restoredCarrier.relatedFiles.contains(restoredPayload)); assertFalse(restoredCarrier.relatedFiles.contains(restoredCarrier)); assertTrue(restoredPayload.relatedFiles.contains(restoredCarrier)); assertFalse(restoredPayload.relatedFiles.contains(restoredPayload)); } catch (IOException e) { e.printStackTrace(); } }