public class CipherInputStream
extends FilterInputStream
| java.lang.Object | |||
| java.io.InputStream | |||
| java.io.FilterInputStream | |||
| javax.crypto.CipherInputStream | |||
CipherInputStream由InputStream和Cipher组成,以便read()方法返回从底层InputStream读入但由Cipher额外处理的数据。 密码必须在被CipherInputStream使用之前完全初始化。
例如,如果Cipher初始化为解密,则CipherInputStream将尝试读取数据并解密它们,然后再返回解密的数据。
该类严格遵守其祖先类java.io.FilterInputStream和java.io.InputStream的语义,特别是失败语义。 该类完全具有在其祖先类中指定的方法,并覆盖它们全部。 而且,这个类捕获所有祖先类不抛出的异常。 特别是, skip方法会跳过,并且available方法只计算已被封装密码处理的数据。
使用这个类的程序员不要使用未在此类中定义或重写的方法(例如稍后将其添加到其中一个超类中的新方法或构造函数),这是非常重要的,因为这些方法的设计和实现不太可能考虑对CipherInputStream的安全影响。
Inherited fields |
|---|
java.io.FilterInputStream
|
Public constructors |
|
|---|---|
CipherInputStream(InputStream is, Cipher c) 从InputStream和Cipher构造一个CipherInputStream。 |
|
Protected constructors |
|
|---|---|
CipherInputStream(InputStream is) 从InputStream构造一个CipherInputStream而不指定密码。 |
|
公共方法(Public methods) |
|
|---|---|
int |
available() 返回可以从该输入流中读取而不被阻塞的字节数。 |
void |
close() 关闭此输入流并释放与该流关联的所有系统资源。 |
boolean |
markSupported() 测试此输入流是否支持 |
int |
read() 从此输入流中读取下一个字节的数据。 |
int |
read(byte[] b, int off, int len) 从这个输入流中读取多达 |
int |
read(byte[] b) 从这个输入流中读取多达 |
long |
skip(long n) 跳过 |
继承方法(Inherited methods) |
|
|---|---|
java.io.FilterInputStream
|
|
java.io.InputStream
|
|
java.lang.Object
|
|
java.io.Closeable
|
|
java.lang.AutoCloseable
|
|
CipherInputStream (InputStream is, Cipher c)
从InputStream和Cipher构造一个CipherInputStream。
注意:如果指定的输入流或密码为空,则NullPointerException在稍后使用时可能会被抛出。
| 参数(Parameters) | |
|---|---|
is |
InputStream: the to-be-processed input stream |
c |
Cipher: an initialized Cipher object |
CipherInputStream (InputStream is)
从InputStream构造一个CipherInputStream而不指定密码。 这具有使用NullCipher构造CipherInputStream的效果。
注意:如果指定的输入流为空,则在使用NullPointerException时可能会稍后抛出它。
| 参数(Parameters) | |
|---|---|
is |
InputStream: the to-be-processed input stream |
int available ()
返回可以从该输入流中读取而不被阻塞的字节数。 该available方法InputStream回报0 。 这个方法应该被子类覆盖。
| 返回(Returns) | |
|---|---|
int |
the number of bytes that can be read from this input stream without blocking. |
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs. |
void close ()
关闭此输入流并释放与该流关联的所有系统资源。
close方法 CipherInputStream调用其基础输入流的 close方法。
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs. |
boolean markSupported ()
测试此输入流是否支持 mark和 reset方法,但不支持。
| 返回(Returns) | |
|---|---|
boolean |
false, since this class does not support the mark and reset methods. |
int read ()
从此输入流中读取下一个字节的数据。 值字节被返回作为int范围0到255 。 如果由于已到达流的末尾而没有可用的字节,则返回值-1 。 此方法阻塞直到输入数据可用,流的末尾被检测到,或抛出异常。
| 返回(Returns) | |
|---|---|
int |
the next byte of data, or -1 if the end of the stream is reached. |
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs. |
int read (byte[] b,
int off,
int len)
从该输入流中读取多达len个字节的数据到一个字节数组中。 此方法阻塞,直到有些输入可用。 如果第一个参数是null,最多可读取并丢弃len个字节。
| 参数(Parameters) | |
|---|---|
b |
byte: the buffer into which the data is read. |
off |
int: the start offset in the destination array buf |
len |
int: the maximum number of bytes read. |
| 返回(Returns) | |
|---|---|
int |
the total number of bytes read into the buffer, or -1 if there is no more data because the end of the stream has been reached. |
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs. |
也可以看看:
int read (byte[] b)
从这个输入流中最多读取 b.length个字节的数据到一个字节数组中。
该 read的方法 InputStream调用 read的三个参数方法与参数 b , 0 ,并 b.length 。
| 参数(Parameters) | |
|---|---|
b |
byte: the buffer into which the data is read. |
| 返回(Returns) | |
|---|---|
int |
the total number of bytes read into the buffer, or -1 is there is no more data because the end of the stream has been reached. |
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs. |
也可以看看:
long skip (long n)
跳过 n字节的输入字节,可以从该输入流中读取而不受阻塞。
可能会跳过比请求更少的字节。 实际跳过的字节数等于n或调用的结果,以较小者为准。 如果availablen小于零,则不跳过字节。
返回跳过的实际字节数。
| 参数(Parameters) | |
|---|---|
n |
long: the number of bytes to be skipped. |
| 返回(Returns) | |
|---|---|
long |
the actual number of bytes skipped. |
| 抛出异常(Throws) | |
|---|---|
IOException |
if an I/O error occurs. |