org.freecompany.redline
Class ChannelWrapper

java.lang.Object
  extended by org.freecompany.redline.ChannelWrapper
Direct Known Subclasses:
ReadableChannelWrapper, WritableChannelWrapper

public abstract class ChannelWrapper
extends java.lang.Object

Wraps an IO channel so that bytes may be observed during transmission. Wrappers around IO channels are used for a variety of purposes, including counting byte output for use in generating headers, calculating a signature across output bytes, and digesting output bytes using a one-way secure hash.


Nested Class Summary
protected static interface ChannelWrapper.Consumer<T>
          Interface describing an object that consumes data from a NIO buffer.
static class ChannelWrapper.Key<T>
           
 
Field Summary
protected  java.util.Map<ChannelWrapper.Key<?>,ChannelWrapper.Consumer<?>> consumers
           
 
Constructor Summary
ChannelWrapper()
           
 
Method Summary
 void close()
           
<T> T
finish(ChannelWrapper.Key<T> object)
           
 ChannelWrapper.Key<java.lang.Integer> start()
          Initializes a byte counter on this channel.
 ChannelWrapper.Key<byte[]> start(java.security.PrivateKey key)
          Initialize a signature on this channel.
 ChannelWrapper.Key<byte[]> start(java.lang.String algorithm)
          Initialize a digest on this channel.
 ChannelWrapper.Key<java.lang.Integer> start(java.nio.channels.WritableByteChannel output)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

consumers

protected java.util.Map<ChannelWrapper.Key<?>,ChannelWrapper.Consumer<?>> consumers
Constructor Detail

ChannelWrapper

public ChannelWrapper()
Method Detail

start

public ChannelWrapper.Key<java.lang.Integer> start(java.nio.channels.WritableByteChannel output)

start

public ChannelWrapper.Key<java.lang.Integer> start()
Initializes a byte counter on this channel.


start

public ChannelWrapper.Key<byte[]> start(java.security.PrivateKey key)
                                 throws java.security.NoSuchAlgorithmException,
                                        java.security.InvalidKeyException
Initialize a signature on this channel.

Parameters:
key - the private key to use in signing this data stream.
Throws:
java.security.NoSuchAlgorithmException - if the key algorithm is not supported
java.security.InvalidKeyException - if the key provided is invalid for signing

start

public ChannelWrapper.Key<byte[]> start(java.lang.String algorithm)
                                 throws java.security.NoSuchAlgorithmException
Initialize a digest on this channel.

Parameters:
algorithm - the digest algorithm to use in computing the hash
Throws:
java.security.NoSuchAlgorithmException - if the given algorithm does not exist

finish

public <T> T finish(ChannelWrapper.Key<T> object)

close

public void close()
           throws java.io.IOException
Throws:
java.io.IOException


Copyright © 2011. All Rights Reserved.