List of usage examples for org.apache.commons.io FileUtils contentEquals
public static boolean contentEquals(File file1, File file2) throws IOException
From source file:Compare.java
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed // TODO add your handling code here: DefaultTableModel model1 = (DefaultTableModel) FileDetails.getModel(); DefaultTableModel model2 = (DefaultTableModel) FileDetails1.getModel(); int count = 1; Boolean flag = false;//from w w w .ja va2 s . c o m for (Files filename : filenames1) { // String size = Long.toString(filename.Filesize) + "Bytes"; // model.addRow(new Object[]{count++,filename.Filename, size , filename.FileLocation}); boolean compare1 = false; for (Files fname : filenames2) { if (filename.Filename.equals(fname.Filename)) { File file1 = new File(filename.FileLocation); File file2 = new File(fname.FileLocation); flag = true; try { compare1 = FileUtils.contentEquals(file1, file2); } catch (IOException ex) { Logger.getLogger(Compare.class.getName()).log(Level.SEVERE, null, ex); } String size = Long.toString(filename.Filesize) + "Bytes"; String status; if (flag) { if (compare1) status = "same"; else status = " changed"; } else status = "deleted"; // model1.addColumn(count, new Object[] { status} ); model1.addRow(new Object[] { count++, filename.Filename, size, filename.FileLocation, status }); } } } }
From source file:com.chingo247.structureapi.persistence.service.ValidationService.java
private boolean firstTime(World world) throws IOException { File worldsFolder = new File(structureAPI.getStructureDataFolder(), "/restoreservice"); worldsFolder.mkdirs();/*from w w w . jav a2 s . c o m*/ File scWorldFile = new File(worldsFolder, world.getName()); File lockFile = new File(world.getWorldFolder(), "session.lock"); if (scWorldFile.exists()) { if (FileUtils.contentEquals(scWorldFile, lockFile)) { return false; } else { FileUtils.copyFile(lockFile, scWorldFile); return true; } } FileUtils.copyFile(lockFile, scWorldFile); return true; }
From source file:de.sulaco.bittorrent.service.downloader.TtorrentDownloaderTest.java
@Test public void testDownload() throws IOException, NoSuchAlgorithmException { // Start seeder and tracker Tracker tracker = startTracker();/*from w ww. j a va2 s . c o m*/ Client client = startSeeder(); // Download file DownloadListener downloadListener = Mockito.mock(DownloadListener.class); TtorrentDownloader ttorrentDownloader = new TtorrentDownloader(); ttorrentDownloader.setDownloadListener(downloadListener); ttorrentDownloader.setTimeout(60 * 1000); ttorrentDownloader.download(TORRENT_FILE, TEMPORARY_DIRECTORY); // Verification Mockito.verify(downloadListener, Mockito.times(1)).onDownloadStart(TORRENT_FILE); Mockito.verify(downloadListener, Mockito.times(1)).onDownloadProgress(TORRENT_FILE, 100); Mockito.verify(downloadListener, Mockito.times(1)).onDownloadEnd(TORRENT_FILE, DownloadState.COMPLETED); File source = new File(CONTENT_DIRECTORY + File.separator + CONTENT_NAME); File result = new File(TEMPORARY_DIRECTORY + File.separator + CONTENT_NAME); assertThat(result.exists()).isTrue(); assertThat(FileUtils.contentEquals(source, result)).isTrue(); // Tear down seeder and tracker client.stop(); tracker.stop(); }
From source file:edu.cornell.med.icb.goby.modes.TestReformatCompactReadsMode.java
/** * Validate read trimming//from w w w . j a v a 2 s . com * * @throws IOException if there is a problem reading or writing to the files */ @Test public void trimPairedReadsAt10() throws IOException { final ReformatCompactReadsMode reformat = new ReformatCompactReadsMode(); final String inputFilename = "test-data/compact-reads/small-paired.compact-reads"; reformat.setInputFilenames(inputFilename); // there are no reads in the input file longer than 23 reformat.setTrimReadLength(10); final String outputFilename = "test-results/reformat-test-trim-paired.compact-reads"; reformat.setOutputFile(outputFilename); reformat.execute(); final File inputFile = new File(inputFilename); final File outputFile = new File(outputFilename); assertFalse("The reformatted file should not be the same as the original", FileUtils.contentEquals(inputFile, outputFile)); ReadsReader reader = new ReadsReader(outputFilename); for (Reads.ReadEntry it : reader) { assertEquals(10, it.getSequence().size()); assertEquals(10, it.getSequencePair().size()); assertEquals(10, it.getQualityScores().size()); assertEquals(10, it.getQualityScoresPair().size()); } }
From source file:edu.unc.lib.dl.admin.collect.DepositBinCollectorTest.java
@Test(expected = IOException.class) public void collectCopyProblemTest() throws Exception { addBinFiles();/*w w w . j a va2 s .c o m*/ mockStatic(FileUtils.class); when(FileUtils.contentEquals(any(File.class), any(File.class))).thenReturn(true).thenReturn(false); try { manager.collect(null, "etd", new HashMap<String, String>()); } finally { verifyStatic(times(2)); FileUtils.contentEquals(any(File.class), any(File.class)); verifyStatic(); FileUtils.deleteDirectory(any(File.class)); verify(depositStatusFactory, never()).save(anyString(), anyMapOf(String.class, String.class)); assertEquals("No files should have been removed from bin", 3, binDirectory.list().length); } }
From source file:de.sulaco.bittorrent.service.downloader.TtorrentDownloaderTest.java
@Test public void testDownloadWithoutDownloadListener() throws IOException, NoSuchAlgorithmException { // Start seeder and tracker Tracker tracker = startTracker();/* www . j av a2 s .com*/ Client client = startSeeder(); // Download file TtorrentDownloader ttorrentDownloader = new TtorrentDownloader(); ttorrentDownloader.setTimeout(60 * 1000); ttorrentDownloader.download(TORRENT_FILE, TEMPORARY_DIRECTORY); // Verification File source = new File(CONTENT_DIRECTORY + File.separator + CONTENT_NAME); File result = new File(TEMPORARY_DIRECTORY + File.separator + CONTENT_NAME); assertThat(result.exists()).isTrue(); assertThat(FileUtils.contentEquals(source, result)).isTrue(); // Tear down seeder and tracker client.stop(); tracker.stop(); }
From source file:dynamicrefactoring.domain.xml.writer.RefactoringWriterTest.java
/** * Comprueba que la escritura se realiza correctamente cuando se aade toda * la informacin posible. Para ello se da valor a los campos de un objeto * de tipo DynamicRefactoringDefinition y luego se realiza la escritura; * posteriormente se hace una comprobacin del contenido del fichero creado * con el contenido que debera tener./*from w w w . j av a2 s . c o m*/ * * Esta informacin es: el nombre, la descripcin, la imagen, la motivacin, * varias entradas, precondiciones, acciones, postcondiciones, parmetros * ambiguos y ejemplos. * * @throws Exception * si se produce un error durante la escritura de la definicin * de la refactorizacin. */ @Test public void testWritingWithFullInformation() throws Exception { // Aadir informacin general DynamicRefactoringDefinition.Builder rd = createRefactoringDefinition("FullInformation", "Renames the class.", "The name of class does not reveal its intention."); rd.image("renameclass.JPG"); //$NON-NLS-1$ // Aadir entradas ArrayList<InputParameter> entradas = new ArrayList<InputParameter>(); entradas.add(new InputParameter.Builder("moon.core.Name").name("Old_name").from(CLASS).method("getName") .main(false).build()); entradas.add(new InputParameter.Builder("moon.core.Model").name("Model").from("").method("").main(false) .build()); entradas.add(new InputParameter.Builder("moon.core.classdef.ClassDef").name(CLASS).from("").method("") .main(true).build()); entradas.add(new InputParameter.Builder("moon.core.Name").name(NEW_NAME).from("").method("").main(false) .build()); rd.inputs(entradas); // aadir precondiciones,acciones y postcondiciones ArrayList<RefactoringMechanismInstance> preconditions = new ArrayList<RefactoringMechanismInstance>(); List<String> preconditionParameters = getPreconditionsParameters(); preconditions.add( new RefactoringMechanismInstance("NotExistsClassWithName", preconditionParameters, PRECONDITION)); //$NON-NLS-1$ rd.preconditions(preconditions); ArrayList<RefactoringMechanismInstance> actions = new ArrayList<RefactoringMechanismInstance>(); List<String> actionParameters = getActionsParameters(); actions.add(new RefactoringMechanismInstance(RENAME_CLASS, actionParameters, ACTION)); //$NON-NLS-1$ actions.add(new RefactoringMechanismInstance("RenameReferenceFile", actionParameters, ACTION)); //$NON-NLS-1$ actions.add(new RefactoringMechanismInstance("RenameClassType", actionParameters, ACTION)); //$NON-NLS-1$ actions.add(new RefactoringMechanismInstance("RenameGenericClassType", actionParameters, ACTION)); //$NON-NLS-1$ actions.add(new RefactoringMechanismInstance("RenameConstructors", actionParameters, ACTION)); //$NON-NLS-1$ actions.add(new RefactoringMechanismInstance("RenameJavaFile", actionParameters, ACTION)); //$NON-NLS-1$ rd.actions(actions); ArrayList<RefactoringMechanismInstance> postconditions = new ArrayList<RefactoringMechanismInstance>(); List<String> postConditionParameters = getPostConditionsParameters(); postconditions.add( new RefactoringMechanismInstance("NotExistsClassWithName", postConditionParameters, POSTCONDITION)); //$NON-NLS-1$ rd.postconditions(postconditions); // aadiendo los ejemplos ArrayList<RefactoringExample> ejemplos = new ArrayList<RefactoringExample>(); ejemplos.add(new RefactoringExample("ejemplo1_antes.txt", "ejemplo1_despues.txt")); rd.examples(ejemplos); HashSet<Category> categories = new HashSet<Category>(); categories.add(new Category("MiClasificacion", "MiCategoria")); rd.categories(categories); rd.keywords(new HashSet<String>()); writeRefactoring(rd.build()); assertTrue(FileUtils.contentEquals( new File(TestCaseRefactoringReader.TESTDATA_XML_READER_DIR + "FullInformation.xml"), //$NON-NLS-1$ new File(TESTDATA_XML_WRITER_DIR + "FullInformation.xml"))); }
From source file:edu.cornell.med.icb.goby.modes.TestReformatCompactReadsMode.java
/** * Validates that setting a maximum read length will not exclude reads that are * within the limit from being written to the output. * * @throws IOException if there is a problem reading or writing to the files *///from w ww .j av a2 s . co m @Test public void excludeReadLengthsAt35() throws IOException { final ReformatCompactReadsMode reformat = new ReformatCompactReadsMode(); final String inputFilename = "test-data/compact-reads/s_1_sequence_short.compact-reads"; reformat.setInputFilenames(inputFilename); reformat.setMaxReadLength(35); final String outputFilename = "test-results/reformat-test-exclude-read-lengths-at-extrreme.compact-reads"; reformat.setOutputFile(outputFilename); reformat.execute(); assertTrue(FileUtils.contentEquals(new File(inputFilename), new File(outputFilename))); }
From source file:de.sulaco.bittorrent.service.downloader.TtorrentDownloaderTest.java
@Test public void testDownloadResume() throws IOException, NoSuchAlgorithmException { // Start seeder and tracker Tracker tracker = startTracker();// ww w . j av a 2s .c om Client client = startSeeder(); // Copy partly available file to download directory FileUtils.copyFileToDirectory(new File(CONTENT_FILE_PART), new File(TEMPORARY_DIRECTORY)); File partFile = new File(CONTENT_FILE_PART); File sourceFile = new File(CONTENT_DIRECTORY + File.separator + CONTENT_NAME); assertThat(FileUtils.contentEquals(partFile, sourceFile)).isFalse(); // Download file DownloadListener downloadListener = Mockito.mock(DownloadListener.class); TtorrentDownloader ttorrentDownloader = new TtorrentDownloader(); ttorrentDownloader.setDownloadListener(downloadListener); ttorrentDownloader.setTimeout(60 * 1000); ttorrentDownloader.download(TORRENT_FILE, TEMPORARY_DIRECTORY); // Verification Mockito.verify(downloadListener, Mockito.times(1)).onDownloadEnd(TORRENT_FILE, DownloadState.COMPLETED); Mockito.verify(downloadListener, Mockito.times(1)).onDownloadStart(TORRENT_FILE); Mockito.verify(downloadListener, Mockito.times(1)).onDownloadProgress(TORRENT_FILE, 100); File downloadFile = new File(TEMPORARY_DIRECTORY + File.separator + CONTENT_NAME); assertThat(downloadFile.exists()).isTrue(); assertThat(FileUtils.contentEquals(sourceFile, downloadFile)).isTrue(); // Tear down seeder and tracker client.stop(); tracker.stop(); }
From source file:com.splicemachine.derby.impl.sql.execute.operations.InsertOperationIT.java
@Test public void testInsertBlob() throws Exception { InputStream fin = new FileInputStream(getResourceDirectory() + "order_line_500K.csv"); PreparedStatement ps = methodWatcher.prepareStatement("insert into FILES (name, doc) values (?,?)"); ps.setString(1, "csv_file"); ps.setBinaryStream(2, fin);/*ww w. ja v a 2 s . c o m*/ ps.execute(); ResultSet rs = methodWatcher.executeQuery("SELECT doc FROM FILES WHERE name = 'csv_file'"); byte buff[] = new byte[1024]; while (rs.next()) { Blob ablob = rs.getBlob(1); File newFile = new File(getBaseDirectory() + "/target/order_line_500K.csv"); if (newFile.exists()) { newFile.delete(); } newFile.createNewFile(); InputStream is = ablob.getBinaryStream(); FileOutputStream fos = new FileOutputStream(newFile); for (int b = is.read(buff); b != -1; b = is.read(buff)) { fos.write(buff, 0, b); } is.close(); fos.close(); } File file1 = new File(getResourceDirectory() + "order_line_500K.csv"); File file2 = new File(getBaseDirectory() + "/target/order_line_500K.csv"); Assert.assertTrue("The files contents are not equivalent", FileUtils.contentEquals(file1, file2)); }