public class DigestInputStream extends FilterInputStream
完成消息摘要计算,调用一个在相关消息摘要digest
方法在你调用这一消化输入流的read
方法。
它可能把这流或关闭(见on
)。当它的时候,打电话给一个在消息摘要更新read
方法结果。但是当它关闭时,消息摘要未被更新。默认的是要在流上的。
请注意,只有一个消化消化的对象可以计算(见MessageDigest
),所以为了计算中间消化,来电者应该保留一个柄上的消化和克隆对象,每个消化来计算的,离开原来的消化不。
MessageDigest
,
DigestOutputStream
Modifier and Type | Field and Description |
---|---|
protected MessageDigest |
digest
与此流关联的消息摘要。
|
in
Constructor and Description |
---|
DigestInputStream(InputStream stream, MessageDigest digest)
创建一个摘要输入流,使用指定的输入流和消息摘要。
|
Modifier and Type | Method and Description |
---|---|
MessageDigest |
getMessageDigest()
返回与此流关联的消息摘要。
|
void |
on(boolean on)
打开或关闭消化功能。
|
int |
read()
读取一个字节,并更新消息摘要(如果摘要函数是在)。
|
int |
read(byte[] b, int off, int len)
读入一个字节数组,并更新消息摘要(如果摘要函数是在)。
|
void |
setMessageDigest(MessageDigest digest)
将指定的消息摘要与此流关联。
|
String |
toString()
打印此摘要输入流及其相关的消息摘要对象的字符串表示形式。
|
available, close, mark, markSupported, read, reset, skip
protected MessageDigest digest
public DigestInputStream(InputStream stream, MessageDigest digest)
stream
-输入流。
digest
的消息摘要与流关联。
public MessageDigest getMessageDigest()
setMessageDigest(java.security.MessageDigest)
public void setMessageDigest(MessageDigest digest)
digest
-消息摘要是本流相关。
getMessageDigest()
public int read() throws IOException
on
),该方法将调用的消息摘要与流相关的
update
,它传递的字节读。
read
方法重写,继承类
FilterInputStream
IOException
如果I/O错误发生。
MessageDigest.update(byte)
public int read(byte[] b, int off, int len) throws IOException
b
到
len
字节偏移,开始
off
。这种方法块,直到数据实际上是读取。如果消化功能是(见
on
),该方法将调用的消息摘要与流相关的
update
,传递数据。
read
方法重写,继承类
FilterInputStream
b
-阵列数据读入的。
off
-起始偏移为
b
数据在哪里应该放。
len
-的最大字节数是从输入流中读取到B,起点偏移
off
。
len
如果到达流的末尾读
len
字节之前。如果没有读取字节,则返回1,因为当调用调用时,流的结束已经到达了。
IOException
如果I/O错误发生。
MessageDigest.update(byte[], int, int)
public void on(boolean on)
read
方法结果。但是当它关闭时,消息摘要未被更新。
on
真把消化功能,虚假的关掉它。
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.