本文整理了Java中org.apache.commons.io.FileUtils.contentEquals()
方法的一些代码示例,展示了FileUtils.contentEquals()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.contentEquals()
方法的具体详情如下:
包路径:org.apache.commons.io.FileUtils
类名称:FileUtils
方法名:contentEquals
[英]Compares the contents of two files to determine if they are equal or not.
This method checks to see if the two files are different lengths or if they point to the same file, before resorting to byte-by-byte comparison of the contents.
Code origin: Avalon
[中]比较两个文件的内容以确定它们是否相等。
在对内容进行逐字节比较之前,此方法检查两个文件的长度是否不同,或者它们是否指向同一个文件。
代码来源:阿瓦隆
代码示例来源:origin: apache/zeppelin
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);
}
}
代码示例来源:origin: commons-io/commons-io
assertTrue(FileUtils.contentEquals(cr, cr));
assertTrue(FileUtils.contentEquals(crlf, crlf));
assertTrue(FileUtils.contentEquals(lf, lf));
assertFalse(FileUtils.contentEquals(cr, crlf));
assertFalse(FileUtils.contentEquals(cr, lf));
assertFalse(FileUtils.contentEquals(crlf, lf));
代码示例来源:origin: apache/zeppelin
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;
}
代码示例来源:origin: apache/hive
private static void compareResults(File file2) throws IOException {
// load the expected results
File baseResultFile = new File(System.getProperty("proxyAuth.res.file"), "data/files/ProxyAuth.res");
if (!FileUtils.contentEquals(baseResultFile, file2)) {
throw new IOException("File compare failed: " + file2.getPath() + " differs");
}
}
}
代码示例来源:origin: apache/drill
if (!outputFile.exists()) {
report.addNew();
} else if (!FileUtils.contentEquals(file, outputFile)) {
getLog().info(format("%s has changed", relPath));
if (!outputFile.delete()) {
代码示例来源:origin: azkaban/azkaban
@Test
public void testUploadFlowFile() throws Exception {
final File testYamlFile = ExecutionsTestUtil.getFlowFile(BASIC_FLOW_YAML_DIR, BASIC_FLOW_FILE);
this.loader.uploadFlowFile(PROJECT_ID, PROJECT_VERSION, testYamlFile, FLOW_VERSION);
final File tempDir = Files.createTempDir();
tempDir.deleteOnExit();
final File file = this.loader
.getUploadedFlowFile(PROJECT_ID, PROJECT_VERSION, BASIC_FLOW_FILE, FLOW_VERSION, tempDir);
assertThat(file.getName()).isEqualTo(BASIC_FLOW_FILE);
assertThat(FileUtils.contentEquals(testYamlFile, file)).isTrue();
}
代码示例来源:origin: azkaban/azkaban
private boolean areDirsEqualUtil(final File file1, final File file2, final boolean isRoot,
final boolean ignoreRoot)
throws IOException {
if (!file1.getName().equals(file2.getName())) {
if (!isRoot && ignoreRoot) {
return false;
}
}
if (file1.isDirectory() && file2.isDirectory()) {
if (file1.listFiles().length != file2.listFiles().length) {
return false;
}
final File[] fileList1 = file1.listFiles();
final File[] fileList2 = file2.listFiles();
Arrays.sort(fileList1, NameFileComparator.NAME_COMPARATOR);
Arrays.sort(fileList2, NameFileComparator.NAME_COMPARATOR);
for (int i = 0; i < fileList1.length; i++) {
if (!areDirsEqualUtil(fileList1[i], fileList2[i], false, ignoreRoot)) {
return false;
}
}
return true;
} else if (file1.isFile() && file2.isFile()) {
return file1.getName().equals(file2.getName()) && FileUtils.contentEquals(file1, file2);
} else {
return false;
}
}
代码示例来源:origin: commons-io/commons-io
final File file2 = new File(getTestDirectory(), getName() + "2");
assertTrue(FileUtils.contentEquals(file, file));
assertTrue(FileUtils.contentEquals(file, file2));
assertTrue(FileUtils.contentEquals(file2, file2));
assertTrue(FileUtils.contentEquals(file2, file));
FileUtils.contentEquals(getTestDirectory(), getTestDirectory());
fail("Comparing directories should fail with an IOException");
} catch (final IOException ioe) {
objFile2);
assertFalse(FileUtils.contentEquals(objFile1, objFile2));
assertFalse(FileUtils.contentEquals(objFile1b, objFile2));
assertTrue(FileUtils.contentEquals(objFile1, objFile1b));
assertTrue(FileUtils.contentEquals(objFile1, objFile1));
assertTrue(FileUtils.contentEquals(objFile1b, objFile1b));
assertTrue(FileUtils.contentEquals(objFile2, objFile2));
assertTrue(FileUtils.contentEquals(file, file));
assertTrue(FileUtils.contentEquals(file, file2));
代码示例来源:origin: azkaban/azkaban
);
assertTrue(expectedTargetFile.exists());
assertTrue(FileUtils.contentEquals(testFile, expectedTargetFile));
final File getFile = new File("tmp.get");
FileUtils.copyInputStreamToFile(getIs, getFile);
assertTrue(FileUtils.contentEquals(testFile, getFile));
代码示例来源:origin: testcontainers/testcontainers-java
@Test
public void copyFolderToContainerFolderTest() throws Exception {
try (
GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2")
.withCommand("top")
) {
alpineCopyToContainer.start();
final MountableFile mountableFile = MountableFile.forClasspathResource("mappable-resource/");
alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/test/");
File actualFile = new File(temporaryFolder.getRoot().getAbsolutePath() + "/test_copy_to_container.txt");
alpineCopyToContainer.copyFileFromContainer("/home/test/test-resource.txt", actualFile.getPath());
File expectedFile = new File(mountableFile.getResolvedPath() + "/test-resource.txt");
assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile));
}
}
代码示例来源:origin: testcontainers/testcontainers-java
@Test
public void copyFileToContainerFileTest() throws Exception {
try (
GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2")
.withCommand("top")
) {
alpineCopyToContainer.start();
final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt");
alpineCopyToContainer.copyFileToContainer(mountableFile, "/test.txt");
File actualFile = new File(temporaryFolder.getRoot().getAbsolutePath() + "/test_copy_to_container.txt");
alpineCopyToContainer.copyFileFromContainer("/test.txt", actualFile.getPath());
File expectedFile = new File(mountableFile.getResolvedPath());
assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile));
}
}
代码示例来源:origin: testcontainers/testcontainers-java
@Test
public void copyFileToContainerFolderTest() throws Exception {
try (
GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2")
.withCommand("top")
) {
alpineCopyToContainer.start();
final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt");
alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/");
File actualFile = new File(temporaryFolder.getRoot().getAbsolutePath() + "/test_copy_to_container.txt");
alpineCopyToContainer.copyFileFromContainer("/home/test_copy_to_container.txt", actualFile.getPath());
File expectedFile = new File(mountableFile.getResolvedPath());
assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile));
}
}
代码示例来源:origin: testcontainers/testcontainers-java
@Test
public void shouldCopyFileFromContainerTest() throws IOException {
try (
GenericContainer alpineCopyToContainer = new GenericContainer("alpine:3.2")
.withCommand("top")
) {
alpineCopyToContainer.start();
final MountableFile mountableFile = MountableFile.forClasspathResource("test_copy_to_container.txt");
alpineCopyToContainer.copyFileToContainer(mountableFile, "/home/");
File actualFile = new File(temporaryFolder.getRoot().getAbsolutePath() + "/test_copy_from_container.txt");
alpineCopyToContainer.copyFileFromContainer("/home/test_copy_to_container.txt", actualFile.getPath());
File expectedFile = new File(mountableFile.getResolvedPath());
assertTrue("Files aren't same ", FileUtils.contentEquals(expectedFile, actualFile));
}
}
}
代码示例来源:origin: apache/incubator-pinot
Assert.assertTrue(FileUtils.contentEquals(ON_HEAP_INVERTED_INDEX, OFF_HEAP_INVERTED_INDEX));
代码示例来源:origin: apache/incubator-pinot
Assert.assertTrue(FileUtils.contentEquals(ON_HEAP_INVERTED_INDEX, OFF_HEAP_INVERTED_INDEX));
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void testHTTPResultDefaultRows() throws IOException {
File localFileForUpload = getInputFile( "existingFile1", ".tmp" );
File tempFileForDownload = File.createTempFile( "downloadedFile1", ".tmp" );
localFileForUpload.deleteOnExit();
tempFileForDownload.deleteOnExit();
Object[] r = new Object[] { HTTP_SERVER_BASEURL + "/uploadFile",
localFileForUpload.getCanonicalPath(), tempFileForDownload.getCanonicalPath() };
RowMeta rowMetaDefault = new RowMeta();
rowMetaDefault.addValueMeta( new ValueMetaString( "URL" ) );
rowMetaDefault.addValueMeta( new ValueMetaString( "UPLOAD" ) );
rowMetaDefault.addValueMeta( new ValueMetaString( "DESTINATION" ) );
List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();
rows.add( new RowMetaAndData( rowMetaDefault, r ) );
Result previousResult = new Result();
previousResult.setRows( rows );
JobEntryHTTP http = new JobEntryHTTP();
http.setParentJob( new Job() );
http.setRunForEveryRow( true );
http.setAddFilenameToResult( false );
http.execute( previousResult, 0 );
assertTrue( FileUtils.contentEquals( localFileForUpload, tempFileForDownload ) );
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void testHTTPResultCustomRows() throws IOException {
File localFileForUpload = getInputFile( "existingFile2", ".tmp" );
File tempFileForDownload = File.createTempFile( "downloadedFile2", ".tmp" );
localFileForUpload.deleteOnExit();
tempFileForDownload.deleteOnExit();
Object[] r = new Object[] { HTTP_SERVER_BASEURL + "/uploadFile",
localFileForUpload.getCanonicalPath(), tempFileForDownload.getCanonicalPath() };
RowMeta rowMetaDefault = new RowMeta();
rowMetaDefault.addValueMeta( new ValueMetaString( "MyURL" ) );
rowMetaDefault.addValueMeta( new ValueMetaString( "MyUpload" ) );
rowMetaDefault.addValueMeta( new ValueMetaString( "MyDestination" ) );
List<RowMetaAndData> rows = new ArrayList<RowMetaAndData>();
rows.add( new RowMetaAndData( rowMetaDefault, r ) );
Result previousResult = new Result();
previousResult.setRows( rows );
JobEntryHTTP http = new JobEntryHTTP();
http.setParentJob( new Job() );
http.setRunForEveryRow( true );
http.setAddFilenameToResult( false );
http.setUrlFieldname( "MyURL" );
http.setUploadFieldname( "MyUpload" );
http.setDestinationFieldname( "MyDestination" );
http.execute( previousResult, 0 );
assertTrue( FileUtils.contentEquals( localFileForUpload, tempFileForDownload ) );
}
代码示例来源:origin: openmrs/openmrs-core
assertFalse(FileUtils.contentEquals(previousFile, currentFile));
代码示例来源:origin: zalando/intellij-swagger
@Test
public void itCanSetPlaceholderValueInANewFile() throws Exception {
File targetFile = copyResourceTo("with_placeholder.html", "index.html");
File expectedOutputFile = copyResourceTo("with_placeholder_replaced.html", "expected.html");
fileContentManipulator.setJsonToIndexFile("{}", targetFile);
assertTrue("The files differ!", FileUtils.contentEquals(targetFile, expectedOutputFile));
}
代码示例来源:origin: com.paypal.butterfly/butterfly-utilities
@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);
}
}
内容来源于网络,如有侵权,请联系作者删除!