com.denova.io
Class FileSystem

java.lang.Object
  |
  +--com.denova.io.FileSystem

public class FileSystem
extends java.lang.Object

Manage files and directories.

Author:
DeNova Copyright (c) 1997-2008 DeNova All rights reserved worldwide. Last modified: 2008-05-23

Constructor Summary
FileSystem()
           
 
Method Summary
static void appendFile(java.io.File fromPath, java.io.File toPath)
          Appends a file.
static void copyDirectory(java.io.File fromDir, java.io.File toDir)
          Copies all the files from one directory to another directory.
static void copyDirectory(java.io.File fromDir, java.lang.String toDirPath)
          Copies all the files from one directory to another directory.
static void copyDirectory(java.lang.String fromDirPath, java.io.File toDir)
          Copies all the files from one directory to another directory.
static void copyDirectory(java.lang.String fromDirPath, java.lang.String toDirPath)
          Copies all the files from one directory to another directory.
static void copyFile(java.io.File fromPath, java.io.File toPath)
          Copies a file.
static void copyFile(java.io.File fromPath, java.lang.String toPathname)
          Copies an individual file.
static void copyFile(java.lang.String fromPathname, java.io.File toPath)
          Copies a file.
static void copyFile(java.lang.String fromPathname, java.lang.String toPathname)
          Copies a single file by filename.
static void copyFileToStream(java.io.File fromFile, java.io.OutputStream oStream)
          Copies a file to an output stream.
static void copyFileToStream(java.lang.String pathname, java.io.OutputStream oStream)
          Copies a file to an output stream.
static void copyFileToZipStream(java.io.File fromFile, java.lang.String toFilename, java.io.File baseDir, java.util.zip.ZipOutputStream zOut)
          Copies a file to an zip output stream.
static void copyFileToZipStream(java.io.File fromFile, java.lang.String filename, java.util.zip.ZipOutputStream zOut)
          Copies a file to an zip output stream.
static void copyFileToZipStream(java.lang.String filename, java.util.zip.ZipOutputStream zOut)
          Copies a file to an zip output stream.
static void copyStreams(java.io.InputStream in, java.io.OutputStream out)
          Copies an input stream to an output stream.
static void copyStreams(java.io.InputStream in, java.io.OutputStream out, long size)
          Copies an input stream to an output stream.
static void copyStreamToFile(java.io.InputStream iStream, java.io.File toFile)
          Copies a file to an output stream.
static void copyStreamToFile(java.io.InputStream iStream, java.lang.String pathname)
          Copies a file to an output stream.
static void createEmptyFile(java.io.File toFile)
          Create an empty file.
static java.lang.String findFileInPath(java.lang.String filename)
          Find a file in the path.
static long getCrc(java.io.File f)
          Returns the CRC for the file.
static boolean getFile(java.lang.String filename)
           
static boolean getFile(java.lang.String filename, java.io.InputStream in)
           
static java.io.InputStream getFileStream(java.lang.String filename)
          Get an input stream for a file.
static javax.swing.JProgressBar getProgressBar()
          Returns the currently active progress bar.
static javax.swing.JLabel getProgressStatus()
          Returns the current progress bar's status.
static java.lang.String getRelativePathname(java.io.File baseDir, java.io.File f)
          Gets a pathname relative to a base directory.
static java.net.URL getResource(java.lang.String name)
          IMPORTANT: Generally, you don't want to use this method because it isn't very portable; we're keeping it because sometimes we use it as a last ditch effort to get a resource
static boolean getResourceAsFile(java.lang.String filename)
          Copy a resource to a file.
static boolean getResourceAsFile(java.lang.String filename, java.lang.String pathname)
          Copy a resource to a file.
static java.io.InputStream getResourceAsStream(java.lang.String name)
          Get an input stream for a resource.
static boolean isRootDirectory(java.io.File d)
          Returns true if the parameter points to the root directory.
static boolean isRootDirectory(java.lang.String d)
          Returns true if the parameter points to the root directory.
static int read(java.io.InputStream in)
          Reads a byte from an input stream.
static int read(java.io.InputStream in, byte[] bytes)
          Reads bytes from an input stream.
