sam.io
Class Mixer

java.lang.Object
  |
  +--sam.io.Mixer
Direct Known Subclasses:
HuffmanMixer, RandomMixer

public abstract class Mixer
extends java.lang.Object

Class for mixing streams with garbage bytes. Mixing consists of


 Mixer mixer = ...;
 OutputStream mixedOutput = mixer.new OutputStream(nativeOutput);
 ...  // Use 'mixedOutput' here
 mixedOutput.close();
 byte[] trace = mixer.getTrace();
 
then unmixing consists of

 byte[] trace = ...
 Mixer mixer = ...
 mixer.setTrace(trace);
 InputStream unmixedInput = mixer.new InputStream(mixedInput);
 ...  // Use 'unmixedInput' here
 


Nested Class Summary
 class Mixer.InputStream
          Inner-class for transparently unmixing an mixed stream
 class Mixer.OutputStream
          Inner-class for transparently mixing a stream The trace is stored back in the outer Mixer instance once the close() method is called
 
Field Summary
static sam.io.Mixer DUMMY
          Dummy mixer implementation.
 
Constructor Summary
Mixer()
           
 
Method Summary
protected  long blockSize()
          Gets the block size of this mixer.
protected abstract  long getDataChunkLength(long blockSize)
          Sets the next data chunk length, in bytes.
 byte[] getTrace()
          Gets the current mixing trace since creation of the stream
 long nextDataChunkLength(long blockSize)
          Sets the next data chunk length, in bytes.
abstract  void readGarbageChunk(java.io.InputStream stream, long length)
          Reads garbage data from the stream.
 void setBlockSize(long blockSize)
          Sets the block size.
 void setTrace(byte[] trace)
          Sets the current mixing trace
 void setTracker(sam.io.Tracker tracker)
          Sets the tracker.
abstract  void writeGarbageChunk(java.io.OutputStream stream)
          Writes garbage data to the stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DUMMY

public static final sam.io.Mixer DUMMY
Dummy mixer implementation. This just does nothgin and serves as an example or for debugging purpose.

Constructor Detail

Mixer

public Mixer()
Method Detail

getDataChunkLength

protected abstract long getDataChunkLength(long blockSize)
Sets the next data chunk length, in bytes.

Parameters:
blockSize - the block size of the data stream, which might be zero to specify infinite block size A lazy implementation might just return blockSize
Returns:
desired data chunk length, or zero to specify unlimited data chunk

nextDataChunkLength

public long nextDataChunkLength(long blockSize)
Sets the next data chunk length, in bytes.

Parameters:
blockSize - the block size of the data stream, which might be zero to specify infinite block size A lazy implementation might just return blockSize
Returns:
desired data chunk length, or the maximum positive long to specify unlimited data chunk

writeGarbageChunk

public abstract void writeGarbageChunk(java.io.OutputStream stream)
                                throws java.io.IOException
Writes garbage data to the stream.

Parameters:
stream - the output to write onto Note that the number of bytes written will be kept back automatically
java.io.IOException

readGarbageChunk

public abstract void readGarbageChunk(java.io.InputStream stream,
                                      long length)
                               throws java.io.IOException
Reads garbage data from the stream.

Parameters:
stream - the input to write onto
length - the number of garbage bytes to read
java.io.IOException

blockSize

protected long blockSize()
Gets the block size of this mixer.


setBlockSize

public void setBlockSize(long blockSize)
Sets the block size.


setTracker

public void setTracker(sam.io.Tracker tracker)
Sets the tracker.


getTrace

public byte[] getTrace()
Gets the current mixing trace since creation of the stream


setTrace

public void setTrace(byte[] trace)
Sets the current mixing trace