// 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 > modtime) minModtime = modtime;
if (maxModtime < modtime) maxModtime = 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 == -1) bestVersion = 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.