javax.crypto

Class CipherInputStream

public class CipherInputStream extends FilterInputStream

This is an {@link java.io.InputStream} that filters its data through a {@link Cipher} before returning it. The Cipher argument must have been initialized before it is passed to the constructor.
Constructor Summary
CipherInputStream(InputStream in, Cipher cipher)
Creates a new input stream with a source input stream and cipher.
protected CipherInputStream(InputStream in)
Creates a new input stream without a cipher.
Method Summary
intavailable()
Returns the number of bytes available without blocking.
voidclose()
Close this input stream.
voidmark(int mark)
Set the mark.
booleanmarkSupported()
Returns whether or not this input stream supports the {@link #mark(long)} and {@link #reset()} methods; this input stream does not, however, and invariably returns false.
intread()
Read a single byte from this input stream; returns -1 on the end-of-file.
intread(byte[] buf, int off, int len)
Read bytes into an array, returning the number of bytes read or -1 on the end-of-file.
intread(byte[] buf)
Read bytes into an array, returning the number of bytes read or -1 on the end-of-file.
voidreset()
Reset to the mark.
longskip(long bytes)
Skip a number of bytes.

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()
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.

Returns: The number of bytes immediately available.

Throws: java.io.IOException If an I/O exception occurs.

close

public void close()
Close this input stream. This method merely calls the {@link java.io.InputStream#close()} method of the underlying input stream.

Throws: java.io.IOException If an I/O exception occurs.

mark

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

Parameters: mark Is ignored.

markSupported

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

Returns: false

read

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

Returns: The byte read, or -1 if there are no more bytes.

Throws: java.io.IOExcpetion If an I/O exception occurs.

read

public 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.

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: java.io.IOException If an I/O exception occurs.

read

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

Parameters: buf The byte arry to read into.

Returns: The number of bytes read, or -1 on the end-of-file.

Throws: java.io.IOException If an I/O exception occurs.

reset

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

skip

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

Parameters: bytes The number of bytes to skip.

Returns: The number of bytes skipped.