javax.crypto

Class CipherInputStream

Implemented Interfaces:
AutoCloseable, 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

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.io.FilterInputStream

available, close, mark, markSupported, read, read, read, reset, skip

Methods inherited from class java.io.InputStream

available, close, mark, markSupported, read, read, read, reset, skip

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

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.

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.

Method Details

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 interface 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
close in interface AutoCloseable
Overrides:
close in interface FilterInputStream
Throws:
IOException - If an I/O exception occurs.

mark

public void mark(int mark)
Set the mark. This method is unsupported and is empty.
Overrides:
mark in interface FilterInputStream
Parameters:
mark - Is ignored.

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 interface FilterInputStream
Returns:
false

read

public int read()
            throws IOException
Read a single byte from this input stream; returns -1 on the end-of-file.
Overrides:
read in interface FilterInputStream
Returns:
The byte read, or -1 if there are no more bytes.

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

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

reset

public void reset()
            throws IOException
Reset to the mark. This method is unsupported and is empty.
Overrides:
reset in interface FilterInputStream

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 interface FilterInputStream
Parameters:
bytes - The number of bytes to skip.
Returns:
The number of bytes skipped.

CipherInputStream.java -- Filters input through a cipher. Copyright (C) 2004 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.