Example usage for java.util.jar Attributes Attributes

List of usage examples for java.util.jar Attributes Attributes

Introduction

In this page you can find the example usage for java.util.jar Attributes Attributes.

Prototype

public Attributes() 

Source Link

Document

Constructs a new, empty Attributes object with default size.

Usage

From source file:pxb.android.tinysign.TinySign.java

private static void doFile(String name, File f, ZipOutputStream zos, DigestOutputStream dos, Manifest m)
        throws IOException {
    zos.putNextEntry(new ZipEntry(name));
    FileInputStream fis = FileUtils.openInputStream(f);
    IOUtils.copy(fis, dos);//from  w w w.j a v a  2s  .  com
    IOUtils.closeQuietly(fis);
    byte[] digets = dos.getMessageDigest().digest();
    zos.closeEntry();
    Attributes attr = new Attributes();
    attr.putValue("SHA1-Digest", eBase64(digets));
    m.getEntries().put(name, attr);
}

From source file:pxb.android.tinysign.TinySign.java

private static Manifest generateSF(Manifest manifest)
        throws NoSuchAlgorithmException, UnsupportedEncodingException {
    MessageDigest md = MessageDigest.getInstance("SHA1");
    PrintStream print = new PrintStream(new DigestOutputStream(new OutputStream() {

        @Override//from w ww  . j  a  v  a 2s .c o m
        public void write(byte[] arg0) throws IOException {
        }

        @Override
        public void write(byte[] arg0, int arg1, int arg2) throws IOException {
        }

        @Override
        public void write(int arg0) throws IOException {
        }
    }, md), true, "UTF-8");
    Manifest sf = new Manifest();
    Map<String, Attributes> entries = manifest.getEntries();
    for (Map.Entry<String, Attributes> entry : entries.entrySet()) {
        // Digest of the manifest stanza for this entry.
        print.print("Name: " + entry.getKey() + "\r\n");
        for (Map.Entry<Object, Object> att : entry.getValue().entrySet()) {
            print.print(att.getKey() + ": " + att.getValue() + "\r\n");
        }
        print.print("\r\n");
        print.flush();

        Attributes sfAttr = new Attributes();
        sfAttr.putValue("SHA1-Digest", eBase64(md.digest()));
        sf.getEntries().put(entry.getKey(), sfAttr);
    }
    return sf;
}