jut.io
Class Streams

java.lang.Object
  extended by jut.io.Streams

public final class Streams
extends Object

static stream utility methods.


Method Summary
static InputStream input(File file)
          opens a buffered input stream for a file. if the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a FileNotFoundException is thrown.
static OutputStream output(File file)
          opens a buffered output stream for a file. if the named file does cannot be opened for writing a FileNotFoundException is thrown.
static int read(InputStream stream, byte[] buffer)
          fill a byte buffer from an input stream. this method will fill the whole buffer unless the end of stream is reached first.
static int read(InputStream stream, byte[] buffer, int off)
          fill a byte buffer from an input stream. this method will fill the whole buffer unless the end of stream is reached first.
static void setInput(ParamCallable<InputStream,File> inputHandler)
          globally set the method for creating buffered InputStreams used by input(File) . by setting a suitable method, e.g. an input speed limit can be implemented.
static void setOutput(ParamCallable<OutputStream,File> outputHandler)
          globally set the method for creating buffered OutputStreams used by output(File). by setting a suitable method, e.g. an output speed limit can be implemented.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

input

public static InputStream input(File file)
                         throws FileNotFoundException
opens a buffered input stream for a file. if the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a FileNotFoundException is thrown.

if this method is used consequently, it can be used e.g. to implement an input speed limit.

Parameters:
file - - the file to open an input stream for.
Returns:
a buffered input stream for a file. if the named file does not exist, is a directory rather than a regular file, or for some other reason cannot be opened for reading then a FileNotFoundException is thrown.
Throws:
FileNotFoundException - if the file cannot be opened for reading.

output

public static OutputStream output(File file)
                           throws FileNotFoundException
opens a buffered output stream for a file. if the named file does cannot be opened for writing a FileNotFoundException is thrown.

if this method is used consequently, it can be used e.g. to implement an output speed limit.

Parameters:
file - - the file to open an output stream for.
Returns:
a buffered output stream for a file. if the named file does cannot be opened for writing a FileNotFoundException is thrown.
Throws:
FileNotFoundException - if the file cannot be opened for writing.

setInput

public static void setInput(ParamCallable<InputStream,File> inputHandler)
globally set the method for creating buffered InputStreams used by input(File) . by setting a suitable method, e.g. an input speed limit can be implemented.

Parameters:
inputHandler - - the method to use by input(File) for creating InputStreams.

setOutput

public static void setOutput(ParamCallable<OutputStream,File> outputHandler)
globally set the method for creating buffered OutputStreams used by output(File). by setting a suitable method, e.g. an output speed limit can be implemented.

Parameters:
outputHandler - - the method to use by output(File) for creating OutputStreams.

read

public static int read(InputStream stream,
                       byte[] buffer)
                throws IOException
fill a byte buffer from an input stream. this method will fill the whole buffer unless the end of stream is reached first.

Parameters:
stream - - the input stream to read from.
buffer - - the byte buffer to fill.
Returns:
the actual number of bytes read.
Throws:
IOException - if the input stream has been closed, or if some other I/O error occurs.

read

public static int read(InputStream stream,
                       byte[] buffer,
                       int off)
                throws IOException
fill a byte buffer from an input stream. this method will fill the whole buffer unless the end of stream is reached first.

Parameters:
stream - - the input stream to read from.
buffer - - the byte buffer to fill.
off - - the offset where to start in the buffer.
Returns:
the actual number of bytes read.
Throws:
IOException - if the input stream has been closed, or if some other I/O error occurs.