static int read(java.io.InputStream in, byte[] bytes, int bytesToRead)
          Reads from the zero byte through the bytesToRead element from an input stream.
static boolean removeDirectory(java.io.File directory)
          Deletes all the files from the directory and then deletes the directory.
static boolean removeDirectory(java.lang.String dirName)
          Deletes all the files from the directory and then deletes the directory.
static boolean removeDirectoryContents(java.io.File directory)
          Deletes the contents of the directory, but not the directory.
static boolean removeDirectoryContents(java.lang.String dirName)
          Deletes the contents of the directory, but not the directory.
static boolean removeFile(java.lang.String name)
          Deletes the file from the system.
static boolean removeSubdirectories(java.io.File directory)
           
static void setHostUrl(java.lang.String newHostUrl)
          Set the host url where a resource might be found.
static void setProgressBar(javax.swing.JProgressBar bar)
          Set the progress bar to use when copying files or calculating the CRC.
static void setProgressStatus(javax.swing.JLabel status)
          Set the status for the progress bar.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileSystem

public FileSystem()
Method Detail

findFileInPath

public static java.lang.String findFileInPath(java.lang.String filename)
Find a file in the path. This method will not find a directory, only a file.

Parameters:
filename - is the name of the file to locate. A pathname should not be included.
Returns:
The full pathname, including filename, if found. Otherwise, it returns an empty string.


removeFile

public static boolean removeFile(java.lang.String name)
Deletes the file from the system.

Parameters:
name - is the full pathname for the file.
Returns:
true if successful


removeDirectory

public static boolean removeDirectory(java.lang.String dirName)
Deletes all the files from the directory and then deletes the directory.

Parameters:
dirName - is the full pathname for the directory.
Returns:
true if successful


removeDirectory

public static boolean removeDirectory(java.io.File directory)
Deletes all the files from the directory and then deletes the directory.

Parameters:
directory - is the name of the directory to delete.
Returns:
true if successful.


removeDirectoryContents

public static boolean removeDirectoryContents(java.lang.String dirName)
Deletes the contents of the directory, but not the directory.

Parameters:
dirName - is the full pathname to the directory
Returns:
true if successful


removeDirectoryContents

public static boolean removeDirectoryContents(java.io.File directory)
Deletes the contents of the directory, but not the directory.

Parameters:
directory - is a File that points to the directory
Returns:
true if successful


copyFile

public static void copyFile(java.lang.String fromPathname,
                            java.lang.String toPathname)
                     throws java.lang.Exception
Copies a single file by filename. If the toPathname already exists, then it is overwritten.

Parameters:
fromPathname - is the full pathname to the original file
toPathname is the full pathname to the new file
java.lang.Exception

copyFile

public static void copyFile(java.io.File fromPath,
                            java.lang.String toPathname)
                     throws java.lang.Exception
Copies an individual file.

If the toPathname already exists, then it is overwritten.

Parameters:
fromPath - is a File for the original file
toPathname is the full pathname to the new file
java.lang.Exception

copyFile

public static void copyFile(java.lang.String fromPathname,
                            java.io.File toPath)
                     throws java.lang.Exception
Copies a file.

If the toPath already exists, then it is overwritten.

Parameters:
fromPathname - is the full pathname to the original file
toPath is a File for the target file
java.lang.Exception

copyFile

public static void copyFile(java.io.File fromPath,
                            java.io.File toPath)
                     throws java.lang.Exception
Copies a file.

If the toPath already exists, then it is overwritten.

Parameters:
fromPath - is a File for the original file
toPath is a File for the target file
java.lang.Exception

copyFileToStream

public static void copyFileToStream(java.lang.String pathname,
                                    java.io.OutputStream oStream)
                             throws java.lang.Exception
Copies a file to an output stream.

If the destination file already exists, it is overwritten.

Parameters:
pathname - source file that is being copied
oStream destination file
java.lang.Exception

copyFileToStream

public static void copyFileToStream(java.io.File fromFile,
                                    java.io.OutputStream oStream)
                             throws java.lang.Exception
Copies a file to an output stream.

If the destination file already exists, it is overwritten.

Parameters:
fromFile - source file that is being copied
oStream destination file
java.lang.Exception

copyStreamToFile

