ccs.crypt
Class CipherInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by ccs.crypt.CipherInputStream
All Implemented Interfaces:
java.io.Closeable
Direct Known Subclasses:
AbstractBlockCipherInputStream

public abstract class CipherInputStream
extends java.io.FilterInputStream

The base class for input streams returned by Cipher subclasses. A CipherInputStream reads an underlying stream of Ciphertext and provides plaintext.


Field Summary
protected  boolean isDelimit
          Whether this stream is self-delimiting.
protected  byte[] temp8
          An 8-byte scratch space.
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
protected CipherInputStream(java.io.InputStream is, boolean isDelimit)
          Creates a new CipherInputStream based on the supplied underlying stream.
 
Method Summary
 int available()
          Returns the number of bytes that can be read from the underlying input stream without blocking.
 void close()
          Finishes with this decryption, releases the decryption engine and closes the underlying stream.
abstract  void finish()
          Finishes with this decryption and releases the decryption engine, but does not close the underlying stream.
 void mark(int readlimit)
          Does nothing: mark / reset is not supported.
 boolean markSupported()
          Indicates whether this input stream supports the mark and reset methods, which it does not.
 int read()
          Returns the next byte of plaintext as an int in the range 0 - 255, or -1 if the stream is exhausted.
 int read(byte[] b)
          Reads up to b.length bytes into b.
abstract  int read(byte[] b, int off, int len)
          Reads up to len bytes of plaintext into b[], starting at off.
 void reset()
          Does nothing: mark / reset is not supported.
 long skip(long n)
          Skips over and discards n bytes of data from this input stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

temp8

protected byte[] temp8
An 8-byte scratch space. Useful for a) buffering single-byte reads; b) working with packed longs.

See Also:
Unsigned.writePacked(java.io.OutputStream, long, byte[])

isDelimit

protected boolean isDelimit
Whether this stream is self-delimiting.

Constructor Detail

CipherInputStream

protected CipherInputStream(java.io.InputStream is,
                            boolean isDelimit)
Creates a new CipherInputStream based on the supplied underlying stream. Use the getInputStream() method of a Cipher to obatain a CipherInputStream. NB. This ctor does not set the dam. Recommended strategy: on first read (set a flag to detect this) set the dam to the correct ciphertext length (if delimited), then write away.

Parameters:
is - The underlying (ciphertext) stream
Method Detail

read

public int read()
         throws java.io.IOException
Returns the next byte of plaintext as an int in the range 0 - 255, or -1 if the stream is exhausted. Blocks until the datum is made available.

Overrides:
read in class java.io.FilterInputStream
Returns:
The byte.
Throws:
java.io.IOException - if an error occurs.

read

public abstract int read(byte[] b,
                         int off,
                         int len)
                  throws java.io.IOException
Reads up to len bytes of plaintext into b[], starting at off. Blocks until some input is available.

Overrides:
read in class java.io.FilterInputStream
Parameters:
b - The buffer to read into. Cannot be null.
off - The starting offset.
len - The maximum number of bytes to read.
Returns:
the total number of byes read, or -1 if the stream is exhausted.
Throws:
java.io.IOException - if an I/O error occurs.

read

public int read(byte[] b)
         throws java.io.IOException
Reads up to b.length bytes into b. Exactly equivalent to read(b, 0, b.length).

Overrides:
read in class java.io.FilterInputStream
Parameters:
b - The buffer to read into. Cannot be null.
Returns:
the total number of byes read, or -1 if the stream is exhausted.
Throws:
java.io.IOException - if an I/O error occurs.

skip

public long skip(long n)
          throws java.io.IOException
Skips over and discards n bytes of data from this input stream. Unlike its superclass, this method is guaranteed to skip the number of bytes requested unless the stream comes up short.

Overrides:
skip in class java.io.FilterInputStream
Parameters:
n - The number of bytes to be skipped.
Returns:
The actual number of bytes skipped.
Throws:
java.io.IOException - if an I/O error occurs.

available

public int available()
              throws java.io.IOException
Returns the number of bytes that can be read from the underlying input stream without blocking. This is generally not much of a guide to anything and shouldn't be relied upon.

Overrides:
available in class java.io.FilterInputStream
Returns:
The number of bytes that can be read from the underlying input stream without blocking, maybe. If you're lucky.
Throws:
java.io.IOException - If an I/O error occurs.

finish

public abstract void finish()
                     throws java.io.IOException
Finishes with this decryption and releases the decryption engine, but does not close the underlying stream.

Throws:
java.io.IOException - if an error occurs.

close

public void close()
           throws java.io.IOException
Finishes with this decryption, releases the decryption engine and closes the underlying stream.

Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.FilterInputStream
Throws:
java.io.IOException - if an error occurs.

mark

public void mark(int readlimit)
Does nothing: mark / reset is not supported.

Overrides:
mark in class java.io.FilterInputStream
Parameters:
readlimit - Ignored.

reset

public void reset()
Does nothing: mark / reset is not supported.

Overrides:
reset in class java.io.FilterInputStream

markSupported

public boolean markSupported()
Indicates whether this input stream supports the mark and reset methods, which it does not.

Overrides:
markSupported in class java.io.FilterInputStream
Returns:
false - mark/reset isn't supported.