List of usage examples for java.io File equals
public boolean equals(Object obj)
From source file:org.apache.oodt.cas.filemgr.versioning.VersioningUtils.java
public static List<Reference> getReferencesFromDir(File dirRoot) { List<Reference> references; if (dirRoot == null) { throw new IllegalArgumentException("null"); }/*from w ww.j a v a 2 s .c om*/ if (!dirRoot.isDirectory()) { dirRoot = dirRoot.getParentFile(); } references = new Vector<Reference>(); Stack<File> stack = new Stack<File>(); stack.push(dirRoot); while (!stack.isEmpty()) { File dir = stack.pop(); // add the reference for the dir // except if it's the rootDir, then, skip it if (!dir.equals(dirRoot)) { try { Reference r = new Reference(); r.setOrigReference(dir.toURL().toExternalForm()); r.setFileSize(dir.length()); references.add(r); } catch (MalformedURLException e) { LOG.log(Level.SEVERE, e.getMessage()); LOG.log(Level.WARNING, "MalformedURLException when generating reference for dir: " + dir); } } File[] files = dir.listFiles(FILE_FILTER); if (files != null) { for (File file : files) { // add the file references try { Reference r = new Reference(); r.setOrigReference(file.toURL().toExternalForm()); r.setFileSize(file.length()); references.add(r); } catch (MalformedURLException e) { LOG.log(Level.SEVERE, e.getMessage()); LOG.log(Level.WARNING, "MalformedURLException when generating reference for file: " + file); } } File[] subdirs = dir.listFiles(DIR_FILTER); if (subdirs != null) { for (File subdir : subdirs) { stack.push(subdir); } } } } return references; }
From source file:com.diffplug.gradle.FileMisc.java
/** Deletes all empty folders (recursively). */ public static void deleteEmptyFolders(File d) throws IOException { retry(d, root -> {/*from w ww. ja v a 2s . co m*/ // define the directory hierarchy TreeDef<File> dirTree = file -> Arrays.stream(file.listFiles()).filter(File::isDirectory) .collect(Collectors.toList()); // find all the empty directories List<File> emptyDirs = TreeStream.depthFirst(dirTree, root).filter(dir -> dir.list().length == 0) .collect(Collectors.toList()); for (File emptyDir : emptyDirs) { File toDelete = emptyDir; while (!toDelete.equals(root)) { Preconditions.checkArgument(toDelete.delete(), "Failed to delete %s", toDelete); toDelete = toDelete.getParentFile(); if (toDelete.list().length > 0) { break; } } } return null; }); }
From source file:com.theelix.libreexplorer.FileManager.java
/** * Deletes the given file/*from w w w.j a va2 s . c o m*/ * * @param selectedFiles The Selected Files * @throws IOException */ public static void delete(Object[] selectedFiles) throws IOException { for (Object selectedFile : selectedFiles) { File file = (File) selectedFile; if (file.isDirectory()) { FileUtils.deleteDirectory(file); } else { file.delete(); if (file.equals(targetFile)) { targetFile = null; setPasteVisible(false); } } } }
From source file:net.sf.jabref.logic.util.io.FileUtil.java
/** * Converts an absolute filename to a relative one, if necessary. * Returns the parameter fileName itself if no shortening is possible * <p>//from w w w . j av a 2 s . c o m * This method works correctly only if dirs are sorted decent in their length * i.e. /home/user/literature/important before /home/user/literature * * @param fileName the filename to be shortened * @param dirs directories to check. */ public static File shortenFileName(File fileName, List<String> dirs) { if ((fileName == null) || !fileName.isAbsolute() || (dirs == null)) { return fileName; } for (String dir : dirs) { if (dir != null) { File result = shortenFileName(fileName, dir); if ((result != null) && !result.equals(fileName)) { return result; } } } return fileName; }
From source file:de.jcup.egradle.eclipse.ide.virtualroot.EclipseVirtualProjectPartCreator.java
/** * Check if given file should be linked inside project * /*from ww w.j av a 2s. c o m*/ * @param virtualRootProject * @param newProjectFile * @param foldersToIgnore * a list of folders to ignore for inspection * @param targetFolder * where to create the link * @param file * - origin file/folder * @return <code>true</code> when a link candidate */ protected static boolean isLinkCandidate(IProject virtualRootProject, File newProjectFile, List<File> foldersToIgnore, Object targetFolder, File file) { if (newProjectFile.equals(file)) { /* root project cannot link to itself - infinite loop... */ return false; } if (file.getParentFile().equals(newProjectFile)) { /* we also do not link content of virtual root project */ return false; } String fileName = file.getName(); boolean fileIsDirectory = file.isDirectory(); boolean fileExists = file.exists(); if (!fileExists) { return false; } if (fileIsDirectory) { if (FOLDERNAMES_NOT_TO_LINK.contains(fileName)) { return false; } if (targetFolder == virtualRootProject) { // inside root if (foldersToIgnore.contains(file)) { /* ignored - normally because eclipse project inside */ return false; } /* okay, directory link has to be created */ return true; } /* * we do not dive into folders deeper than root folder - because * links to folders does all the job */ return false; } else { /* not a directory but a normal file */ if (FILENAMES_NOT_TO_LINK.contains(fileName)) { return false; } return true; } }
From source file:net.dv8tion.jda.core.utils.SimpleLog.java
/** * Removes all File-logs created via {@link #addFileLog(net.dv8tion.jda.core.utils.SimpleLog.Level, java.io.File)} with given File. * To remove the sout and serr logs, call {@link #addFileLogs(java.io.File, java.io.File)} with null args. * * @param file// ww w . j av a 2 s. c o m * The file to remove from all FileLogs (except sout and serr logs) * @throws java.io.IOException * If the File can't be canonically resolved (access denied) */ public static void removeFileLog(File file) throws IOException { File canonicalFile = file.getCanonicalFile(); Iterator<Map.Entry<Level, Set<File>>> setIter = fileLogs.entrySet().iterator(); while (setIter.hasNext()) { Map.Entry<Level, Set<File>> set = setIter.next(); Iterator<File> fileIter = set.getValue().iterator(); while (fileIter.hasNext()) { File logFile = fileIter.next(); if (logFile.equals(canonicalFile)) { fileIter.remove(); break; } } if (set.getValue().isEmpty()) { setIter.remove(); } } }
From source file:org.broad.igv.DirectoryManager.java
/** * Move the "igv" directory to a new location, copying all contents. Returns True if the directory * is successfully moved, irrespective of any errors that might occur later (e.g. when attempting to * remove the old directory).//from www . ja v a 2s. c o m * * @param newIGVDirectory * @return True if the directory is successfully moved, false otherwise */ public static Boolean moveIGVDirectory(final File newIGVDirectory) { if (newIGVDirectory.equals(IGV_DIRECTORY)) { return false; // Nothing to do } if (IGV_DIRECTORY != null && IGV_DIRECTORY.exists()) { File oldDirectory = IGV_DIRECTORY; try { log.info("Moving igv directory from " + oldDirectory.getParent() + " to " + newIGVDirectory.getAbsolutePath()); FileUtils.copyDirectory(IGV_DIRECTORY, newIGVDirectory); IGV_DIRECTORY = newIGVDirectory; // Store location of new directory in Java preferences node (not pref.properties) Preferences prefs = Preferences.userNodeForPackage(Globals.class); prefs.put(IGV_DIR_USERPREF, newIGVDirectory.getAbsolutePath()); // Update preference manager with new file location PreferenceManager.getInstance().setPrefsFile(getPreferencesFile().getAbsolutePath()); } catch (IOException e) { log.error("Error copying IGV directory", e); MessageUtils.showMessage("<html>Error moving IGV directory:<br/> nbsp;" + e.getMessage()); return false; } // Restart the log LogManager.shutdown(); initializeLog(); // Try to delete the old directory try { deleteDirectory(oldDirectory); } catch (IOException e) { log.error("An error was encountered deleting the previous IGV directory", e); MessageUtils.showMessage("<html>An error was encountered deleting the previous IGV directory (" + e.getMessage() + "):<br> nbsp;nbsp;" + oldDirectory.getAbsolutePath() + "<br>Remaining files should be manually deleted."); } } GENOME_CACHE_DIRECTORY = null; GENE_LIST_DIRECTORY = null; BAM_CACHE_DIRECTORY = null; return true; }
From source file:nl.knaw.dans.common.lang.util.FileUtil.java
/** * Copy the file <code>original</code> to the file <code>destination</code>. * /*from w ww . j a v a 2s . c o m*/ * @param original * the original file * @param destination * the destination file * @throws IOException * for exceptions during IO */ public static void copyFile(File original, File destination) throws IOException { if (!original.exists()) { throw new FileNotFoundException("File not found: " + original.getName()); } if (original.isHidden()) { return; } if (original.equals(destination)) { throw new IOException("Cannot copy " + original.getName() + " into itself."); } if (original.isDirectory() && destination.isFile()) { throw new IOException("Cannot copy the contents of '" + original.getName() + "' to the file " + destination.getName()); } File finalDestination; if (destination.isDirectory()) { finalDestination = new File(destination, original.getName()); } else { finalDestination = destination; } if (original.isDirectory()) { finalDestination.mkdirs(); for (File f : original.listFiles()) { copyFile(f, finalDestination); } } else { FileInputStream fis = null; FileOutputStream fos = null; try { fis = new FileInputStream(original); fos = new FileOutputStream(finalDestination); byte[] buffer = new byte[4096]; int read = fis.read(buffer); while (read != -1) { fos.write(buffer, 0, read); read = fis.read(buffer); } } finally { closeStreams(fis, fos); } } }
From source file:org.renjin.appengine.AppEngineContextFactory.java
@VisibleForTesting static String findHomeDirectory(File servletContextRoot, String sexpClassPath) throws IOException { LOG.fine("Found SEXP in '" + sexpClassPath); File jarFile = jarFileFromResource(sexpClassPath); StringBuilder homePath = new StringBuilder(); homePath.append('/').append(jarFile.getName()).append("!/org/renjin"); File parent = jarFile.getParentFile(); while (!servletContextRoot.equals(parent)) { if (parent == null) { throw new IllegalStateException( "Expected the renjin-core jar to be in the WEB-INF, bound found it in:\n" + jarFile.toString() + "\nAre you sure you are running in a servlet environment?"); }/*from www . j a v a 2s . com*/ homePath.insert(0, parent.getName()); homePath.insert(0, '/'); parent = parent.getParentFile(); } homePath.insert(0, "jar:file://"); return homePath.toString(); }
From source file:com.xtructure.xnet.demos.art.TwoNodeSimulation.java
/** * Load config files./*from w ww . j a v a2s .c o m*/ * * @param dir * the dir * @param ignoreFiles * the ignore files */ private static void loadConfigFiles(File dir, File... ignoreFiles) { if (dir == null) { return; } PROCESS: for (File file : dir.listFiles()) { if (file.isDirectory()) { continue; } for (File iFile : ignoreFiles) { if (file.equals(iFile)) { continue PROCESS; } } System.out.println("Checking : " + file.getName()); try { try { XmlReader.read(file, XmlBinding.builder().add(NodeConfiguration.XML_BINDING) .add(LinkConfiguration.XML_BINDING).add(NetworkImpl.XML_BINDING).newInstance()); System.out.println("Loaded configuration."); continue; } catch (XMLStreamException e) { } System.out.println("Skipped. (Not a recognized node or link configuration.)"); } catch (IOException e) { e.printStackTrace(); } } }