/** * To be kept in sync with {@link FilePathVF#computeRelativePathToRoot()} */ private String computeRelativePathToRoot(){ if (this.root.equals(this.f)) { return ""; } Deque<String> relativePath = new LinkedList<>(); File current = this.f; while (current != null && !current.equals(this.root)) { relativePath.addFirst(current.getName()); current = current.getParentFile(); } return String.join(File.separator, relativePath) + File.separator; } }
private static boolean isInSubDirectoryInternal(File baseDir, File canonFile) { if (canonFile == null) { return false; } if (canonFile.equals(baseDir)) { return true; } return isInSubDirectoryInternal(baseDir, canonFile.getParentFile()); }
public static boolean isSymlink(File file) throws IOException { if (file == null) throw new NullPointerException("File must not be null"); File canon; if (file.getParent() == null) { canon = file; } else { File canonDir = file.getParentFile().getCanonicalFile(); canon = new File(canonDir, file.getName()); } return !canon.getCanonicalFile().equals(canon.getAbsoluteFile()); }
/** * Creates a new iterator representation for all files within a folder. * * @param folder The root folder. */ protected FolderIterator(File folder) { files = new LinkedList<File>(Collections.singleton(folder)); File candidate; do { candidate = files.removeFirst(); File[] file = candidate.listFiles(); if (file != null) { files.addAll(0, Arrays.asList(file)); } } while (!files.isEmpty() && (files.peek().isDirectory() || files.peek().equals(new File(folder, JarFile.MANIFEST_NAME)))); }
String name = element.getName(); if (!name.endsWith("/")) { File target = new File(folder, name), resolved = element.resolveAs(File.class); if (!target.getCanonicalPath().startsWith(folder.getCanonicalPath())) { throw new IllegalArgumentException(target + " is not a subdirectory of " + folder); } else if (!target.getParentFile().isDirectory() && !target.getParentFile().mkdirs()) { throw new IOException("Could not create directory: " + target.getParent()); } else if (DISPATCHER.isAlive() && resolved != null && !resolved.equals(target)) { DISPATCHER.copy(resolved, target); } else if (!target.equals(resolved)) { InputStream inputStream = element.getInputStream(); try {
@Override public void parse() { final File inputFile = files.get(0); File outputFile = null; if (files.size() == 2) { outputFile = files.get(1); } else { final String name = FilenameUtils.getBaseName(inputFile.getName()); final String extension = FilenameUtils.getExtension(inputFile.getName()); final String newName = name + "_" + channel + "." + extension; outputFile = new File(inputFile.getParent(), newName); } if (inputFile.equals(outputFile)) { try { ChannelWriter.put(outputFile, channel, extraInfo); } catch (IOException | SignatureNotFoundException e) { e.printStackTrace(); } } else { try { FileUtils.copyFile(inputFile, outputFile); ChannelWriter.put(outputFile, channel, extraInfo); } catch (IOException | SignatureNotFoundException e) { e.printStackTrace(); } } } }
private static String tailSystemLog(DistributionConfig sc) throws IOException { File logFile = sc.getLogFile(); if (logFile == null || logFile.equals(new File(""))) { return null; } if (!logFile.isAbsolute()) { logFile = new File(logFile.getAbsolutePath()); } return tailSystemLog(logFile); } }
if (!srcFile.exists()) { throw new BuildException("src " + srcFile.toString() + " does not exist.", getLocation()); if (srcFile.equals(destFile)) { log("Warning: src == dest", Project.MSG_WARN); } catch (IOException ioe) { throw new BuildException( "Error copying file: " + srcFile.getAbsolutePath() + " due to " + ioe.getMessage());
/** * Are we a file and a JSON or YAML file? */ private boolean isProcessConfigFile(File file) { if (this.configuration.getProcessConfigDirOrFile().isFile()) { return file.equals(this.configuration.getProcessConfigDirOrFile()); } // If the file doesn't exist anymore, treat it as a regular file (to handle file deletion events) if(file.exists() && !file.isFile()) { return false; } final String fileName = file.getName(); return !fileName.startsWith(".") && (fileName.endsWith(".json") || fileName.endsWith(".yml") || fileName.endsWith(".yaml")); }
@Override public void afterPropertiesSet() throws Exception { if (uploadDirectory.equals(parseFailureDirectory)) { throw new Exception("Upload and parse failed directories must not be the same directory: " + uploadDirectory); } if (!uploadDirectory.exists()) { uploadDirectory.mkdirs(); } if (!parseFailureDirectory.exists()) { parseFailureDirectory.mkdirs(); } }
/** * Are the two File instances pointing to the same object on the * file system? * * @param f1 File * @param f2 File * @return boolean * @throws IOException if file name canonicalization fails * @since Ant 1.8.2 */ public boolean areSame(File f1, File f2) throws IOException { if (f1 == null && f2 == null) { return true; } if (f1 == null || f2 == null) { return false; } File f1Normalized = normalize(f1.getAbsolutePath()); File f2Normalized = normalize(f2.getAbsolutePath()); return f1Normalized.equals(f2Normalized) || f1Normalized.getCanonicalFile().equals(f2Normalized .getCanonicalFile()); }
File f1 = parent.getCanonicalFile(); File f2 = file.getCanonicalFile(); if (f1.equals(f2)) { LOGGER.log(Level.INFO, "Skipping links to itself...: {0} {1}", new Object[]{parent.getAbsolutePath(), file.getAbsolutePath()}); return false; while ((t1 = t1.getParentFile()) != null) { if (f2.equals(t1)) { LOGGER.log(Level.INFO, "Skipping links to parent...: {0} {1}", new Object[]{parent.getAbsolutePath(), file.getAbsolutePath()}); return false;
public void add(SootClass c) { if (c.isPhantom()) { return; } addAsClassDefItem(c); // save original APK for this class, needed to copy all the other files // inside Map<String, File> dexClassIndex = SourceLocator.v().dexClassIndex(); if (dexClassIndex == null) { return; // no dex classes were loaded } File sourceForClass = dexClassIndex.get(c.getName()); if (sourceForClass == null || sourceForClass.getName().endsWith(".dex")) { return; // a class was written that was not a dex class or the class // originates from a .dex file, not an APK } if (originalApk != null && !originalApk.equals(sourceForClass)) { throw new CompilationDeathException("multiple APKs as source of an application are not supported"); } originalApk = sourceForClass; }
public static boolean isSymlink(File file) throws IOException { if (file == null) throw new NullPointerException("File must not be null"); File canon; if (file.getParent() == null) { canon = file; } else { File canonDir = file.getParentFile().getCanonicalFile(); canon = new File(canonDir, file.getName()); } return !canon.getCanonicalFile().equals(canon.getAbsoluteFile()); }
/** * {@inheritDoc} */ @SuppressFBWarnings(value = "IT_NO_SUCH_ELEMENT", justification = "Exception is thrown by invoking removeFirst on an empty list.") public Element next() { try { return new Element.ForFile(folder, files.removeFirst()); } finally { while (!files.isEmpty() && (files.peek().isDirectory() || files.peek().equals(new File(folder, JarFile.MANIFEST_NAME)))) { File folder = files.removeFirst(); File[] file = folder.listFiles(); if (file != null) { files.addAll(0, Arrays.asList(file)); } } } }
/** * Grab the rather voluminous vertical datum files from the OTP web server and save them in the NED cache directory. */ private void fetchDatum() throws Exception { LOG.info("Attempting to fetch datum files from OTP project web server..."); URL datumUrl = new URL("http://dev.opentripplanner.org/resources/datum.zip"); ZipInputStream zis = new ZipInputStream(datumUrl.openStream()); /* Silly boilerplate because Java has no simple unzip-to-directory function. */ for (ZipEntry entry = zis.getNextEntry(); entry != null; entry = zis.getNextEntry()) { if (entry.isDirectory()) { throw new RuntimeException("ZIP files containing directories are not supported"); } File file = new File(cacheDirectory, entry.getName()); if (!file.getParentFile().equals(cacheDirectory)) { throw new RuntimeException("ZIP files containing directories are not supported"); } LOG.info("decompressing {}", file); OutputStream os = new FileOutputStream(file); ByteStreams.copy(zis, os); os.close(); } zis.close(); LOG.info("Done."); }
final File outDir = new File(baseStorageDir, this.getStorageDir(segment, useUniquePath)); if (dataSegmentFile.equals(outDir)) { long size = 0; for (File file : dataSegmentFile.listFiles()) { final File tmpOutDir = new File(baseStorageDir, makeIntermediateDir()); log.info("Creating intermediate directory[%s] for segment[%s]", tmpOutDir.toString(), segment.getId()); FileUtils.forceMkdir(tmpOutDir); final File tmpIndexFile = new File(tmpOutDir, INDEX_FILENAME); final long size = compressSegment(dataSegmentFile, tmpIndexFile); final File indexFileTarget = new File(outDir, tmpIndexFile.getName()); final File descriptorFileTarget = new File(outDir, tmpDescriptorFile.getName());
private String createGroovyClassName(File root, File file) { StringBuffer sb = new StringBuffer(); String fileName = file.getName(); sb.append(fileName.substring(0, fileName.lastIndexOf(".groovy"))); file = file.getParentFile(); while (file != null && !file.equals(root)) { sb.insert(0, '.').insert(0, file.getName()); file = file.getParentFile(); } return sb.toString(); }