org.homeunix.thecave.moss.util
Class FileFunctions

java.lang.Object
  extended by org.homeunix.thecave.moss.util.FileFunctions

public class FileFunctions
extends java.lang.Object

Common file-based functions for which there is no good support in Java.

Author:
wyatt

Method Summary
static void copyFile(java.io.File source, java.io.File dest)
          Copies a given file from Source to Destination
static java.io.FilenameFilter getDirectoryFilter(boolean includeHiddenDirectories)
           
static java.io.FilenameFilter getExtensionFilter(boolean includeHiddenDirectories, java.lang.String... extensions)
           
static java.util.List<java.io.File> getFileTree(java.io.File root)
          Returns a list of all File objects which descend from the given root.
static boolean isFolderWritable(java.io.File folder)
          Simple test to see if a folder is writable.
static java.lang.String readTextStream(java.io.InputStream stream)
          Reads a String from a given InputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

copyFile

public static void copyFile(java.io.File source,
                            java.io.File dest)
                     throws java.io.IOException
Copies a given file from Source to Destination

Parameters:
source -
dest -
Throws:
java.io.IOException

readTextStream

public static java.lang.String readTextStream(java.io.InputStream stream)
                                       throws java.io.IOException
Reads a String from a given InputStream. Useful for reading text files from Jars, etc. Thanks to JST for helping find and fix a bug in this code which would append garbage characters to the output.

Parameters:
stream -
Returns:
Throws:
java.io.IOException

isFolderWritable

public static boolean isFolderWritable(java.io.File folder)
Simple test to see if a folder is writable. File.canWrite() does not work on all Windows folders, as the folder may be set RO but permissions allow it to be written. This is in response to Buddi bug #1716654, "Error creating a new file in My Documents folder".

Parameters:
folder -
Returns:

getFileTree

public static java.util.List<java.io.File> getFileTree(java.io.File root)
Returns a list of all File objects which descend from the given root. If root is a file, this list will contain just that file. It root if a directory, this list will contain that file, plus all directories and files beneath it.

Parameters:
root -
Returns:

getDirectoryFilter

public static java.io.FilenameFilter getDirectoryFilter(boolean includeHiddenDirectories)

getExtensionFilter

public static java.io.FilenameFilter getExtensionFilter(boolean includeHiddenDirectories,
                                                        java.lang.String... extensions)