if (com.google.common.io.Files.equal(currentFile.get().getFile(), dest)) { logger.warn("Completed file " + dest + " already exists, but files match, so continuing.");
public void testEqual() throws IOException { File asciiFile = getTestFile("ascii.txt"); File i18nFile = getTestFile("i18n.txt"); assertFalse(Files.equal(asciiFile, i18nFile)); assertTrue(Files.equal(asciiFile, asciiFile)); File temp = createTempFile(); Files.copy(asciiFile, temp); assertTrue(Files.equal(asciiFile, temp)); Files.copy(i18nFile, temp); assertTrue(Files.equal(i18nFile, temp)); Files.copy(asciiFile, temp); RandomAccessFile rf = new RandomAccessFile(temp, "rw"); rf.writeByte(0); rf.close(); assertEquals(asciiFile.length(), temp.length()); assertFalse(Files.equal(asciiFile, temp)); assertTrue(Files.asByteSource(asciiFile).contentEquals(Files.asByteSource(asciiFile))); // 0-length files have special treatment (/proc, etc.) assertTrue(Files.equal(asciiFile, new BadLengthFile(asciiFile, 0))); }
public void testMove() throws IOException { File i18nFile = getTestFile("i18n.txt"); File temp1 = createTempFile(); File temp2 = createTempFile(); Files.copy(i18nFile, temp1); moveHelper(true, temp1, temp2); assertTrue(Files.equal(temp2, i18nFile)); }
public void testMoveViaCopy() throws IOException { File i18nFile = getTestFile("i18n.txt"); File temp1 = createTempFile(); File temp2 = createTempFile(); Files.copy(i18nFile, temp1); moveHelper(true, new UnmovableFile(temp1, false, true), temp2); assertTrue(Files.equal(temp2, i18nFile)); }
public void testNewWriter() throws IOException { File temp = createTempFile(); try { Files.newWriter(temp, null); fail("expected exception"); } catch (NullPointerException expected) { } try { Files.newWriter(null, Charsets.UTF_8); fail("expected exception"); } catch (NullPointerException expected) { } BufferedWriter w = Files.newWriter(temp, Charsets.UTF_8); try { w.write(I18N); } finally { w.close(); } File i18nFile = getTestFile("i18n.txt"); assertTrue(Files.equal(i18nFile, temp)); }
@Override protected boolean matchesSafely(final File item) { try { return Files.equal(expected, item); } catch (IOException e) { throw new RuntimeException(e); } }
private static boolean filesEqual(File file1, File file2) { try { return Files.equal(file1, file2); } catch (IOException e) { throw new UncheckedIOException(e); } } }
private static boolean filesEqual(File file1, File file2) { try { return Files.equal(file1, file2); } catch (IOException e) { throw new UncheckedIOException(e); } } }
@edu.umd.cs.findbugs.annotations.SuppressFBWarnings(value = "DM_DEFAULT_ENCODING") public static boolean compareFiles(File out, File gold) { try { return Files.equal(out, gold); } catch (IOException e) { e.printStackTrace(System.err); } return false; }
void verify() throws IOException { if (streamId.equals("file")) { assertTrue("File stream did not match.", Files.equal(testData.testFile, outFile)); } else { byte[] result = ((ByteArrayOutputStream)out).toByteArray(); ByteBuffer srcBuffer = testData.srcBuffer(streamId); ByteBuffer base; synchronized (srcBuffer) { base = srcBuffer.duplicate(); } byte[] expected = new byte[base.remaining()]; base.get(expected); assertEquals(expected.length, result.length); assertTrue("buffers don't match", Arrays.equals(expected, result)); } }
private static void assertFile(InputStream is, File org, TemporaryFolder folder, boolean close) throws IOException { try { File ret = folder.newFile(); copyToFile(is, ret); assertTrue(Files.equal(org, ret)); } finally { if (close) { IOUtils.closeQuietly(is); } } }
@Test public void testGyro() throws AnalysisEngineProcessException, ResourceInitializationException, IOException, URISyntaxException { processJCas( DocumentGraph.PARAM_OUTPUT_DIRECTORY, tempDirectory.toString(), DocumentGraph.PARAM_GRAPH_FORMAT, GraphFormat.GYRO.toString(), DocumentGraph.PARAM_OUTPUT_RELATIONS_AS_LINKS, true); Path path = tempDirectory.resolve(tempDirectory.toFile().list()[0]); Path expectedPath = createAndFailIfMissing(path, EXPECTED_GYRO_FILE, GYRO_NAME); assertTrue(com.google.common.io.Files.equal(expectedPath.toFile(), path.toFile())); Files.delete(path); } }
private static void assertCache(int seed, FileCache cache, File f) throws IOException { File cached = cache.get(ID_PREFIX + seed); assertNotNull(cached); assertTrue(Files.equal(f, cached)); }
private static void assertCacheIfPresent(int seed, FileCache cache, File f) throws IOException { File cached = cache.getIfPresent(ID_PREFIX + seed); assertNotNull(cached); assertTrue(Files.equal(f, cached)); }
private void assertFilesNoMove(String moveFolder, String... ids) throws Exception { for (String id : ids) { File file = getFile(id, path); assertTrue(file.exists()); assertTrue(Files.equal(file, copyToFile(randomStream(Integer.parseInt(id), 4 * 1024), folder.newFile()))); file = getFile(id, new File(path, moveFolder)); assertFalse(file.exists()); } }
private void assertFiles(String moveFolder, String... ids) throws Exception { for (String id : ids) { File file = getFile(id, path); assertFalse(file.exists()); file = getFile(id, new File(path, moveFolder)); assertTrue(file.exists()); assertTrue(Files.equal(file, copyToFile(randomStream(Integer.parseInt(id), 4 * 1024), folder.newFile()))); } }
public void testMove() throws IOException { File i18nFile = getTestFile("i18n.txt"); File temp1 = createTempFile(); File temp2 = createTempFile(); Files.copy(i18nFile, temp1); moveHelper(true, temp1, temp2); assertTrue(Files.equal(temp2, i18nFile)); }
public void testMoveViaCopy() throws IOException { File i18nFile = getTestFile("i18n.txt"); File temp1 = createTempFile(); File temp2 = createTempFile(); Files.copy(i18nFile, temp1); moveHelper(true, new UnmovableFile(temp1, false, true), temp2); assertTrue(Files.equal(temp2, i18nFile)); }
private void assertUpgrade(File pendingUploadFile) throws IOException { assertNull(stagingCache.getIfPresent(ID_PREFIX + 1)); assertTrue(Files.equal(copyToFile(randomStream(1, 4 * 1024), folder.newFile()), uploader.read(ID_PREFIX + 1))); assertFalse(pendingUploadFile.exists()); }
/** * Test build on start. * @throws Exception */ @Test public void testBuild() throws Exception { // Add load List<ListenableFuture<Integer>> futures = put(folder); // Close before uploading finished closer.close(); // Start again init(1); taskLatch.countDown(); callbackLatch.countDown(); afterExecuteLatch.await(); waitFinish(futures); assertNull(stagingCache.getIfPresent(ID_PREFIX + 0)); assertTrue(Files.equal(copyToFile(randomStream(0, 4 * 1024), folder.newFile()), uploader.read(ID_PREFIX + 0))); assertCacheStats(stagingCache, 0, 0, 1, 1); }