List of usage examples for java.io File equals
public boolean equals(Object obj)
From source file:org.openspaces.pu.container.servicegrid.deploy.HTTPFileSystemView.java
public boolean isRoot(File f) { return f.equals(getRoots()[0]); }
From source file:org.opendatakit.common.android.utilities.ODKFileUtils.java
/** * Returns the relative path beginning after the getAppFolder(appName) directory. * The relative path does not start or end with a '/' * * @param appName/*from www .jav a 2s . c o m*/ * @param fileUnderAppName * @return */ public static String asRelativePath(String appName, File fileUnderAppName) { // convert fileUnderAppName to a relative path such that if // we just append it to the AppFolder, we have a full path. File parentDir = new File(ODKFileUtils.getAppFolder(appName)); ArrayList<String> pathElements = new ArrayList<String>(); File f = fileUnderAppName; while (f != null && !f.equals(parentDir)) { pathElements.add(f.getName()); f = f.getParentFile(); } if (f == null) { throw new IllegalArgumentException("file is not located under this appName (" + appName + ")!"); } StringBuilder b = new StringBuilder(); for (int i = pathElements.size() - 1; i >= 0; --i) { String element = pathElements.get(i); b.append(element); if (i != 0) { b.append(File.separator); } } return b.toString(); }
From source file:org.jetbrains.teamcity.widgets.WidgetContentController.java
@Override protected boolean isLegalPath(@NotNull File maybeChild, @NotNull File possibleParent) throws IOException { final File parent = possibleParent.getCanonicalFile(); File child = maybeChild.getCanonicalFile(); while (child != null) { if (child.equals(parent)) { return true; }//from ww w. j a v a2 s . c om child = child.getParentFile(); } return false; }
From source file:org.gradle.caching.internal.tasks.FileWalkingBenchmark.java
@Benchmark public void java6walk(Blackhole blackhole) { File file = missing ? missingFile : existingFile; while (!file.equals(tempDirFile)) { file = file.getParentFile();/* ww w.j a v a 2 s. c o m*/ blackhole.consume(file.exists()); } blackhole.consume(file); }
From source file:org.geoserver.bkprst.RestoreTransaction.java
/** * Starts the restore//from w ww . ja va 2s. com */ public synchronized void start() throws Exception { task.setStartTime(new Date()); task.setState(BrTaskState.STARTING); task.lock(); LOGGER.info("Started restore " + task.id + " to " + task.path + " from " + srcMount.getAbsolutePath() + " to" + this.trgMount.getAbsolutePath()); // Puts in topFiles the top-level files of the target directoy using the filter Collector topColl = new Collector(this.filter, 1); this.topFiles = topColl.collect(this.trgMount); // Renames selected top-level files (deletes files with the sane name // if already present) for (File file : this.topFiles) { if (!file.equals(this.trgMount)) { File renamedFile = new File(file.getAbsolutePath() + BrTask.BACKUPEXT); try { FileUtils.forceDelete(renamedFile); } catch (FileNotFoundException e) { } file.renameTo(renamedFile); } } }
From source file:org.duracloud.sync.walker.RestartDirWalkerTest.java
@Test public void testRestartDirWalker() throws Exception { List<File> dirs = new ArrayList<File>(); dirs.add(tempDir);/* w ww.java 2s . c o m*/ // Create three sub directories with files File subDir1 = new File(tempDir, "subdir1"); subDir1.mkdir(); File sub1file1 = File.createTempFile("subdir1", "file1", subDir1); File sub1file2 = File.createTempFile("subdir1", "file2", subDir1); File subDir2 = new File(tempDir, "subdir2"); subDir2.mkdir(); File sub2file1 = File.createTempFile("subdir2", "file1", subDir2); File subDir3 = new File(tempDir, "subdir3"); subDir3.mkdir(); File sub3file1 = File.createTempFile("subdir3", "file1", subDir3); long restartTime = System.currentTimeMillis(); Thread.sleep(1000); // Add a file to subdir 2 File sub2file2 = File.createTempFile("subdir2", "file2", subDir2); // Update file in subdir 1 FileUtils.touch(sub1file1); // Run the restart walker RestartDirWalker rDirWalker = new RestartDirWalker(dirs, restartTime, new FileExclusionManager()); assertFalse(rDirWalker.walkComplete()); rDirWalker.walkDirs(); assertTrue(rDirWalker.walkComplete()); // Changed list should include sub1file1, and all files from sub2 List<File> changedFiles = new ArrayList<File>(); ChangedFile changedFile = changedList.reserve(); while (changedFile != null) { changedFiles.add(changedFile.getFile()); changedFile = changedList.reserve(); } assertEquals(3, changedFiles.size()); for (File file : changedFiles) { assertTrue(file.equals(sub1file1) || file.equals(sub2file1) || file.equals(sub2file2)); } assertNull(changedList.reserve()); }
From source file:com.github.fritaly.dualcommander.FileComparator.java
@Override public int compare(File f1, File f2) { // Directories come first if (f1.isDirectory()) { if (f1.equals(this.delegate.getParentDirectory())) { // The parent directory always comes first return -1; }//from w ww . java2 s .c o m if (f2.isDirectory()) { if (f2.equals(this.delegate.getParentDirectory())) { // The parent directory always comes first return +1; } // Compare the 2 directories by (case-insensive) name return f1.getName().compareToIgnoreCase(f2.getName()); } else { // The directories come first return -1; } } else { if (f2.isDirectory()) { // The directories come first return +1; } else { // Compare the 2 files by (case-insensive) name return f1.getName().compareToIgnoreCase(f2.getName()); } } }
From source file:org.kalypso.ui.rrm.internal.conversion.to12_02.CalcCaseConvertWalker.java
@Override protected boolean handleDirectory(final File directory, final int depth, final Collection<File> results) { if (directory.equals(m_templateDir)) return false; /* Happened in Krckau Model: .calculation inside .models folder */ if (directory.equals(new File(m_sourceDir, INaProjectConstants.FOLDER_MODEL))) return false; /* Just ignore non calculation dirs. Needs to return true, as we may come from further up. */ if (!isCalculationDirectory(directory)) return true; results.add(directory);/*from w w w .ja v a2s .co m*/ return false; }
From source file:com.github.fritaly.dualcommander.ConfigurableFileComparator.java
@Override public int compare(File f1, File f2) { // The parent directory always comes first if (f1.isDirectory() && f1.equals(this.delegate.getParentDirectory())) { return -1; }/*from w w w.ja va 2 s . c om*/ if (f2.isDirectory() && f2.equals(this.delegate.getParentDirectory())) { return +1; } // Compare the 2 files according to the current sort criteria final int result = criteria.compare(f1, f2); return ascending ? result : -1 * result; }
From source file:org.geoserver.bkprst.RestoreTransaction.java
/** * Aborts the restore//from ww w .j av a 2s . co m */ public synchronized void rollback() { // Renames selected top-level files back the original name (deletes files with the sane name // if present) try { for (File file : this.topFiles) { if (!file.equals(this.trgMount)) { File renamedFile = new File(file.getAbsolutePath() + BrTask.BACKUPEXT); try { FileUtils.forceDelete(file); } catch (FileNotFoundException e) { } renamedFile.renameTo(file); } } File xmlFile = new File(this.trgMount.getAbsolutePath() + File.separatorChar + BrTask.INFOFILE); xmlFile.delete(); } catch (Exception e) { LOGGER.severe(e.getMessage()); } finally { task.setState(BrTaskState.FAILED); task.setEndTime(new Date()); LOGGER.severe("Restore " + task.getId() + " failed"); task.unlock(); } }