List of usage examples for java.io File equals
public boolean equals(Object obj)
From source file:org.geoserver.bkprst.RestoreTransaction.java
/** * Successfuly complete the restore// w ww . j a va2 s .c om */ public synchronized void commit() { // Deletes selected top-level files who had their name changed try { 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) { } } } } catch (Exception e) { LOGGER.severe(e.getMessage()); task.setState(BrTaskState.FAILED); task.setEndTime(new Date()); LOGGER.info("Restore " + task.getId() + " rolled back"); task.unlock(); return; } task.setState(BrTaskState.COMPLETED); task.setEndTime(new Date()); LOGGER.info("Restore " + task.getId() + " completed"); task.unlock(); }
From source file:com.thoughtworks.go.domain.materials.DirectoryCleaner.java
private void allow(File allowedDir, List<File> allowedDirs) { allowed.add(allowedDir);//from w w w . jav a 2 s .c o m File parentDir = allowedDir.getParentFile(); if (!parentDir.equals(baseFolder) && !allowed.contains(parentDir)) { if (!isContainedInOtherAllowedDirs(parentDir, allowedDirs)) { check(parentDir); } allow(parentDir, allowedDirs); } }
From source file:ga.rugal.jpt.common.tracker.common.Torrent.java
/** * Helper method to create a {@link Torrent} object for a set of files. * * <p>/* w w w. j a v a 2 s. c o m*/ * Hash the given files to create the multi-file {@link Torrent} object representing the Torrent * meta-info about them, needed for announcing and/or sharing these files. Since we created the * torrent, we're considering we'll be a full initial seeder for it. * </p> * * @param parent The parent directory or location of the torrent files, also used as the * torrent's name. * @param files The files to add into this torrent. * @param announce The announce URI that will be used for this torrent. * @param announceList The announce URIs organized as tiers that will be used for this torrent * @param createdBy The creator's name, or any string identifying the torrent's creator. */ private static Torrent create(File parent, List<File> files, int pieceLength, URI announce, List<List<URI>> announceList, String createdBy) throws InterruptedException, IOException { if (files == null || files.isEmpty()) { LOG.info("Creating single-file torrent for {}...", parent.getName()); } else { LOG.info("Creating {}-file torrent {}...", files.size(), parent.getName()); } Map<String, BEValue> torrent = new HashMap<>(); if (announce != null) { torrent.put("announce", new BEValue(announce.toString())); } if (announceList != null) { List<BEValue> tiers = new LinkedList<>(); for (List<URI> trackers : announceList) { List<BEValue> tierInfo = new LinkedList<>(); for (URI trackerURI : trackers) { tierInfo.add(new BEValue(trackerURI.toString())); } tiers.add(new BEValue(tierInfo)); } torrent.put("announce-list", new BEValue(tiers)); } torrent.put("creation date", new BEValue(new Date().getTime() / 1000)); torrent.put("created by", new BEValue(createdBy)); Map<String, BEValue> info = new TreeMap<>(); info.put("name", new BEValue(parent.getName())); info.put("piece length", new BEValue(pieceLength)); if (files == null || files.isEmpty()) { info.put("length", new BEValue(parent.length())); info.put("pieces", new BEValue(Torrent.hashFile(parent, pieceLength), SystemDefaultProperties.BYTE_ENCODING)); } else { List<BEValue> fileInfo = new LinkedList<>(); for (File file : files) { Map<String, BEValue> fileMap = new HashMap<>(); fileMap.put("length", new BEValue(file.length())); LinkedList<BEValue> filePath = new LinkedList<>(); while (file != null) { if (file.equals(parent)) { break; } filePath.addFirst(new BEValue(file.getName())); file = file.getParentFile(); } fileMap.put("path", new BEValue(filePath)); fileInfo.add(new BEValue(fileMap)); } info.put("files", new BEValue(fileInfo)); info.put("pieces", new BEValue(Torrent.hashFiles(files, pieceLength), SystemDefaultProperties.BYTE_ENCODING)); } torrent.put("info", new BEValue(info)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BEncoder.bencode(new BEValue(torrent), baos); return new Torrent(baos.toByteArray(), true); }
From source file:com.github.javarch.support.data.LocalFileStorage.java
public String storeFile(FileData fileData) { File file = new File(storageDirectory, fileData.getName()); if (file.exists()) { file.delete();/*from ww w . j a va 2 s . co m*/ } File parent = file.getParentFile(); if (parent != null && !parent.equals(storageDirectory)) { parent.mkdirs(); } LinkedList<File> parents = new LinkedList<File>(); while (parent != null && !parent.equals(storageDirectory)) { parents.addFirst(parent); parent = parent.getParentFile(); } if (deleteOnExit) { for (File p : parents) { p.deleteOnExit(); } file.deleteOnExit(); } try { file.createNewFile(); FileOutputStream os = new FileOutputStream(file); os.write(fileData.getBytes()); } catch (FileNotFoundException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } return file.toURI().toString(); }
From source file:de.jcup.egradle.sdk.builder.action.type.SaveTypesToSDKTargetFolder.java
String extractSubPathFromFile(File file, File parent) throws IOException { StringBuilder sb = new StringBuilder(); File current = file; boolean parentFound = false; while (current != null) { if (current.equals(parent)) { parentFound = true;//from ww w.jav a 2s . com break; } sb.insert(0, current.getName()); sb.insert(0, '/'); current = current.getParentFile(); } if (!parentFound) { throw new IllegalArgumentException("Parent:" + parent + "\ndoes not contain\nFile:" + file); } String result = sb.toString(); if (result.startsWith("/")) { result = StringUtils.substring(result, 1); } return result; }
From source file:com.github.ukase.toolkit.fs.FileSource.java
private boolean isSubDirectory(File dir, File kind) { while (kind != null) { if (kind.equals(dir)) { return true; }// w w w . jav a 2 s. c om kind = kind.getParentFile(); } return false; }
From source file:org.opendatakit.common.android.utilities.ODKFileUtils.java
public static boolean isPathUnderAppName(String appName, File path) { File parentDir = new File(ODKFileUtils.getAppFolder(appName)); while (path != null && !path.equals(parentDir)) { path = path.getParentFile();/*from www .j a v a2 s .c o m*/ } return (path != null); }
From source file:de.jcup.egradle.eclipse.ide.IDEUtil.java
/** * Returns true when given project is configured as root project * //from w w w. j a v a 2 s.co m * @param project * @return <code>true</code> when project location is same as root project */ public static boolean isRootProject(IProject project) { if (project == null) { return false; } File rootFolder = getRootProjectFolderWithoutErrorHandling(); if (rootFolder == null) { return false; } try { File projectLocation = getResourceHelper().toFile(project.getLocation()); return rootFolder.equals(projectLocation); } catch (CoreException e) { /* ignore ... project not found anymore */ return false; } }
From source file:org.jajuk.util.UpgradeManager.java
/** * For Jajuk < 1.9: bootstrap file is now in XML format * <br>/* www .ja v a 2 s. c om*/ * If it exists and contains data in 1.7 or 1.8 format, it convert it to new XML * format (to handle backslashes properly, old format just drop them) * <br> * This method doesn't yet validate provided workspace paths but only the bootstrap file * structure itself. */ public static void upgradeBootstrapFile() { try { String KEY_TEST = "test"; String KEY_FINAL = "final"; File bootstrapOld = new File(SessionService.getBootstrapPath(Const.FILE_BOOTSTRAP_OLD)); File bootstrapOldOldHome = new File(System.getProperty("user.home") + "/" + Const.FILE_BOOTSTRAP_OLD); File bootstrapNew = new File(SessionService.getBootstrapPath()); // Fix for #1473 : move the bootstrap file if required (See #1473) if (UtilSystem.isUnderWindows() && !bootstrapOld.equals(bootstrapOldOldHome) && !bootstrapOld.exists() && bootstrapOldOldHome.exists()) { try { FileUtils.copyFileToDirectory(bootstrapOldOldHome, new File(UtilSystem.getUserHome())); UtilSystem.deleteFile(bootstrapOldOldHome); } catch (IOException ex) { ex.printStackTrace(); } } if (bootstrapOld.exists() && !bootstrapNew.exists()) { Properties prop = null; // Try to load a bootstrap file using plain text old format prop = new Properties(); FileInputStream fis = new FileInputStream( SessionService.getBootstrapPath(Const.FILE_BOOTSTRAP_OLD)); prop.load(fis); fis.close(); // If it exists and contains pre-1.7 bootstrap format (a single line with a raw path), // convert it to 1.7 format first if (prop.size() == 1) { // We get something like <... path ...> = <nothing> String path = (String) prop.keys().nextElement(); // we use this path for both test and final workspace prop.clear(); prop.put(KEY_TEST, path); prop.put(KEY_FINAL, path); } // Make sure to populate both test and final release if (!prop.containsKey(KEY_TEST)) { prop.put(KEY_TEST, UtilSystem.getUserHome()); } if (!prop.containsKey(KEY_FINAL)) { prop.put(KEY_FINAL, UtilSystem.getUserHome()); } // Write down the new bootstrap file SessionService.commitBootstrapFile(prop); // Delete old bootstrap file bootstrapOld.delete(); } } catch (Exception e) { // Do not throw any exception from here. display raw stack trace, Logs facilities // are not yet available. e.printStackTrace(); } }
From source file:com.genericworkflownodes.knime.base.data.port.FileStorePrefixURIPortObject.java
/** * Triggers the re-indexing of the current content of the port, by * collecting all files that share the given prefix. This method should be * called after all content was generated inside the file store. *///w ww . j av a2s . co m public void collectFiles() { // we have generated a list of files based on a prefix final File f = new File(getPrefix()); Iterator<File> fIt = FileUtils.iterateFiles(f.getParentFile(), TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); while (fIt.hasNext()) { File tf = fIt.next(); if (!tf.isDirectory()) { final String abs_path = tf.getAbsolutePath(); if (abs_path.startsWith(getPrefix())) { // get relative path to filestore as string File relPath = new File(tf.getName()); File parent = tf.getParentFile(); while (!parent.equals(getFileStoreRootDirectory())) { relPath = new File(parent.getName(), relPath.toString()); parent = parent.getParentFile(); } // register the found file at the underlying // FileStoreURIPortObject registerFile(relPath.toString()); } } } }