org.vizzini.util
Class FileUtilities

java.lang.Object
  extended by org.vizzini.util.FileUtilities

public class FileUtilities
extends Object

Provides convenience methods for working with files.

Since:
v0.3
Version:
v0.3
Author:
Jeffrey M. Thompson

Nested Class Summary
(package private)  class FileUtilities.URLComparator
          Provides an implementation of Comparator for URLs.
 
Field Summary
protected static String LINE_SEPARATOR
          Line separator.
 
Method Summary
static FileUtilities getInstance()
          Return the singleton instance.
protected  boolean isPrefixedWith(URL url, List list)
          Return true if the given URL is prefixed by any item in the given list.
protected  boolean isSuffixedWith(URL url, List list)
          Return true if the given URL is suffixed with any item in the given list.
 URL[] listDirectories(String protocol, String host, String file, List includePrefixes, List includeSuffixes, List excludePrefixes, List excludeSuffixes)
          List all directories using the given parameters.
 URL[] listDirectories(String protocol, String host, String file, List includePrefixes, List includeSuffixes, List excludePrefixes, List excludeSuffixes, boolean isRecursive)
          List all directories using the given parameters.
 URL[] listFiles(String protocol, String host, String file)
          List all files using the given parameters.
 URL[] listFiles(String protocol, String host, String file, List includePrefixes, List includeSuffixes, List excludePrefixes, List excludeSuffixes)
          List all files using the given parameters.
 URL[] listFiles(String protocol, String host, String file, List includePrefixes, List includeSuffixes, List excludePrefixes, List excludeSuffixes, boolean isRecursive)
          List all files using the given parameters.
 URL[] listFiles(String protocol, String host, String file, List includePrefixes, List includeSuffixes, List excludePrefixes, List excludeSuffixes, boolean isRecursive, boolean isDirectoriesOnly)
          List all files using the given parameters.
 URL[] listFiles(URL url)
          Return a collection of URLs representing files at the given URL.
protected  boolean passes(URL url, List includePrefixes, List includeSuffixes, List excludePrefixes, List excludeSuffixes)
          Return true if the given URL passes the filter as specified by the other parameters.
protected  String read(BufferedReader reader)
          Return the contents of the given reader.
 String readFile(InputStream inputStream)
          Return the contents of the given input stream.
 String readFile(Reader reader)
          Return the contents of the given reader.
 String readFile(String sFilepath)
          Return the contents of the file at the given path.
 String readFile(URL url)
          Return the contents of the file at the given URL.
 void writeFile(File file, String content)
          Write the given string to the given file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LINE_SEPARATOR

protected static final String LINE_SEPARATOR
Line separator.

Method Detail

getInstance

public static FileUtilities getInstance()
Return the singleton instance.

Since:
v0.3

listDirectories

public URL[] listDirectories(String protocol,
                             String host,
                             String file,
                             List includePrefixes,
                             List includeSuffixes,
                             List excludePrefixes,
                             List excludeSuffixes)
                      throws MalformedURLException
List all directories using the given parameters.

Parameters:
protocol - Protocol (e.g. http or file).
host - Host.
file - File.
includePrefixes - List of included prefixes (ignored if null).
includeSuffixes - List of included suffixes (ignored if null).
excludePrefixes - List of excluded prefixes (ignored if null).
excludeSuffixes - List of excluded suffixes (ignored if null).
Throws:
MalformedURLException
Since:
v0.3

listDirectories

public URL[] listDirectories(String protocol,
                             String host,
                             String file,
                             List includePrefixes,
                             List includeSuffixes,
                             List excludePrefixes,
                             List excludeSuffixes,
                             boolean isRecursive)
                      throws MalformedURLException
List all directories using the given parameters.

Parameters:
protocol - Protocol (e.g. http or file).
host - Host.
file - File.
includePrefixes - List of included prefixes (ignored if null).
includeSuffixes - List of included suffixes (ignored if null).
excludePrefixes - List of excluded prefixes (ignored if null).
excludeSuffixes - List of excluded suffixes (ignored if null).
isRecursive - Flag indicating whether to recursively include subdirectories.
Throws:
MalformedURLException
Since:
v0.3

listFiles

public URL[] listFiles(URL url)
                throws IOException
Return a collection of URLs representing files at the given URL.

Parameters:
url - Parent directory of the files to list.
Returns:
a collection of URLs representing files.
Throws:
IOException
Since:
v0.3

listFiles

public URL[] listFiles(String protocol,
                       String host,
                       String file)
                throws MalformedURLException
List all files using the given parameters.

Parameters:
protocol - Protocol (e.g. http or file).
host - Host.
file - File.
Throws:
MalformedURLException
Since:
v0.3