public static void copyStreamToFile(java.io.InputStream iStream,
                                    java.lang.String pathname)
                             throws java.lang.Exception
Copies a file to an output stream.

If the destination file already exists, it is overwritten.

Parameters:
pathname - source file that is being copied
pathname destination file
java.lang.Exception

copyStreamToFile

public static void copyStreamToFile(java.io.InputStream iStream,
                                    java.io.File toFile)
                             throws java.lang.Exception
Copies a file to an output stream.

If the destination file already exists, it is overwritten.

Parameters:
iStream - source file that is being copied
toFile destination file
java.lang.Exception

copyFileToZipStream

public static void copyFileToZipStream(java.lang.String filename,
                                       java.util.zip.ZipOutputStream zOut)
                                throws java.lang.Exception
Copies a file to an zip output stream.

If the destination file already exists, it is overwritten.

Parameters:
filename - source file that is being copied
zOut destination file
java.lang.Exception

copyFileToZipStream

public static void copyFileToZipStream(java.io.File fromFile,
                                       java.lang.String filename,
                                       java.util.zip.ZipOutputStream zOut)
                                throws java.lang.Exception
Copies a file to an zip output stream.

If the destination file already exists, it is overwritten.

Parameters:
fromFile - source file that is being copied
filename destination file
zOut zip file
java.lang.Exception

copyFileToZipStream

public static void copyFileToZipStream(java.io.File fromFile,
                                       java.lang.String toFilename,
                                       java.io.File baseDir,
                                       java.util.zip.ZipOutputStream zOut)
                                throws java.lang.Exception
Copies a file to an zip output stream.

If the destination file already exists, it is overwritten.

Parameters:
fromFile - source file that is being copied
toFilename destination file
baseDir zipped filenames are relative to the base directory, if any
zOut zip file
java.lang.Exception

appendFile

public static void appendFile(java.io.File fromPath,
                              java.io.File toPath)
                       throws java.lang.Exception
Appends a file.

If the toPath doesn't exist, then it creates.

Parameters:
fromPath - is a pathname for the original file
toPath is a pathname for the target file or directory; if directory then filename of the fromPathname is attached to the toPathname
java.lang.Exception

createEmptyFile

public static void createEmptyFile(java.io.File toFile)
                            throws java.lang.Exception
Create an empty file.

If the toFile already exists, then it is overwritten.

Parameters:
toFile - is full path for the file that will be created
java.lang.Exception

getRelativePathname

public static java.lang.String getRelativePathname(java.io.File baseDir,
                                                   java.io.File f)
                                            throws java.lang.Exception
Gets a pathname relative to a base directory.

Parameters:
baseDir - the base directory
f non-relative path, or file representing the path.
java.lang.Exception

copyDirectory

public static void copyDirectory(java.lang.String fromDirPath,
                                 java.lang.String toDirPath)
                          throws java.lang.Exception
Copies all the files from one directory to another directory.

If the destination directory already exists, then the source files are added to the destination directory. Source files overwrite any existing files with the same name in the destination.

Parameters:
fromDirPath - source directory that is being copied
toDirPath destination directory
java.lang.Exception

copyDirectory

public static void copyDirectory(java.io.File fromDir,
                                 java.lang.String toDirPath)
                          throws java.lang.Exception
Copies all the files from one directory to another directory.

If the destination directory already exists, then the source files are added to the destination directory. Source files overwrite any existing files with the same name in the destination.

Parameters:
fromDir - source directory that is being copied
toDirPath destination directory
java.lang.Exception

copyDirectory

public static void copyDirectory(java.lang.String fromDirPath,
                                 java.io.File toDir)
                          throws java.lang.Exception
Copies all the files from one directory to another directory.

If the destination directory already exists, then the source files are added to the destination directory. Source files overwrite any existing files with the same name in the destination.

Parameters:
fromDirPath - source directory that is being copied
toDir destination directory
java.lang.Exception

copyDirectory

public static void copyDirectory(java.io.File fromDir,
                                 java.io.File toDir)
                          throws java.lang.Exception
Copies all the files from one directory to another directory.

If the destination directory already exists, then the source files are added to the destination directory. Source files overwrite any existing files with the same name in the destination.

