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, skipprotected MessageDigest digest
public DigestInputStream(InputStream stream, MessageDigest digest)
stream - 输入流。
digest - 与此流
digest的消息摘要。
public MessageDigest getMessageDigest()
setMessageDigest(java.security.MessageDigest)
public void setMessageDigest(MessageDigest digest)
digest - 要与此流
digest的消息摘要。
getMessageDigest()
public int read()
throws IOException
on ),则此方法将在与此流相关update的消息摘要上调用update ,将其读取字节。
read在类别
FilterInputStream
IOException - 如果发生I / O错误。
MessageDigest.update(byte)
public int read(byte[] b,
int off,
int len)
throws IOException
len个字节到数组b ,从偏移off开始。
该方法阻塞,直到数据被实际读取。
如果摘要功能打开(参见on ),则此方法将调用update与此流相关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 - true打开摘要功能,false将其关闭。
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.