org.freecompany.redline
Class ChannelWrapper

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

public abstract class ChannelWrapper
extends 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  Map<ChannelWrapper.Key<?>,ChannelWrapper.Consumer<?>> consumers
           
 
Constructor Summary
ChannelWrapper()
           
 
Method Summary
 void close()
           
<T> T
finish(ChannelWrapper.Key<T> object)
           
 ChannelWrapper.Key<Integer> start()
          Initializes a byte counter on this channel.
 ChannelWrapper.Key<byte[]> start(org.bouncycastle.openpgp.PGPPrivateKey key, int algorithm)
          Initialize a PGP signatue on the channel
 ChannelWrapper.Key<byte[]> start(PrivateKey key)
          Initialize a signature on this channel.
 ChannelWrapper.Key<byte[]> start(String algorithm)
          Initialize a digest on this channel.
 ChannelWrapper.Key<Integer> start(WritableByteChannel output)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

consumers

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

ChannelWrapper

public ChannelWrapper()
Method Detail

start

public ChannelWrapper.Key<Integer> start(WritableByteChannel output)

start

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


start

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

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

start

public ChannelWrapper.Key<byte[]> start(org.bouncycastle.openpgp.PGPPrivateKey key,
                                        int algorithm)
Initialize a PGP signatue on the channel

Parameters:
key - the private key to use in signing this data stream.
algorithm - the algorithm to use. Can be extracted from public key.
Throws:
org.bouncycastle.openpgp.PGPException - if something with PGP got wrong

start

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

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

finish

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

close

public void close()
           throws IOException
Throws:
IOException


Copyright © 2014. All Rights Reserved.