iaik.utils
Class StreamCopier

java.lang.Object
  |
  +--iaik.utils.StreamCopier
All Implemented Interfaces:
Runnable

public class StreamCopier
extends Object
implements Runnable

This utility class copies all data from an InputStream to an OutputStream.

Version:
File Revision 15

Constructor Summary
StreamCopier(InputStream inStream, boolean closeIn, OutputStream outStream, boolean closeOut)
          Creates a StreamCopier that reads from inStream and writes to outStream.
StreamCopier(InputStream inStream, OutputStream outStream)
          Creates a StreamCopier that reads from inStream and writes to outStream.
 
Method Summary
 void copyStream()
          Start the copying.
 IOException getException()
          Get the IOException that occured during copying (if any).
 boolean isActive()
          Check whether the copier is already finished.
 void run()
          Run method to allow the StreamCopier to be run in a separate Thread easily.
 void setCloseIn(boolean closeIn)
          Set whether the InputStream shall be closed after copying.
 void setCloseOut(boolean closeOut)
          Set whether the OutputStream shall be closed after copying.
 void waitFinished()
          Wait for the StreamCopier to finish.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamCopier

public StreamCopier(InputStream inStream,
                    OutputStream outStream)
Creates a StreamCopier that reads from inStream and writes to outStream. The streams are not closed after copying.

StreamCopier

public StreamCopier(InputStream inStream,
                    boolean closeIn,
                    OutputStream outStream,
                    boolean closeOut)
Creates a StreamCopier that reads from inStream and writes to outStream. The closeIn and closeOut parameters indicate if the streams are to be closed after copying.
Method Detail

setCloseIn

public void setCloseIn(boolean closeIn)
Set whether the InputStream shall be closed after copying.

setCloseOut

public void setCloseOut(boolean closeOut)
Set whether the OutputStream shall be closed after copying.

isActive

public boolean isActive()
Check whether the copier is already finished. This will return true until the stream has been completely copied.

copyStream

public void copyStream()
                throws IOException
Start the copying. This method will read data from the InputStream and write it to the OutputStream until the end of the InputStream (read() returns -1) or until an Exception occurs. If an IOException occurs, this method will still continue and close the stream, etc., but the Exception will be remembered and thrown at the end of the method (only EOFExceptions are not thrown, as they may occur in normal operations). If a Thread is waiting for the copy to finish (see waitFinished()) it will be awaken when copying is done.

waitFinished

public void waitFinished()
Wait for the StreamCopier to finish. If the StreamCopier is running in a separate Thread, you can use this method to wait until the StreamCopier is finished. The current Thread will be suspended for the meantime. If the copier is no longer active, this method will return immediately.

run

public void run()
Run method to allow the StreamCopier to be run in a separate Thread easily. This method just calls copyStream() and ignores Exceptions.
Specified by:
run in interface Runnable

getException

public IOException getException()
Get the IOException that occured during copying (if any). If no exception occured, we return null. This will always only return the first exception that occured, if more than one occured the further ones will be lost.

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK