Last update: 2011-06-23

org.proteios.util
Class FileUtil

java.lang.Object
  extended by org.proteios.util.FileUtil

public class FileUtil
extends Object

This class collects some useful methods for file and stream handling.

Version:
2.0
Author:
Nicklas
Last modified
$Date: 2009-11-06 12:30:35 +0100 (Fri, 06 Nov 2009) $

Constructor Summary
FileUtil()
           
 
Method Summary
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 Map<Directory,List<Directory>> getDirectoryTree(DbControl dc, Directory directory)
          Get the complete tree of subdirectories 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileUtil

public FileUtil()
Method Detail

copy

public static long copy(InputStream in,
                        OutputStream out)
                 throws IOException
Copy from the input stream to the output stream until end of file is reached.

Parameters:
in - InputStream The InputStream to read from.
out - OutputStream The OutputStream to write to.
Returns:
long The number of bytes copied.
Throws:
IOException - This exception is thrown if there is an error

copy

public static long copy(InputStream in,
                        OutputStream out,
                        AbsoluteProgressReporter progress)
                 throws IOException
Copy from the input stream to the output stream until end of file is reached.

Parameters:
in - InputStream The InputStream to read from.
out - OutputStream The OutputStream to write to.
progress - AbsoluteProgressReporter An optional progress reporter.
Returns:
long The number of bytes copied.
Throws:
IOException - This exception is thrown if there is an error

getInputStream

public static InputStream getInputStream(File file)
                                  throws IOException
Get a buffered InputStream object reading from the specified file.

Parameters:
file - The path to the file to read from
Returns:
A buffered InputStream
Throws:
IOException - If the stream cannot be opened

getOutputStream

public static OutputStream getOutputStream(File file)
                                    throws IOException
Get a buffered OutputStream object writing to the specified file.

Parameters:
file - The path to the file to write to
Returns:
A buffered OutputStream
Throws:
IOException - If the stream cannot be opened

getDirectoryTree

public static Map<Directory,List<Directory>> getDirectoryTree(DbControl dc,
                                                              Directory directory)
                                                       throws InvalidDataException,
                                                              BaseException
Get the complete tree of subdirectories from a given directory.

Parameters:
directory - The directory to start with
Returns:
A Map which maps a directory to a list of it's subdirectories. Directories without subdirectories are not included in the map.
Throws:
InvalidDataException - If the directory is null
BaseException - If there is another error

Last update: 2011-06-23