it.jnrpe.utils
Class StreamManager

java.lang.Object
  extended by it.jnrpe.utils.StreamManager

public final class StreamManager
extends Object

Utility class for handling streams.

Author:
Massimiliano Ziccardi

Constructor Summary
StreamManager()
          Default constructor.
 
Method Summary
 void closeAll()
          Closes all handles streams and readers.
 InputStream getInputStream(File f)
          Returns an InputStream on the given file.
 OutputStream getOutputStream(File f)
          Returns an OutputStream on the given file.
 InputStream handle(InputStream in)
          Handles the received InputStream and returns it.
 OutputStream handle(OutputStream out)
          Handles the received OutputStream and returns it.
 Reader handle(Reader r)
          Handles the received Reader and returns it.
 Writer handle(Writer w)
          Handles the received Writer and returns it.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamManager

public StreamManager()
Default constructor.

Method Detail

handle

public InputStream handle(InputStream in)
Handles the received InputStream and returns it.

Parameters:
in - The stream to be automatically closed when closeAll() is called.
Returns:
The passed in stream.

handle

public OutputStream handle(OutputStream out)
Handles the received OutputStream and returns it.

Parameters:
out - The stream to be automatically closed when closeAll() is called.
Returns:
The passed in stream.

handle

public Reader handle(Reader r)
Handles the received Reader and returns it.

Parameters:
r - The reader to be automatically closed when closeAll() is called.
Returns:
The passed in reader.

handle

public Writer handle(Writer w)
Handles the received Writer and returns it.

Parameters:
w - The writer to be automatically closed when closeAll() is called.
Returns:
The passed in writer.

getInputStream

public InputStream getInputStream(File f)
                           throws FileNotFoundException
Returns an InputStream on the given file.

Parameters:
f - The file attached to the returned stream to be automatically closed when closeAll() is called.
Returns:
The stream to the passed in file
Throws:
FileNotFoundException - If the file does not exists

getOutputStream

public OutputStream getOutputStream(File f)
                             throws FileNotFoundException
Returns an OutputStream on the given file.

Parameters:
f - The file attached to the returned stream to be automatically closed when closeAll() is called.
Returns:
The stream to the passed in file
Throws:
FileNotFoundException - If the file does not exists

closeAll

public void closeAll()
Closes all handles streams and readers. Non exception is thrown. This. method should be called in the finally block.



Copyright © 2014. All Rights Reserved.