本文整理汇总了Java中sun.net.www.MessageHeader.set方法的典型用法代码示例。如果您正苦于以下问题:Java MessageHeader.set方法的具体用法?Java MessageHeader.set怎么用?Java MessageHeader.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sun.net.www.MessageHeader
的用法示例。
在下文中一共展示了MessageHeader.set方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: computeEntry
import sun.net.www.MessageHeader; //导入方法依赖的package包/类
/**
* Given a manifest entry, computes the signature entry for this
* manifest entry.
*/
private MessageHeader computeEntry(MessageHeader mh) throws IOException {
MessageHeader smh = new MessageHeader();
String name = mh.findValue("Name");
if (name == null) {
return null;
}
smh.set("Name", name);
try {
for (int i = 0; i < hashes.length; ++i) {
MessageDigest dig = getDigest(hashes[i]);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
mh.print(ps);
byte[] headerBytes = baos.toByteArray();
byte[] digest = dig.digest(headerBytes);
smh.set(hashes[i] + "-Digest", Base64.getMimeEncoder().encodeToString(digest));
}
return smh;
} catch (NoSuchAlgorithmException e) {
throw new JarException(e.getMessage());
}
}
示例2: doHashes
import sun.net.www.MessageHeader; //导入方法依赖的package包/类
public void doHashes(MessageHeader mh) throws IOException {
// If unnamed or is a directory return immediately
String name = mh.findValue("Name");
if (name == null || name.endsWith("/")) {
return;
}
/* compute hashes, write over any other "Hash-Algorithms" (?) */
for (int j = 0; j < hashes.length; ++j) {
InputStream is = new FileInputStream(stdToLocal(name));
try {
MessageDigest dig = MessageDigest.getInstance(hashes[j]);
int len;
while ((len = is.read(tmpbuf, 0, tmpbuf.length)) != -1) {
dig.update(tmpbuf, 0, len);
}
mh.set(hashes[j] + "-Digest", Base64.getMimeEncoder().encodeToString(dig.digest()));
} catch (NoSuchAlgorithmException e) {
throw new JarException("Digest algorithm " + hashes[j] +
" not available.");
} finally {
is.close();
}
}
}
示例3: SignatureFile
import sun.net.www.MessageHeader; //导入方法依赖的package包/类
/**
* Private constructor which takes a name a given signature file
* and a new file predicate. If it is a new file, a main header
* will be added. */
private SignatureFile(String name, boolean newFile)
throws JarException {
this(name);
if (newFile) {
MessageHeader globals = new MessageHeader();
globals.set("Signature-Version", "1.0");
entries.addElement(globals);
}
}