/** * <p>Appends the given path to the end of this path. * * @param other The path to append * @return The new path */ public RelativePath append(RelativePath other) { return new RelativePath(other.endsWithFile, this, other.segments); }
/** * Appends the given names to the end of this path. * * @param segments The names to append. * @param endsWithFile when true, the new path refers to a file. * @return The new path. */ public RelativePath append(boolean endsWithFile, String... segments) { return new RelativePath(endsWithFile, this, segments); }
public static RelativePath parse(boolean isFile, RelativePath parent, String path) { String[] names = StringUtils.split(path, FILE_PATH_SEPARATORS); return new RelativePath(isFile, parent, names); }
public DefaultFileVisitDetails(File file, Chmod chmod, Stat stat) { this(file, new RelativePath(!file.isDirectory(), file.getName()), new AtomicBoolean(), chmod, stat); }
/** * Prepends the given names to the start of this path. * * @param segments The names to prepend * @return The new path. */ public RelativePath prepend(String... segments) { return new RelativePath(false, segments).append(this); }
private FileSnapshot calculateDetails(File file) { String path = getPath(file); FileMetadataSnapshot stat = fileSystem.stat(file); switch (stat.getType()) { case Missing: return new MissingFileSnapshot(path, new RelativePath(true, file.getName())); case Directory: return new DirectoryFileSnapshot(path, new RelativePath(false, file.getName()), true); case RegularFile: return new RegularFileSnapshot(path, new RelativePath(true, file.getName()), true, fileSnapshot(file, stat)); default: throw new IllegalArgumentException("Unrecognized file type: " + stat.getType()); } }
/** * Returns the parent of this path. * * @return The parent of this path, or null if this is the root path. */ public RelativePath getParent() { switch (segments.length) { case 0: return null; case 1: return EMPTY_ROOT; default: String[] parentSegments = new String[segments.length - 1]; copySegments(parentSegments, segments); return new RelativePath(false, parentSegments); } }
private static RelativePath stripFirstName(RelativePath relativePath) { String[] segments = relativePath.getSegments(); return new RelativePath(relativePath.isFile(), Arrays.copyOfRange(segments, 1, segments.length)); } }
public RelativePath getRelativePath() { return new RelativePath(!entry.isDirectory(), entry.getName().split("/")); }
/** * <p>Returns a copy of this path, with the last name replaced with the given name.</p> * * @param name The name. * @return The path. */ public RelativePath replaceLastName(String name) { String[] newSegments = new String[segments.length]; copySegments(newSegments, segments, segments.length - 1); newSegments[segments.length - 1] = internPathSegment(name); return new RelativePath(endsWithFile, newSegments); }
public RelativePath getRelativePath() { return new RelativePath(!entry.isDirectory(), entry.getName().split("/")); }
private void processSingleFile(File file, FileVisitor visitor, Spec<FileTreeElement> spec, AtomicBoolean stopFlag) { RelativePath path = new RelativePath(true, file.getName()); FileVisitDetails details = new DefaultFileVisitDetails(file, path, stopFlag, fileSystem, fileSystem, false); if (isAllowed(details, spec)) { visitor.visitFile(details); } }
private void doVisitDirOrFile(FileVisitor visitor, File file, LinkedList<String> relativePath, int segmentIndex, AtomicBoolean stopFlag) { if (file.isFile()) { if (segmentIndex == patternSegments.size()) { RelativePath path = new RelativePath(true, relativePath.toArray(new String[relativePath.size()])); FileVisitDetails details = new DefaultFileVisitDetails(file, path, stopFlag, fileSystem, fileSystem); if (!excludeSpec.isSatisfiedBy(details)) { visitor.visitFile(details); } } } else if (file.isDirectory()) { RelativePath path = new RelativePath(false, relativePath.toArray(new String[relativePath.size()])); FileVisitDetails details = new DefaultFileVisitDetails(file, path, stopFlag, fileSystem, fileSystem); if (!excludeSpec.isSatisfiedBy(details)) { visitor.visitDir(details); } if (segmentIndex < patternSegments.size()) { doVisit(visitor, file, relativePath, segmentIndex, stopFlag); } } }
public RelativePath getDestPath() { RelativePath parentPath; if (parentResolver == null) { parentPath = new RelativePath(false); } else { parentPath = parentResolver.getDestPath(); } if (destDir == null) { return parentPath; } String path = PATH_NOTATION_PARSER.parseNotation(destDir); if (path.startsWith("/") || path.startsWith(File.separator)) { return RelativePath.parse(false, path); } return RelativePath.parse(false, parentPath, path); }
patternSet.exclude(excludeSpec); DirectoryFileTree fileTree = new DirectoryFileTree(baseDir, patternSet, fileSystem); fileTree.visitFrom(visitor, file, new RelativePath(file.isFile(), relativePath.toArray(new String[relativePath.size()]))); } else if (segment.contains("*") || segment.contains("?")) { PatternStep step = PatternStepFactory.getStep(segment, false);
final RelativePath relativePath = new RelativePath(true, segments);