javax.crypto
Class CipherInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by javax.crypto.CipherInputStream
All Implemented Interfaces:
Closeable

public class CipherInputStream
extends FilterInputStream

This is an InputStream that filters its data through a Cipher before returning it. The Cipher argument must have been initialized before it is passed to the constructor.


Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
protected CipherInputStream(InputStream in)
          Creates a new input stream without a cipher.
  CipherInputStream(InputStream in, Cipher cipher)
          Creates a new input stream with a source input stream and cipher.
 
Method Summary
 int available()
          Returns the number of bytes available without blocking.
 void close()
          Close this input stream.
 void mark(int mark)
          Set the mark.
 boolean markSupported()
          Returns whether or not this input stream supports the #mark(long) and reset() methods; this input stream does not, however, and invariably returns false.
 int read()
          Read a single byte from this input stream; returns -1 on the end-of-file.
 int read(byte[] buf)
          Read bytes into an array, returning the number of bytes read or -1 on the end-of-file.
 int read(byte[] buf, int off, int len)
          Read bytes into an array, returning the number of bytes read or -1 on the end-of-file.
 void reset()
          Reset to the mark.
 long skip(long bytes)
          Skip a number of bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CipherInputStream

public CipherInputStream(InputStream in,
                         Cipher cipher)
Creates a new input stream with a source input stream and cipher.

Parameters:
in - The underlying input stream.
cipher - The cipher to filter data through.

CipherInputStream

protected CipherInputStream(InputStream in)
Creates a new input stream without a cipher. This constructor is protected because this class does not work without an underlying cipher.

Parameters:
in - The underlying input stream.
Method Detail

available

public int available()
              throws IOException
Returns the number of bytes available without blocking. The value returned is the number of bytes that have been processed by the cipher, and which are currently buffered by this class.

Overrides:
available in class FilterInputStream
Returns:
The number of bytes immediately available.
Throws:
IOException - If an I/O exception occurs.

close

public void close()
           throws IOException
Close this input stream. This method merely calls the InputStream.close() method of the underlying input stream.

Specified by:
close in interface Closeable
Overrides:
close in class FilterInputStream
Throws:
IOException - If an I/O exception occurs.

read

public int read()
         throws IOException
Read a single byte from this input stream; returns -1 on the end-of-file.

Overrides:
read in class FilterInputStream
Returns:
The byte read, or -1 if there are no more bytes.
Throws:
java.io.IOExcpetion - If an I/O exception occurs.
IOException - If an error occurs

read

public int read(byte[] buf,
                int off,
                int len)
         throws IOException
Read bytes into an array, returning the number of bytes read or -1 on the end-of-file.

Overrides:
read in class FilterInputStream
Parameters:
buf - The byte array to read into.
off - The offset in buf to start.
len - The maximum number of bytes to read.
Returns:
The number of bytes read, or -1 on the end-of-file.
Throws:
IOException - If an I/O exception occurs.

read

public int read(byte[] buf)
         throws IOException
Read bytes into an array, returning the number of bytes read or -1 on the end-of-file.

Overrides:
read in class FilterInputStream
Parameters:
buf - The byte arry to read into.
Returns:
The number of bytes read, or -1 on the end-of-file.
Throws:
IOException - If an I/O exception occurs.

skip

public long skip(long bytes)
          throws IOException
Skip a number of bytes. This class only supports skipping as many bytes as are returned by available(), which is the number of transformed bytes currently in this class's internal buffer.

Overrides:
skip in class FilterInputStream
Parameters:
bytes - The number of bytes to skip.
Returns:
The number of bytes skipped.
Throws:
IOException - If an error occurs

markSupported

public boolean markSupported()
Returns whether or not this input stream supports the #mark(long) and reset() methods; this input stream does not, however, and invariably returns false.

Overrides:
markSupported in class FilterInputStream
Returns:
false

mark

public void mark(int mark)
Set the mark. This method is unsupported and is empty.

Overrides:
mark in class FilterInputStream
Parameters:
mark - Is ignored.

reset

public void reset()
           throws IOException
Reset to the mark. This method is unsupported and is empty.

Overrides:
reset in class FilterInputStream
Throws:
IOException - If an error occurs