|
2.12.0: 2009-05-27 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.basedb.util.FileUtil
public class FileUtil
This class collects some useful methods for file and stream handling.
Field Summary | |
---|---|
private static int |
BUFFER_SIZE
|
Constructor Summary | |
---|---|
FileUtil()
|
Method Summary | |
---|---|
static boolean |
checkMagicNumber(PushbackInputStream pin,
byte[] bCheck)
Take a peek at an input stream and check if the first few bytes matches the bCheck parameter. |
static void |
close(InputStream in)
Close an input stream without throwing an exception. |
static void |
close(OutputStream out)
Close an output stream without throwing an exception. |
static long |
copy(InputStream in,
OutputStream out)
Copy from the input stream to the output stream until end of file is reached. |
static long |
copy(InputStream in,
OutputStream out,
AbsoluteProgressReporter progress)
Copy from the input stream to the output stream until end of file is reached. |
static long |
copy(Reader in,
Writer out)
Copy from the reader to the writer until end of file is reached. |
static long |
copy(Reader in,
Writer out,
AbsoluteProgressReporter progress)
Copy from the reader to the writer until end of file is reached. |
static List<File> |
findFiles(File directory,
FileFilter filter)
Find files matching a given filter in a directory. |
static Map<Directory,List<Directory>> |
getDirectoryTree(DbControl dc,
Directory directory)
Get the complete tree of sub-directories from a given directory. |
static InputStream |
getInputStream(File file)
Get a buffered InputStream object reading from
the specified file. |
static OutputStream |
getOutputStream(File file)
Get a buffered OutputStream object writing to
the specified file. |
static Map<Directory,List<Directory>> |
loadMinimalDirectoryTree(DbControl dc,
Directory... directories)
Load a minimal directory tree that includes at least all the specified directories and their parent directories all the way up to the root or as far as the logged in user has read permission. |
static long |
read(InputStream in)
Read from the input stream until the end is reached. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final int BUFFER_SIZE
Constructor Detail |
---|
public FileUtil()
Method Detail |
---|
public static long copy(InputStream in, OutputStream out) throws IOException
in
- The InputStream
to read fromout
- The OutputStream
to write to
IOException
- This exception is thrown if there is an errorpublic static long copy(InputStream in, OutputStream out, AbsoluteProgressReporter progress) throws IOException
in
- The InputStream
to read fromout
- The OutputStream
to write toprogress
- An optional progress reporter
IOException
- This exception is thrown if there is an errorpublic static long copy(Reader in, Writer out) throws IOException
in
- The Reader
to read fromout
- The Writer
to write to
IOException
- This exception is thrown if there is an errorpublic static long copy(Reader in, Writer out, AbsoluteProgressReporter progress) throws IOException
in
- The Reader
to read fromout
- The Writer
to write toprogress
- An optional progress reporter
IOException
- This exception is thrown if there is an errorpublic static long read(InputStream in) throws IOException
in
- The InputStream
to read from
IOException
- This exception is thrown if there is an errorpublic static void close(InputStream in)
in
- The input stream to closepublic static void close(OutputStream out)
out
- The output stream to closepublic static InputStream getInputStream(File file) throws IOException
InputStream
object reading from
the specified file.
file
- The path to the file to read from
InputStream
IOException
- If the stream cannot be openedpublic static OutputStream getOutputStream(File file) throws IOException
OutputStream
object writing to
the specified file.
file
- The path to the file to write to
OutputStream
IOException
- If the stream cannot be openedpublic static boolean checkMagicNumber(PushbackInputStream pin, byte[] bCheck) throws IOException
bCheck = new byte[] { 0x1f, (byte)0x8b };
pin
- The input stream to read from which must have
large enough buffer to be able to unread the bytesbCheck
- The byte values to use for comparison
IOException
- If there is an error reading or unreading
the bytes
NullPointerException
- If pin or bCheck is null
IllegalArgumentException
- If bCheck is zero lengthpublic static Map<Directory,List<Directory>> getDirectoryTree(DbControl dc, Directory directory) throws InvalidDataException, BaseException
NOTE!!! This method has very bad performance on large directory trees.
Consider if it is not possible to use the loadMinimalDirectoryTree(DbControl, Directory...)
instead together with lazy loading of subdirectories.
dc
- DbControl used to access the database.directory
- The directory to start with
Map
which maps a directory to a
list of it's sub-directories. Directories without sub-directories
are not included in the map.
InvalidDataException
- If the directory is null
BaseException
- If there is another errorpublic static Map<Directory,List<Directory>> loadMinimalDirectoryTree(DbControl dc, Directory... directories) throws InvalidDataException, BaseException
dc
- A DbControl for accessing the databasedirectories
- An array of directories
Map
which maps a directory to a
list of it's sub-directories. The map is guaranteed to contain an entry for each of
the given directories, but the list may be empty if there are no subdirectories
BaseException
- If there is an error
InvalidDataException
public static List<File> findFiles(File directory, FileFilter filter)
RegexpFileFilter
to look for files
matching a regular expression.
directory
- The parent directory to search infilter
- A filter which specifies which files to find, or null
to find all files
RegexpFileFilter
|
2.12.0: 2009-05-27 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |