org.tranche.streams
Class WrappedOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by org.tranche.streams.WrappedOutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class WrappedOutputStream
extends java.io.OutputStream

A wrapper class that lets the AddFielTool upload data on-the-fly without requiring temporary files when downloading. This greatly speeds up uploads and significantly reduces disk access times.


Constructor Summary
WrappedOutputStream(java.io.OutputStream out, BigHashMaker bhm)
          Creates a wrapped output stream that will automatically create an appropriate BigHash from the bytes streamed through it.
WrappedOutputStream(java.io.OutputStream out, BigHashMaker bhm, java.lang.String algorithm, java.security.PrivateKey key)
           
 
Method Summary
 void close()
          Closes the wrapped OutputStream.
 void flush()
          Flushes any bytes being buffered.
 byte[] getSignatureBytes()
          Returns the appropriate bytes to represent a signature for this file.
 void write(byte[] b)
          Writes a complete buffer of bytes.
 void write(byte[] buf, int off, int len)
          Writes using a buffer and respecting offset and length.
 void write(int b)
          Writes a single byte out a time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WrappedOutputStream

public WrappedOutputStream(java.io.OutputStream out,
                           BigHashMaker bhm)

Creates a wrapped output stream that will automatically create an appropriate BigHash from the bytes streamed through it.

Parameters:
out - The OutputStream to write bytes to. This wrapper will pass all bytes.
bhm - The BigHashMaker that will be updated as bytes are written to this class.

WrappedOutputStream

public WrappedOutputStream(java.io.OutputStream out,
                           BigHashMaker bhm,
                           java.lang.String algorithm,
                           java.security.PrivateKey key)
Parameters:
out -
bhm -
algorithm -
key -
Method Detail

write

public void write(byte[] buf,
                  int off,
                  int len)
           throws java.io.IOException
Writes using a buffer and respecting offset and length.

Overrides:
write in class java.io.OutputStream
Parameters:
buf -
off -
len -
Throws:
java.io.IOException

write

public void write(byte[] b)
           throws java.io.IOException

Writes a complete buffer of bytes.

Overrides:
write in class java.io.OutputStream
Parameters:
b -
Throws:
java.io.IOException

write

public void write(int b)
           throws java.io.IOException

Writes a single byte out a time. Not recommended for speed.

Specified by:
write in class java.io.OutputStream
Parameters:
b -
Throws:
java.io.IOException

flush

public void flush()
           throws java.io.IOException

Flushes any bytes being buffered. This class doesn't not buffer bytes from the wrapped OutputStream.

Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException

Closes the wrapped OutputStream.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.OutputStream
Throws:
java.io.IOException

getSignatureBytes

public byte[] getSignatureBytes()

Returns the appropriate bytes to represent a signature for this file.

Returns:
The appropriate bytes to represent a signature for this file.


This code is free for use both commercially and non-commercially as stated in the project's license