listFiles

public URL[] listFiles(String protocol,
                       String host,
                       String file,
                       List includePrefixes,
                       List includeSuffixes,
                       List excludePrefixes,
                       List excludeSuffixes)
                throws MalformedURLException
List all files using the given parameters.

Parameters:
protocol - Protocol (e.g. http or file).
host - Host.
file - File.
includePrefixes - List of included prefixes (ignored if null).
includeSuffixes - List of included suffixes (ignored if null).
excludePrefixes - List of excluded prefixes (ignored if null).
excludeSuffixes - List of excluded suffixes (ignored if null).
Throws:
MalformedURLException
Since:
v0.3

listFiles

public URL[] listFiles(String protocol,
                       String host,
                       String file,
                       List includePrefixes,
                       List includeSuffixes,
                       List excludePrefixes,
                       List excludeSuffixes,
                       boolean isRecursive)
                throws MalformedURLException
List all files using the given parameters.

Parameters:
protocol - Protocol (e.g. http or file).
host - Host.
file - File.
includePrefixes - List of included prefixes (ignored if null).
includeSuffixes - List of included suffixes (ignored if null).
excludePrefixes - List of excluded prefixes (ignored if null).
excludeSuffixes - List of excluded suffixes (ignored if null).
isRecursive - Flag indicating whether to recursively include subdirectories.
Throws:
MalformedURLException
Since:
v0.3

listFiles

public URL[] listFiles(String protocol,
                       String host,
                       String file,
                       List includePrefixes,
                       List includeSuffixes,
                       List excludePrefixes,
                       List excludeSuffixes,
                       boolean isRecursive,
                       boolean isDirectoriesOnly)
                throws MalformedURLException
List all files using the given parameters.

Parameters:
protocol - Protocol (e.g. http or file).
host - Host.
file - File.
includePrefixes - List of included prefixes (ignored if null).
includeSuffixes - List of included suffixes (ignored if null).
excludePrefixes - List of excluded prefixes (ignored if null).
excludeSuffixes - List of excluded suffixes (ignored if null).
isRecursive - Flag indicating whether to recursively include subdirectories.
isDirectoriesOnly - Flag indicating whether to include directories only.
Throws:
MalformedURLException
Since:
v0.3

readFile

public String readFile(Reader reader)
                throws IOException
Return the contents of the given reader.

Parameters:
reader - Reader.
Returns:
The contents of the file.
Throws:
IOException
Since:
v0.3

readFile

public String readFile(InputStream inputStream)
                throws IOException
Return the contents of the given input stream.

Parameters:
inputStream - Input stream.
Returns:
The contents of the file.
Throws:
IOException
Since:
v0.3

readFile

public String readFile(String sFilepath)
                throws FileNotFoundException,
                       IOException
Return the contents of the file at the given path.

Parameters:
sFilepath - Path to the file.
Returns:
The contents of the file.
Throws:
FileNotFoundException
IOException
Since:
v0.3

readFile

public String readFile(URL url)
                throws IOException
Return the contents of the file at the given URL.

Parameters:
url - URL of the file.
Returns:
The contents of the file.
Throws:
IOException
Since:
v0.3

writeFile

public void writeFile(File file,
                      String content)
               throws IOException
Write the given string to the given file.

Parameters:
file - File to which to write.
content - Content to put into the file.
Throws:
IOException
Since:
v0.3

isPrefixedWith

protected boolean isPrefixedWith(URL url,
                                 List list)
Return true if the given URL is prefixed by any item in the given list.

Parameters:
list - List of prefixes.
url - URL.
Since:
v0.3

isSuffixedWith

protected boolean isSuffixedWith(URL url,
                                 List list)
Return true if the given URL is suffixed with any item in the given list.

Parameters:
list - List of suffixes.
url - URL.
Since:
v0.3

passes

protected boolean passes(URL url,
                         List includePrefixes,
                         List includeSuffixes,
                         List excludePrefixes,
                         List excludeSuffixes)
Return true if the given URL passes the filter as specified by the other parameters.

Parameters:
url - URL.
includePrefixes - List of included prefixes (ignored if null).
includeSuffixes - List of included suffixes (ignored if null).
excludePrefixes - List of excluded prefixes (ignored if null).
excludeSuffixes - List of excluded suffixes (ignored if null).
Since:
v0.3

read

protected String read(BufferedReader reader)
               throws IOException
Return the contents of the given reader.

Parameters:
reader - Buffered reader.
Returns:
The contents of the reader.
Throws:
IOException
Since:
v0.3


Copyright 2007 Vizzini.org. All Rights Reserved. 2007.12.25.03.00.02