net.sf.staccatocommons.io
Class Directory

java.lang.Object
  extended by net.sf.staccatocommons.io.Directory

public class Directory
extends Object

Author:
flbulgarelli

Constructor Summary
Directory(File file)
          Creates a new Directory from a File.
Directory(String pathname)
          Creates a new Directory from a pathname
 
Method Summary
 Directory clean()
          Cleans this directory using FileUtils.cleanDirectory(this.getFile())
 Directory copy(Directory destination)
          Copies this directory and its contents to the given destinantion using FileUtils.copyDirectory(file, destination.getFile())
 String getAbsolutePath()
          Answers the absolute path of this directory
 Stream<File> getBreadthFirstFileStream()
          Returns a Stream that retrieves all the non-directory files contained by this directory or in subdirectories, recursing the directory tree using a breadth-first algorithm
 Stream<File> getDepthFirstFileStream()
          Returns a Stream that retrieves all the non-directory files contained by this directory or in subdirectories, recursing the directory tree using a depth-first algorithm
 File getFile()
          Returns the underlying File of this directory
 Stream<File> getFileStream()
          returns a Stream of the files directly contained by this directory
 Stream<File> getRecurseFileStream()
          Synonym of getDepthFirstFileStream().
 long size()
          Answers Directory size.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Directory

public Directory(@NonNull
                 String pathname)
Creates a new Directory from a pathname

Parameters:
pathname - the pathname of the directory. It must point to a directory

Directory

public Directory(@NonNull
                 File file)
Creates a new Directory from a File.

Parameters:
file - must be a directory
Method Detail

getAbsolutePath

@NonNull
public String getAbsolutePath()
Answers the absolute path of this directory

Returns:
getFile().getAbsolutePath()
See Also:
File.getAbsolutePath()

getFile

@NonNull
public File getFile()
Returns the underlying File of this directory

Returns:
the underlying file. It grants be a directory

getFileStream

@NonNull
public Stream<File> getFileStream()
returns a Stream of the files directly contained by this directory

Returns:
a new ordered Stream. However, precise order of files in the stream depend on the filesystem
See Also:
File.listFiles()

getBreadthFirstFileStream

@NonNull
public Stream<File> getBreadthFirstFileStream()
Returns a Stream that retrieves all the non-directory files contained by this directory or in subdirectories, recursing the directory tree using a breadth-first algorithm

Returns:
a new Stream.
See Also:
Breadth first search

getDepthFirstFileStream

@NonNull
public Stream<File> getDepthFirstFileStream()
Returns a Stream that retrieves all the non-directory files contained by this directory or in subdirectories, recursing the directory tree using a depth-first algorithm

Returns:
a new Stream.
See Also:
Depth first search

getRecurseFileStream

@NonNull
public Stream<File> getRecurseFileStream()
Synonym of getDepthFirstFileStream(). Prefer this method if iteration order is not important

Returns:
getDepthFirstFileStream()

size

public long size()
Answers Directory size.

Returns:
FileUtils.sizeOfDirectory(this.getFile())
See Also:
FileUtils.sizeOfDirectory(File)

clean

public Directory clean()
                throws IOException
Cleans this directory using FileUtils.cleanDirectory(this.getFile())

Returns:
this
Throws:
IOException
See Also:
FileUtils#cleanDirectory(File)}

copy

public Directory copy(@NonNull
                      Directory destination)
               throws IOException
Copies this directory and its contents to the given destinantion using FileUtils.copyDirectory(file, destination.getFile())

Parameters:
destination - the new directory
Returns:
this
Throws:
IOException


Copyright © 2010-2012 Staccatocommons. All Rights Reserved.