@Override public Stream<FileHandle> streamFilesRecursive( File directory ) throws IOException { return StreamFilesRecursive.streamFilesRecursive( directory, this ); }
/** * Static implementation of {@link FileSystemAbstraction#streamFilesRecursive(File)} that does not require * any external state, other than what is presented through the given {@link FileSystemAbstraction}. * * Return a stream of {@link FileHandle file handles} for every file in the given directory, and its * sub-directories. * <p> * Alternatively, if the {@link File} given as an argument refers to a file instead of a directory, then a stream * will be returned with a file handle for just that file. * <p> * The stream is based on a snapshot of the file tree, so changes made to the tree using the returned file handles * will not be reflected in the stream. * <p> * No directories will be returned. Only files. If a file handle ends up leaving a directory empty through a * rename or a delete, then the empty directory will automatically be deleted as well. * Likewise, if a file is moved to a path where not all of the directories in the path exists, then those missing * directories will be created prior to the file rename. * * @param directory The base directory to start streaming files from, or the specific individual file to stream. * @param fs The {@link FileSystemAbstraction} to use for manipulating files. * @return A {@link Stream} of {@link FileHandle}s * @throws IOException If an I/O error occurs, possibly with the canonicalisation of the paths. */ public static Stream<FileHandle> streamFilesRecursive( File directory, FileSystemAbstraction fs ) throws IOException { File canonicalizedDirectory = directory.getCanonicalFile(); // We grab a snapshot of the file tree to avoid seeing the same file twice or more due to renames. List<File> snapshot = streamFilesRecursiveInner( canonicalizedDirectory, fs ).collect( toList() ); return snapshot.stream().map( f -> new WrappingFileHandle( f, canonicalizedDirectory, fs ) ); }
private static Stream<File> streamFilesRecursiveInner( File directory, FileSystemAbstraction fs ) { File[] files = fs.listFiles( directory ); if ( files == null ) { if ( !fs.fileExists( directory ) ) { return Stream.empty(); } return Stream.of( directory ); } else { return Stream.of( files ) .flatMap( f -> fs.isDirectory( f ) ? streamFilesRecursiveInner( f, fs ) : Stream.of( f ) ); } } }
@Override public Stream<FileHandle> streamFilesRecursive( File directory ) throws IOException { return StreamFilesRecursive.streamFilesRecursive( directory, this ); }
/** * Static implementation of {@link FileSystemAbstraction#streamFilesRecursive(File)} that does not require * any external state, other than what is presented through the given {@link FileSystemAbstraction}. * * Return a stream of {@link FileHandle file handles} for every file in the given directory, and its * sub-directories. * <p> * Alternatively, if the {@link File} given as an argument refers to a file instead of a directory, then a stream * will be returned with a file handle for just that file. * <p> * The stream is based on a snapshot of the file tree, so changes made to the tree using the returned file handles * will not be reflected in the stream. * <p> * No directories will be returned. Only files. If a file handle ends up leaving a directory empty through a * rename or a delete, then the empty directory will automatically be deleted as well. * Likewise, if a file is moved to a path where not all of the directories in the path exists, then those missing * directories will be created prior to the file rename. * * @param directory The base directory to start streaming files from, or the specific individual file to stream. * @param fs The {@link FileSystemAbstraction} to use for manipulating files. * @return A {@link Stream} of {@link FileHandle}s * @throws IOException If an I/O error occurs, possibly with the canonicalisation of the paths. */ public static Stream<FileHandle> streamFilesRecursive( File directory, FileSystemAbstraction fs ) throws IOException { File canonicalizedDirectory = directory.getCanonicalFile(); // We grab a snapshot of the file tree to avoid seeing the same file twice or more due to renames. List<File> snapshot = streamFilesRecursiveInner( canonicalizedDirectory, fs ).collect( toList() ); return snapshot.stream().map( f -> new WrappingFileHandle( f, canonicalizedDirectory, fs ) ); }
@Override public Stream<FileHandle> streamFilesRecursive( File directory ) throws IOException { return StreamFilesRecursive.streamFilesRecursive( directory, this ); }
private static Stream<File> streamFilesRecursiveInner( File directory, FileSystemAbstraction fs ) { File[] files = fs.listFiles( directory ); if ( files == null ) { if ( !fs.fileExists( directory ) ) { return Stream.empty(); } return Stream.of( directory ); } else { return Stream.of( files ) .flatMap( f -> fs.isDirectory( f ) ? streamFilesRecursiveInner( f, fs ) : Stream.of( f ) ); } } }
@Override public Stream<FileHandle> streamFilesRecursive( File directory ) throws IOException { return StreamFilesRecursive.streamFilesRecursive( directory, this ); }
@Override public Stream<FileHandle> streamFilesRecursive( File directory ) throws IOException { return StreamFilesRecursive.streamFilesRecursive( directory, this ); }
@Override public Stream<FileHandle> streamFilesRecursive( File directory ) throws IOException { return StreamFilesRecursive.streamFilesRecursive( directory, this ); }
@Override public Stream<FileHandle> streamFilesRecursive( File directory ) throws IOException { return StreamFilesRecursive.streamFilesRecursive( directory, this ); }
@Override public Stream<FileHandle> streamFilesRecursive( File directory ) throws IOException { return StreamFilesRecursive.streamFilesRecursive( directory, this ); }