Package com.sun.java.util.jar.pack.Package

Examples of com.sun.java.util.jar.pack.Package.File


        byte[] buf = new byte[1<<16];
        for (int i = 0; i < numFiles; i++) {
            // %%% Use a big temp file for file bits?
            Utf8Entry name = (Utf8Entry) file_name.getRef();
            long size = fileLengths[i];
            File file = pkg.new File(name);
            file.modtime = pkg.default_modtime;
            file.options = pkg.default_options;
            if (haveModtime)
                file.modtime += file_modtime.getInt();
            if (haveOptions)
                file.options |= file_options.getInt();
            if (verbose > 1)
                Utils.log.fine("Reading "+size+" bytes of "+name.stringValue());
            long toRead = size;
            while (toRead > 0) {
                int nr = buf.length;
                if (nr > toReadnr = (int) toRead;
                nr = file_bits.getInputStream().read(buf, 0, nr);
                if (nr < 0throw new EOFException();
                file.addBytes(buf, 0, nr);
                toRead -= nr;
            }
            pkg.addFile(file);
            if (file.isClassStub()) {
                assert(file.getFileLength() == 0);
                Class cls = (Class) nextClass.next();
                cls.initFile(file);
            }
        }
View Full Code Here


        // Import defaults from package (deflate hint, etc.).
        archiveOptions |= pkg.default_options;

        for (Iterator i = pkg.files.iterator(); i.hasNext(); ) {
            File file = (File) i.next();

            int modtime = file.modtime;
            int options = file.options;

            if (minModtime == NO_MODTIME) {
                minModtime = maxModtime = modtime;
            } else {
                if (minModtime > modtimeminModtime = modtime;
                if (maxModtime < modtimemaxModtime = modtime;
            }
            minOptions &= options;
            maxOptions |= options;
        }
        if (pkg.default_modtime == NO_MODTIME) {
            // Make everything else be a positive offset from here.
            pkg.default_modtime = minModtime;
        }
        if (minModtime != NO_MODTIME && minModtime != maxModtime) {
            // Put them into a band.
            archiveOptions |= AO_HAVE_FILE_MODTIME;
        }
        // If the archive deflation is set do not bother with each file.
        if (!testBit(archiveOptions,AO_DEFLATE_HINT) && minOptions != -1) {
            if (testBit(minOptions, FO_DEFLATE_HINT)) {
                // Every file has the deflate_hint set.
                // Set it for the whole archive, and omit options.
                archiveOptions |= AO_DEFLATE_HINT;
                minOptions -= FO_DEFLATE_HINT;
                maxOptions -= FO_DEFLATE_HINT;
            }
            pkg.default_options |= minOptions;
            if (minOptions != maxOptions
                || minOptions != pkg.default_options) {
                archiveOptions |= AO_HAVE_FILE_OPTIONS;
            }
        }
        // Decide on default version number (majority rule).
        HashMap verCounts = new HashMap();
        int bestCount = 0;
        int bestVersion = -1;
        for (Iterator i = pkg.classes.iterator(); i.hasNext(); ) {
            Class cls = (Class) i.next();
            int version = cls.getVersion();
            int[] var = (int[]) verCounts.get(new Integer(version));
            if (var == null) {
                var = new int[1];
                verCounts.put(new Integer(version), var);
            }
            int count = (var[0] += 1);
            //System.out.println("version="+version+" count="+count);
            if (bestCount < count) {
                bestCount = count;
                bestVersion = version;
            }
        }
        verCounts.clear();
        if (bestVersion == -1bestVersion = 0// degenerate case
        int bestMajver = (char)(bestVersion >>> 16);
        int bestMinver = (char)(bestVersion);
        pkg.default_class_majver = (short) bestMajver;
        pkg.default_class_minver = (short) bestMinver;
        String bestVerStr = Package.versionStringOf(bestMajver, bestMinver);
        if (verbose > 0)
           Utils.log.info("Consensus version number in segment is "+bestVerStr);
        if (verbose > 0)
            Utils.log.info("Highest version number in segment is "+
                           Package.versionStringOf(pkg.getHighestClassVersion()));

        // Now add explicit pseudo-attrs. to classes with odd versions.
        for (Iterator i = pkg.classes.iterator(); i.hasNext(); ) {
            Class cls = (Class) i.next();

            if (cls.getVersion() != bestVersion) {
                Attribute a = makeClassFileVersionAttr(cls.minver, cls.majver);
                if (verbose > 1) {
                    String clsVer = cls.getVersionString();
                    String pkgVer = bestVerStr;
                    Utils.log.fine("Version "+clsVer+" of "+cls
                                     +" doesn't match package version "
                                     +pkgVer);
                }
                // Note:  Does not add in "natural" order.  (Who cares?)
                cls.addAttribute(a);
            }
        }

        // Decide if we are transmitting a huge resource file:
        for (Iterator i = pkg.files.iterator(); i.hasNext(); ) {
            File file = (File) i.next();
            long len = file.getFileLength();
            if (len != (int)len) {
                archiveOptions |= AO_HAVE_FILE_SIZE_HI;
                if (verbose > 0)
                   Utils.log.info("Note: Huge resource file "+file.getFileName()+" forces 64-bit sizing");
                break;
            }
        }

        // Decide if code attributes typically have sub-attributes.
View Full Code Here

        boolean haveSizeHi  = testBit(options, AO_HAVE_FILE_SIZE_HI);
        boolean haveModtime = testBit(options, AO_HAVE_FILE_MODTIME);
        boolean haveOptions = testBit(options, AO_HAVE_FILE_OPTIONS);
        if (!haveOptions) {
            for (Iterator i = pkg.files.iterator(); i.hasNext(); ) {
                File file = (File) i.next();
                if (file.isClassStub()) {
                    haveOptions = true;
                    options |= AO_HAVE_FILE_OPTIONS;
                    archiveOptions = options;
                    break;
                }
            }
        }
        if (haveSizeHi || haveModtime || haveOptions || !pkg.files.isEmpty()) {
            options |= AO_HAVE_FILE_HEADERS;
            archiveOptions = options;
        }

        for (Iterator i = pkg.files.iterator(); i.hasNext(); ) {
            File file = (File) i.next();
            file_name.putRef(file.name);
            long len = file.getFileLength();
            file_size_lo.putInt((int)len);
            if (haveSizeHi)
                file_size_hi.putInt((int)(len >>> 32));
            if (haveModtime)
                file_modtime.putInt(file.modtime - pkg.default_modtime);
            if (haveOptions)
                file_options.putInt(file.options);
            file.writeTo(file_bits.collectorStream());
            if (verbose > 1)
                Utils.log.fine("Wrote "+len+" bytes of "+file.name.stringValue());
        }
        if (verbose > 0)
            Utils.log.info("Wrote "+numFiles+" resource files");
View Full Code Here

        byte[] buf = new byte[1<<16];
        for (int i = 0; i < numFiles; i++) {
            // %%% Use a big temp file for file bits?
            Utf8Entry name = (Utf8Entry) file_name.getRef();
            long size = fileLengths[i];
            File file = pkg.new File(name);
            file.modtime = pkg.default_modtime;
            file.options = pkg.default_options;
            if (haveModtime)
                file.modtime += file_modtime.getInt();
            if (haveOptions)
                file.options |= file_options.getInt();
            if (verbose > 1)
                Utils.log.fine("Reading "+size+" bytes of "+name.stringValue());
            long toRead = size;
            while (toRead > 0) {
                int nr = buf.length;
                if (nr > toReadnr = (int) toRead;
                nr = file_bits.getInputStream().read(buf, 0, nr);
                if (nr < 0throw new EOFException();
                file.addBytes(buf, 0, nr);
                toRead -= nr;
            }
            pkg.addFile(file);
            if (file.isClassStub()) {
                assert(file.getFileLength() == 0);
                Class cls = (Class) nextClass.next();
                cls.initFile(file);
            }
        }
View Full Code Here

TOP

Related Classes of com.sun.java.util.jar.pack.Package.File

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.