List of usage examples for org.apache.commons.io FileUtils checksumCRC32
public static long checksumCRC32(File file) throws IOException
From source file:ca.uviccscu.lp.server.main.MainFrame.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed l.info("Edit game action activated"); MainFrame.lockInterface();/*from w w w . j a v a 2 s. co m*/ MainFrame.updateTask("Editing game...", true); l.info("Starting game edit action"); DefaultTableModel mdl = (DefaultTableModel) jTable1.getModel(); final int row = jTable1.getSelectedRow(); if (row >= 0 && mdl.getValueAt(row, 0) != null) { AddGameDialog addGameDialog = new AddGameDialog(this, true); addGameDialog.setLocationRelativeTo(null); //addGameDialog.setVisible(true); final Game temp = GamelistStorage.getGame((String) mdl.getValueAt(row, 0)); final Game g = addGameDialog.popupEditDialog(temp); if (g != null) { l.trace("Edit done, checking for changes"); //l.trace("Calculating folder size: " + g.gameAbsoluteFolderPath); MainFrame.updateTask("Checking for changes...", true); MainFrame.updateGameInterfaceFromStorage(); boolean changed = true; if (temp.gameAbsoluteExecPath.equals(g.gameAbsoluteExecPath) && temp.gameAbsoluteFolderPath.equals(g.gameAbsoluteFolderPath)) { l.trace("Location same - assuming no changes made"); g.gameName = temp.gameName; g.gameBatCommands = temp.gameBatCommands; g.gamePName = temp.gamePName; g.gamePUser = temp.gamePUser; g.gamePWName = temp.gamePWName; g.gameRuntimeFlags = temp.gameRuntimeFlags; changed = false; } else { l.trace("Locations changed - rescanning the game"); g.gameStatus = 0; MainFrame.updateProgressBar(0, 0, 0, "Calculating game size", true, true); final ObjectPlaceholder obj = new ObjectPlaceholder(); SwingWorker worker = new SwingWorker<Long, Void>() { @Override public Long doInBackground() throws IOException { MainFrame.lockInterface(); l.trace("Checking size"); MainFrame.updateProgressBar(0, 0, 0, "Analyzing game size", true, true); obj.payload = FileUtils.sizeOfDirectory(new File(g.gameAbsoluteFolderPath)); l.trace("Checking files"); MainFrame.updateProgressBar(0, 0, 0, "Analyzing game files", true, true); g.gameFileNumber = FileUtils.listFiles(new File(g.gameAbsoluteFolderPath), null, true) .size(); l.trace("Checking CRC32"); MainFrame.updateProgressBar(0, 0, 0, "Analyzing game signature", true, true); g.gameExecCRC32 = FileUtils.checksumCRC32(new File(g.gameAbsoluteExecPath)); return ((Long) obj.payload); } @Override public void done() { l.trace("Finishing game check"); MainFrame.updateProgressBar(0, 0, 0, "Finishing game edit", false, false); g.gameSize = ((Long) obj.payload); /* double mbsize = Math.ceil(g.gameSize / (1024 * 1024)); jTable1.getModel().setValueAt(mbsize, row, 2); * */ g.copyTo(temp); Shared.lastCreatedGame = null; l.trace("Done editing game"); MainFrame.updateGameInterfaceFromStorage(); MainFrame.unlockInterface(); MainFrame.setReportingIdle(); } }; worker.execute(); } //we are trusting the size task to finish here ELSE TROUBLE /* GamelistStorage.removeGame(temp.gameName); GamelistStorage.addGame(g); * */ if (!changed) { MainFrame.unlockInterface(); MainFrame.setReportingIdle(); } MainFrame.updateGameInterfaceFromStorage(); } else { MainFrame.unlockInterface(); MainFrame.setReportingIdle(); MainFrame.updateGameInterfaceFromStorage(); } } else { l.trace("Game edit - bad selection or empty table"); JOptionPane.showMessageDialog(this, "Invalid selection - can't edit", "Edit error", JOptionPane.WARNING_MESSAGE); MainFrame.unlockInterface(); MainFrame.setReportingIdle(); MainFrame.updateGameInterfaceFromStorage(); } }
From source file:net.sourceforge.seqware.pipeline.plugins.SequencerRunReporterET.java
@Test public void runSequencerRunReporter() throws IOException { File createTempDir = Files.createTempDir(); String randomString = UUID.randomUUID().toString(); File testOutFile = new File(createTempDir, randomString + ".txt"); String listCommand = "-p net.sourceforge.seqware.pipeline.plugins.SequencerRunReporter " + "-- --output-filename " + testOutFile.getName(); String listOutput = ITUtility.runSeqWareJar(listCommand, ReturnValue.SUCCESS, createTempDir); Log.info(listOutput);/* w w w.java2 s .co m*/ File retrievedFile = new File(createTempDir, testOutFile.getName()); Assert.assertTrue("output file does not exist", retrievedFile.exists()); List<String> readLines = FileUtils.readLines(testOutFile); Assert.assertTrue("incorrect number of lines", readLines.size() == 25); long checksumCRC32 = FileUtils.checksumCRC32(testOutFile); Assert.assertTrue("incorrect output checksum", checksumCRC32 == 1696717973L); }
From source file:net.sourceforge.seqware.pipeline.plugins.WorkflowRunReporterET.java
@Test public void runWorkflowRunReporter() throws IOException { File createTempDir = Files.createTempDir(); String randomString = UUID.randomUUID().toString(); File testOutFile = new File(createTempDir, randomString + ".txt"); String listCommand = "-p net.sourceforge.seqware.pipeline.plugins.WorkflowRunReporter " + "-- --output-filename " + testOutFile.getName() + " --workflow-run-accession 6698"; String listOutput = ITUtility.runSeqWareJar(listCommand, ReturnValue.SUCCESS, createTempDir); Log.info(listOutput);/* www .j a v a 2 s. co m*/ File retrievedFile = new File(createTempDir, testOutFile.getName()); Assert.assertTrue("output file does not exist", retrievedFile.exists()); List<String> readLines = FileUtils.readLines(testOutFile); Assert.assertTrue("incorrect number of lines", readLines.size() == 2); long checksumCRC32 = FileUtils.checksumCRC32(testOutFile); Assert.assertTrue("incorrect output checksum" + checksumCRC32, checksumCRC32 == 255117433L); }
From source file:net.sourceforge.seqware.pipeline.plugins.WorkflowRunReporterET.java
@Test public void runFirstDate() throws IOException { File createTempDir = Files.createTempDir(); String randomString = UUID.randomUUID().toString(); File testOutFile = new File(createTempDir, randomString + ".txt"); String listCommand = "-p net.sourceforge.seqware.pipeline.plugins.WorkflowRunReporter " + "-- --output-filename " + testOutFile.getName() + " --workflow-accession 2861 --time-period 2012-01-01 "; String listOutput = ITUtility.runSeqWareJar(listCommand, ReturnValue.SUCCESS, createTempDir); Log.info(listOutput);/* w ww. j a va 2s.co m*/ File retrievedFile = new File(createTempDir, testOutFile.getName()); Assert.assertTrue("output file does not exist", retrievedFile.exists()); List<String> readLines = FileUtils.readLines(testOutFile); Assert.assertTrue("incorrect number of lines ", readLines.size() == 7); long checksumCRC32 = FileUtils.checksumCRC32(testOutFile); Assert.assertTrue("incorrect output checksum " + checksumCRC32, checksumCRC32 == 2196935470L); }
From source file:net.sourceforge.seqware.pipeline.plugins.WorkflowRunReporterET.java
@Test public void runBothDates() throws IOException { File createTempDir = Files.createTempDir(); String randomString = UUID.randomUUID().toString(); File testOutFile = new File(createTempDir, randomString + ".txt"); String listCommand = "-p net.sourceforge.seqware.pipeline.plugins.WorkflowRunReporter " + "-- --output-filename " + testOutFile.getName() + " --workflow-accession 2861 --time-period 2012-01-01:2012-01-15 "; String listOutput = ITUtility.runSeqWareJar(listCommand, ReturnValue.SUCCESS, createTempDir); Log.info(listOutput);/* w w w . j av a 2s .c o m*/ File retrievedFile = new File(createTempDir, testOutFile.getName()); Assert.assertTrue("output file does not exist", retrievedFile.exists()); List<String> readLines = FileUtils.readLines(testOutFile); Assert.assertTrue("incorrect number of lines ", readLines.size() == 4); long checksumCRC32 = FileUtils.checksumCRC32(testOutFile); Assert.assertTrue("incorrect output checksum " + checksumCRC32, checksumCRC32 == 4072825873L); }
From source file:net.sourceforge.seqware.pipeline.plugins.WorkflowRunReporterET.java
@Test public void emptyDateRange() throws IOException { File createTempDir = Files.createTempDir(); String randomString = UUID.randomUUID().toString(); File testOutFile = new File(createTempDir, randomString + ".txt"); String listCommand = "-p net.sourceforge.seqware.pipeline.plugins.WorkflowRunReporter " + "-- --output-filename " + testOutFile.getName() + " --workflow-accession 2861 --time-period 2014-01-01"; String listOutput = ITUtility.runSeqWareJar(listCommand, ReturnValue.SUCCESS, createTempDir); File retrievedFile = new File(createTempDir, testOutFile.getName()); Assert.assertTrue("output file does not exist", retrievedFile.exists()); List<String> readLines = FileUtils.readLines(testOutFile); Assert.assertTrue("incorrect number of lines ", readLines.size() == 1); long checksumCRC32 = FileUtils.checksumCRC32(testOutFile); Assert.assertTrue("incorrect output checksum " + checksumCRC32, checksumCRC32 == 1649363086L); }
From source file:org.apache.flume.source.TestExecSource.java
@Test public void testProcess() throws InterruptedException, LifecycleException, EventDeliveryException, IOException { Channel channel = new MemoryChannel(); Context context = new Context(); context.put("command", "cat /etc/passwd"); context.put("keep-alive", "1"); context.put("capacity", "1000"); context.put("transactionCapacity", "1000"); Configurables.configure(source, context); Configurables.configure(channel, context); ChannelSelector rcs = new ReplicatingChannelSelector(); rcs.setChannels(Lists.newArrayList(channel)); source.setChannelProcessor(new ChannelProcessor(rcs)); source.start();//www. j a v a 2 s .co m Transaction transaction = channel.getTransaction(); transaction.begin(); Event event; FileOutputStream outputStream = new FileOutputStream( "/tmp/flume-execsource." + Thread.currentThread().getId()); while ((event = channel.take()) != null) { outputStream.write(event.getBody()); outputStream.write('\n'); } outputStream.close(); transaction.commit(); transaction.close(); source.stop(); File file1 = new File("/tmp/flume-execsource." + Thread.currentThread().getId()); File file2 = new File("/etc/passwd"); Assert.assertEquals(FileUtils.checksumCRC32(file1), FileUtils.checksumCRC32(file2)); FileUtils.forceDelete(file1); }
From source file:org.clickframes.util.CodeGenerator.java
private static long checksum(String text) throws IOException { File file = File.createTempFile("clickframes-", ".tmp"); FileUtils.writeStringToFile(file, normalizeWhitespaces(text)); return FileUtils.checksumCRC32(file); }
From source file:org.gluu.oxtrust.ldap.service.SubversionService.java
public List<SubversionFile> getDifferentFiles(List<SubversionFile> files) throws IOException { String inumFN = StringHelper.removePunctuation(applicationConfiguration.getApplianceInum()); String applianceSvnHomePath = String.format("%s/%s", baseSvnDir, inumFN); File dir = new File(applianceSvnHomePath); log.debug("Copying files to temporary repository folder"); String dirFn = dir.getAbsolutePath(); List<SubversionFile> differentFiles = new ArrayList<SubversionFile>(); for (SubversionFile subversionFile : files) { String fn = getLocalRepositoryFilePath(dirFn, subversionFile); File f = new File(fn); File persistedFile = new File(subversionFile.getLocalFile()); if ((!f.exists()) || FileUtils.checksumCRC32(persistedFile) != FileUtils.checksumCRC32(f)) { differentFiles.add(subversionFile); }//from w w w. jav a 2 s . co m } return differentFiles; }
From source file:org.grycap.gpf4med.DownloadServiceTest.java
@Test public void test() { System.out.println("DownloadServiceTest.test()"); try {/*from www .j a va2 s .c o m*/ // prepare input requests final String[] uris = { "http://www.chromix.com/downloadarea/testimages/frontier_color57sb.jpg", "http://www.hutchcolor.com/Targets_&_images_to_go/GrayBoat.zip", "http://www.chromix.com/downloadarea/testimages/frontier_color57s.jpg" }; // CRC32 checksum computed with Apache Commons IO final ImmutableMap<String, Map.Entry<Long, Long>> chc32sums = new ImmutableMap.Builder<String, Map.Entry<Long, Long>>() .put("frontier_color57sb.jpg", new AbstractMap.SimpleEntry<Long, Long>(1885150690l, 205632l)) .put("GrayBoat.zip", new AbstractMap.SimpleEntry<Long, Long>(2944050653l, 1286661l)) .put("frontier_color57s.jpg", new AbstractMap.SimpleEntry<Long, Long>(3600934165l, 967643l)) .build(); // test download with encryption final ImmutableMap<URI, File> requests = new ImmutableMap.Builder<URI, File>() .put(new URI(uris[0]), uriToFile(uris[0])).put(new URI(uris[1]), uriToFile(uris[1])) .put(new URI(uris[2]), uriToFile(uris[2])).build(); final ImmutableMap<URI, File> pending = new DownloadService().download(requests, null, null, null); assertThat("service response is not null", pending, notNullValue()); assertThat("there are no pending requests", pending.size(), equalTo(0)); for (final Map.Entry<String, Map.Entry<Long, Long>> chc32sum : chc32sums.entrySet()) { final File file = new File(TEST_OUTPUT_DIR, chc32sum.getKey()); assertThat("file exists", file.exists(), equalTo(true)); assertThat("file size coincides", chc32sum.getValue().getValue().longValue(), equalTo(file.length())); assertThat("CRC32 checksum coincides", chc32sum.getValue().getKey().longValue(), equalTo(FileUtils.checksumCRC32(file))); } // test download with encryption FileUtils.deleteQuietly(TEST_OUTPUT_DIR); final FileEncryptionProvider encryptionProvider = FileEncryptionProvider .getInstance(RandomStringUtils.randomAscii(1024)); final ImmutableMap<URI, File> pending2 = new DownloadService().download(requests, null, encryptionProvider, null); assertThat("service response is not null", pending2, notNullValue()); assertThat("there are no pending requests", pending2.size(), equalTo(0)); for (final Map.Entry<String, Map.Entry<Long, Long>> chc32sum : chc32sums.entrySet()) { final File file = new File(TEST_OUTPUT_DIR, chc32sum.getKey()); assertThat("file exists", file.exists(), equalTo(true)); // decrypt file final File clearFile = new File(file.getCanonicalPath() + ".tmp"); encryptionProvider.decrypt(new FileInputStream(file), new FileOutputStream(clearFile)); // check file assertThat("file size concides", chc32sum.getValue().getValue().longValue(), equalTo(clearFile.length())); assertThat("CRC32 checksum coincides", chc32sum.getValue().getKey().longValue(), equalTo(FileUtils.checksumCRC32(clearFile))); } // test file validation fail final String anyFile = uris[0]; final FileValidator alwaysFailValidator = mock(FileValidator.class); when(alwaysFailValidator.isValid(any(File.class))).thenReturn(false); final ImmutableMap<URI, File> pending3 = new DownloadService().download( new ImmutableMap.Builder<URI, File>() .put(new URI(anyFile), new File(TEST_OUTPUT_DIR, "any_file")).build(), alwaysFailValidator, null, null); assertThat("service response is not null", pending3, notNullValue()); assertThat("read invalid file is expected to return a pending file", pending3.size(), equalTo(1)); } catch (Exception e) { e.printStackTrace(System.err); fail("DownloadServiceTest.test() failed: " + e.getMessage()); } finally { System.out.println("DownloadServiceTest.test() has finished"); } }