Parameters:
fromDir - source directory that is being copied
toDir destination directory
java.lang.Exception

copyStreams

public static void copyStreams(java.io.InputStream in,
                               java.io.OutputStream out)
                        throws java.lang.Exception
Copies an input stream to an output stream.

If the destination stream already exists, it is overwritten.

Parameters:
in - source stream that is being copied
out destination stream
java.lang.Exception

copyStreams

public static void copyStreams(java.io.InputStream in,
                               java.io.OutputStream out,
                               long size)
                        throws java.lang.Exception
Copies an input stream to an output stream.

If the destination stream already exists, it is overwritten. The file size is used to calculate the percentage copied.

Parameters:
in - source stream that is being copied
out destination stream
size file size
java.lang.Exception

getResourceAsFile

public static boolean getResourceAsFile(java.lang.String filename)
                                 throws java.lang.Exception
Copy a resource to a file. The resource can be located in the classpath, current directory, etc.

Parameters:
filename - to get, including the destination pathname.
Returns:
true if successful.
java.lang.Exception

getResourceAsFile

public static boolean getResourceAsFile(java.lang.String filename,
                                        java.lang.String pathname)
                                 throws java.lang.Exception
Copy a resource to a file. The resource can be located in the classpath, current directory, etc.

Parameters:
filename - file to get.
pathname - destination pathname.
Returns:
true if successful.
java.lang.Exception

getResourceAsStream

public static java.io.InputStream getResourceAsStream(java.lang.String name)
Get an input stream for a resource. The resource can be located in the classpath, current directory, etc.

Parameters:
name - filename to get.
Returns:
stream to resource.

getResource

public static java.net.URL getResource(java.lang.String name)
IMPORTANT: Generally, you don't want to use this method because it isn't very portable; we're keeping it because sometimes we use it as a last ditch effort to get a resource


getFile

public static boolean getFile(java.lang.String filename)
                       throws java.lang.Exception
java.lang.Exception

getFile

public static boolean getFile(java.lang.String filename,
                              java.io.InputStream in)
                       throws java.lang.Exception
java.lang.Exception

getFileStream

public static java.io.InputStream getFileStream(java.lang.String filename)
                                         throws java.lang.Exception
Get an input stream for a file.

Parameters:
filename - to get.
Returns:
stream to the file.
java.lang.Exception

read

public static int read(java.io.InputStream in)
                throws java.io.IOException
Reads a byte from an input stream.

Parameters:
in - input stream where byte is read from
java.io.IOException

read

public static int read(java.io.InputStream in,
                       byte[] bytes)
                throws java.io.IOException
Reads bytes from an input stream.

Parameters:
in - an input stream that is already open
bytes where the bytes read are stored
java.io.IOException

read

public static int read(java.io.InputStream in,
                       byte[] bytes,
                       int bytesToRead)
                throws java.io.IOException
Reads from the zero byte through the bytesToRead element from an input stream.

Parameters:
in - input stream that is already open
bytes location where the bytes are stored
bytesToRead last element
java.io.IOException

isRootDirectory

public static boolean isRootDirectory(java.lang.String d)
Returns true if the parameter points to the root directory.

On Windows, it returns true if the parameter points to the root for the File's drive.


isRootDirectory

public static boolean isRootDirectory(java.io.File d)
Returns true if the parameter points to the root directory.

On Windows, it returns true if the parameter points to the root for the File's drive.


getCrc

public static long getCrc(java.io.File f)
                   throws java.lang.Exception
Returns the CRC for the file.

java.lang.Exception

setHostUrl

public static void setHostUrl(java.lang.String newHostUrl)
Set the host url where a resource might be found.


setProgressBar

public static void setProgressBar(javax.swing.JProgressBar bar)
Set the progress bar to use when copying files or calculating the CRC.


getProgressBar

public static javax.swing.JProgressBar getProgressBar()
Returns the currently active progress bar.


setProgressStatus

public static void setProgressStatus(javax.swing.JLabel status)
Set the status for the progress bar.


getProgressStatus

public static javax.swing.JLabel getProgressStatus()
Returns the current progress bar's status.


removeSubdirectories

public static boolean removeSubdirectories(java.io.File directory)