Package sun.net.www

Examples of sun.net.www.MessageHeader$HeaderIterator


    throws JarException {

        this(name);

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


        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

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

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

     *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

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

    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

        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

        try {
            Socket sock = ss.accept();
            InputStream is = sock.getInputStream();
            OutputStream os = sock.getOutputStream();

            MessageHeader headers =  new MessageHeader (is);
            String requestLine = headers.getValue(0);

            int first  = requestLine.indexOf(' ');
            int second  = requestLine.lastIndexOf(' ');
            String URIString = requestLine.substring(first+1, second);
View Full Code Here

    static void handleConnection(Socket s, String[] resp, int start, int end) {
        try {
            OutputStream os = s.getOutputStream();

            for (int i=start; i<end; i++) {
                MessageHeader header = new MessageHeader (s.getInputStream());
                //System.out.println("Input :" + header);
                //System.out.println("Output:" + resp[i]);
                os.write(resp[i].getBytes("ASCII"));
            }
View Full Code Here

TOP

Related Classes of sun.net.www.MessageHeader$HeaderIterator

Copyright © 2018 www.massapicom. 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.