Examples of MessageHeader


Examples of sun.net.www.MessageHeader

    }

    public void addFile(File f) throws IOException {
        String stdName = localToStd(f.getPath());
        if (tableEntries.get(stdName) == null) {
            MessageHeader mh = new MessageHeader();
            mh.add("Name", stdName);
            addEntry(mh);
        }
    }
View Full Code Here

Examples of sun.net.www.MessageHeader

        }

        /* the first header in the file should be the global one.
         * It should say "Manifest-Version: x.x"; if not add it
         */
        MessageHeader globals = (MessageHeader) entries.elementAt(0);

        if (globals.findValue("Manifest-Version") == null) {
            /* Assume this is a user-defined manifest.  If it has a Name: <..>
             * field, then it is not global, in which case we just add our own
             * global Manifest-version: <version>
             * If the first MessageHeader has no Name: <..>, we assume it
             * is a global header and so prepend Manifest to it.
             */
            String jdkVersion = System.getProperty("java.version");

            if (globals.findValue("Name") == null) {
                globals.prepend("Manifest-Version", VERSION);
                globals.add("Created-By", "Manifest JDK "+jdkVersion);
            } else {
                ps.print("Manifest-Version: "+VERSION+"\r\n"+
                         "Created-By: "+jdkVersion+"\r\n\r\n");
            }
            ps.flush();
        }

        globals.print(ps);

        for (int i = 1; i < entries.size(); ++i) {
            MessageHeader mh = (MessageHeader) entries.elementAt(i);
            mh.print(ps);
        }
    }
View Full Code Here

Examples of sun.net.www.MessageHeader

    throws JarException {

        this(name);

        if (newFile) {
            MessageHeader globals = new MessageHeader();
            globals.set("Signature-Version", "1.0");
            entries.addElement(globals);
        }
    }
View Full Code Here

Examples of sun.net.www.MessageHeader

        this(name, true);

        this.manifest = manifest;
        Enumeration enum_ = manifest.entries();
        while (enum_.hasMoreElements()) {
            MessageHeader mh = (MessageHeader)enum_.nextElement();
            String entryName = mh.findValue("Name");
            if (entryName != null) {
                add(entryName);
            }
        }
    }
View Full Code Here

Examples of sun.net.www.MessageHeader

     */
    public SignatureFile(InputStream is, String filename)
    throws IOException {
        this(filename);
        while (is.available() > 0) {
            MessageHeader m = new MessageHeader(is);
            entries.addElement(m);
        }
    }
View Full Code Here

Examples of sun.net.www.MessageHeader

    /**
     * Add a specific entry from the current manifest.
     */
    public void add(String entry) throws JarException {
        MessageHeader mh = manifest.getEntry(entry);
        if (mh == null) {
            throw new JarException("entry " + entry + " not in manifest");
        }
        MessageHeader smh;
        try {
            smh = computeEntry(mh);
        } catch (IOException e) {
            throw new JarException(e.getMessage());
        }
View Full Code Here

Examples of sun.net.www.MessageHeader

     *the entry does not exist.
     */
    public MessageHeader getEntry(String name) {
        Enumeration enum_ = entries();
        while(enum_.hasMoreElements()) {
            MessageHeader mh = (MessageHeader)enum_.nextElement();
            if (name.equals(mh.findValue("Name"))) {
                return mh;
            }
        }
        return null;
    }
View Full Code Here

Examples of sun.net.www.MessageHeader

    /**
     * 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);

        BASE64Encoder encoder = new BASE64Encoder();
        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", encoder.encode(digest));
            }
            return smh;
        } catch (NoSuchAlgorithmException e) {
            throw new JarException(e.getMessage());
        }
View Full Code Here

Examples of sun.net.www.MessageHeader

    public void stream(OutputStream os) throws IOException {

        /* the first header in the file should be the global one.
         * It should say "SignatureFile-Version: x.x"; barf if not
         */
        MessageHeader globals = (MessageHeader) entries.elementAt(0);
        if (globals.findValue("Signature-Version") == null) {
            throw new JarException("Signature file requires " +
                            "Signature-Version: 1.0 in 1st header");
        }

        PrintStream ps = new PrintStream(os);
        globals.print(ps);

        for (int i = 1; i < entries.size(); ++i) {
            MessageHeader mh = (MessageHeader) entries.elementAt(i);
            mh.print(ps);
        }
    }
View Full Code Here

Examples of sun.net.www.MessageHeader

        if (is != null) {
            return is;
        }

        MessageHeader msgh = new MessageHeader();

        try {
            decodePath(url.getPath());
            if (filename == null || type == DIR) {
                ftp.ascii();
                cd(pathname);
                if (filename == null)
                    is = new FtpInputStream(ftp, ftp.list());
                else
                    is = new FtpInputStream(ftp, ftp.nameList(filename));
            } else {
                if (type == ASCII)
                    ftp.ascii();
                else
                    ftp.binary();
                cd(pathname);
                is = new FtpInputStream(ftp, ftp.get(filename));
            }

            /* Try to get the size of the file in bytes.  If that is
               successful, then create a MeteredStream. */
            try {
                String response = ftp.getResponseString();
                int offset;

                if ((offset = response.indexOf(" bytes)")) != -1) {
                    int i = offset;
                    int c;

                    while (--i >= 0 && ((c = response.charAt(i)) >= '0'
                                        && c <= '9'))
                        ;
                    i = Integer.parseInt(response.substring(i + 1, offset));
                    msgh.add("content-length", ""+i);
                    if (i > 0) {

                        // Wrap input stream with MeteredStream to ensure read() will always return -1
                        // at expected length.

                        // Check if URL should be metered
                        boolean meteredInput = ProgressMonitor.getDefault().shouldMeterInput(url, "GET");
                        ProgressSource pi = null;

                        if (meteredInput)   {
                            pi = new ProgressSource(url, "GET", i);
                            pi.beginTracking();
                        }

                        is = new MeteredStream(is, pi, i);
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
                /* do nothing, since all we were doing was trying to
                   get the size in bytes of the file */
            }

            String type = guessContentTypeFromName(fullpath);
            if (type == null && is.markSupported()) {
                type = guessContentTypeFromStream(is);
            }
            if (type != null) {
                msgh.add("content-type", type);
            }
        } catch (FileNotFoundException e) {
            try {
                cd(fullpath);
                /* if that worked, then make a directory listing
                   and build an html stream with all the files in
                   the directory */
                ftp.ascii();

                is = new FtpInputStream(ftp, ftp.list());
                msgh.add("content-type", "text/plain");
            } catch (IOException ex) {
                throw new FileNotFoundException(fullpath);
            }
        }
        setProperties(msgh);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.