java.util.jar.JarEntry#setMethod ( )源码实例Demo

下面列出了java.util.jar.JarEntry#setMethod ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: helidon-build-tools   文件: Jar.java
private static JarEntry newJarEntry(Entry entry) {
    final JarEntry result = new JarEntry(entry.getName());
    if (result.getCreationTime() != null) {
        result.setCreationTime(entry.getCreationTime());
    }
    if (result.getLastModifiedTime() != null) {
        result.setLastModifiedTime(entry.getLastModifiedTime());
    }
    if (entry.getExtra() != null) {
        result.setExtra(entry.getExtra());
    }
    if (result.getComment() != null) {
        result.setComment(entry.getComment());
    }
    if (!entry.isDirectory()) {
        final int method = entry.getMethod();
        if (method == JarEntry.STORED || method == ZipEntry.DEFLATED) {
            result.setMethod(method);
        }
    }
    return result;
}
 
/**
 * Creates the directory entries for the given path and writes it to the current archive.
 * 
 * @param destPath the path to add
 * 
 * @throws IOException if an I/O error has occurred
 * @since 3.5
 */
protected void addDirectories(String destPath) throws IOException {
	String path= destPath.replace(File.separatorChar, '/');
	int lastSlash= path.lastIndexOf('/');
	List<JarEntry> directories= new ArrayList<JarEntry>(2);
	while (lastSlash != -1) {
		path= path.substring(0, lastSlash + 1);
		if (!fDirectories.add(path))
			break;

		JarEntry newEntry= new JarEntry(path);
		newEntry.setMethod(ZipEntry.STORED);
		newEntry.setSize(0);
		newEntry.setCrc(0);
		newEntry.setTime(System.currentTimeMillis());
		directories.add(newEntry);

		lastSlash= path.lastIndexOf('/', lastSlash - 1);
	}

	for (int i= directories.size() - 1; i >= 0; --i) {
		fJarOutputStream.putNextEntry(directories.get(i));
	}
}
 
public void addZipEntryStream(ZipEntry zipEntry, InputStream is, String path) throws IOException {
	if (fJarPackage.areDirectoryEntriesIncluded())
		addDirectories(path);
	JarEntry newEntry= new JarEntry(path.replace(File.separatorChar, '/'));
	if (fJarPackage.isCompressed())
		newEntry.setMethod(ZipEntry.DEFLATED);
	// Entry is filled automatically.
	else {
		newEntry.setMethod(ZipEntry.STORED);
		newEntry.setSize(zipEntry.getSize());
		newEntry.setCrc(zipEntry.getCrc());
	}
	long lastModified= System.currentTimeMillis();
	// Set modification time
	newEntry.setTime(lastModified);
	addEntry(newEntry, is);
}
 
public void addZipEntry(ZipEntry zipEntry, ZipFile zipFile, String path) throws IOException {
	if (fJarPackage.areDirectoryEntriesIncluded())
		addDirectories(path);

	JarEntry newEntry= new JarEntry(path.replace(File.separatorChar, '/'));

	if (fJarPackage.isCompressed())
		newEntry.setMethod(ZipEntry.DEFLATED);
		// Entry is filled automatically.
	else {
		newEntry.setMethod(ZipEntry.STORED);
		newEntry.setSize(zipEntry.getSize());
		newEntry.setCrc(zipEntry.getCrc());
	}

	long lastModified= System.currentTimeMillis();

	// Set modification time
	newEntry.setTime(lastModified);

	addEntry(newEntry, zipFile.getInputStream(zipEntry));
}
 
源代码5 项目: twill   文件: ApplicationBundler.java
/**
 * Saves a class entry to the jar output.
 */
private void saveEntry(String entry, URL url, Set<String> entries, JarOutputStream jarOut, boolean compress) {
  if (!entries.add(entry)) {
    return;
  }
  LOG.trace("adding bundle entry " + entry);
  try {
    JarEntry jarEntry = new JarEntry(entry);

    try (InputStream is = url.openStream()) {
      if (compress) {
        jarOut.putNextEntry(jarEntry);
        ByteStreams.copy(is, jarOut);
      } else {
        crc32.reset();
        TransferByteOutputStream os = new TransferByteOutputStream();
        CheckedOutputStream checkedOut = new CheckedOutputStream(os, crc32);
        ByteStreams.copy(is, checkedOut);
        checkedOut.close();

        long size = os.size();
        jarEntry.setMethod(JarEntry.STORED);
        jarEntry.setSize(size);
        jarEntry.setCrc(checkedOut.getChecksum().getValue());
        jarOut.putNextEntry(jarEntry);
        os.transfer(jarOut);
      }
    }
    jarOut.closeEntry();
  } catch (Exception e) {
    throw Throwables.propagate(e);
  }
}
 
源代码6 项目: turbine   文件: Main.java
private static void addEntry(JarOutputStream jos, String name, byte[] bytes) throws IOException {
  JarEntry je = new JarEntry(name);
  // TODO(cushon): switch to setLocalTime after we migrate to JDK 9
  je.setTime(DEFAULT_TIMESTAMP);
  je.setMethod(ZipEntry.STORED);
  je.setSize(bytes.length);
  je.setCrc(Hashing.crc32().hashBytes(bytes).padToLong());
  jos.putNextEntry(je);
  jos.write(bytes);
}
 
/**
 * Creates the directory entries for the given path and writes it to the
 * current archive.
 *
 * @param resource
 *            the resource for which the parent directories are to be added
 * @param destinationPath
 *            the path to add
 *
 * @throws IOException
 *             if an I/O error has occurred
 * @throws CoreException
 *             if accessing the resource failes
 */
protected void addDirectories(IResource resource, IPath destinationPath) throws IOException, CoreException {
	IContainer parent= null;
	String path= destinationPath.toString().replace(File.separatorChar, '/');
	int lastSlash= path.lastIndexOf('/');
	List<JarEntry> directories= new ArrayList<JarEntry>(2);
	while (lastSlash != -1) {
		path= path.substring(0, lastSlash + 1);
		if (!fDirectories.add(path))
			break;

		parent= resource.getParent();
		long timeStamp= System.currentTimeMillis();
		URI location= parent.getLocationURI();
		if (location != null) {
			IFileInfo info= EFS.getStore(location).fetchInfo();
			if (info.exists())
				timeStamp= info.getLastModified();
		}

		JarEntry newEntry= new JarEntry(path);
		newEntry.setMethod(ZipEntry.STORED);
		newEntry.setSize(0);
		newEntry.setCrc(0);
		newEntry.setTime(timeStamp);
		directories.add(newEntry);

		lastSlash= path.lastIndexOf('/', lastSlash - 1);
	}

	for (int i= directories.size() - 1; i >= 0; --i) {
		fJarOutputStream.putNextEntry(directories.get(i));
	}
}
 
/**
 * Creates a new JarEntry with the passed path and contents, and writes it
 * to the current archive.
 *
 * @param	resource			the file to write
 * @param	path				the path inside the archive
 *
    * @throws	IOException			if an I/O error has occurred
 * @throws	CoreException 		if the resource can-t be accessed
 */
protected void addFile(IFile resource, IPath path) throws IOException, CoreException {
	JarEntry newEntry= new JarEntry(path.toString().replace(File.separatorChar, '/'));
	byte[] readBuffer= new byte[4096];

	if (fJarPackage.isCompressed())
		newEntry.setMethod(ZipEntry.DEFLATED);
		// Entry is filled automatically.
	else {
		newEntry.setMethod(ZipEntry.STORED);
		JarPackagerUtil.calculateCrcAndSize(newEntry, resource.getContents(false), readBuffer);
	}

	long lastModified= System.currentTimeMillis();
	URI locationURI= resource.getLocationURI();
	if (locationURI != null) {
		IFileInfo info= EFS.getStore(locationURI).fetchInfo();
		if (info.exists())
			lastModified= info.getLastModified();
	}

	// Set modification time
	newEntry.setTime(lastModified);

	InputStream contentStream = resource.getContents(false);

	addEntry(newEntry, contentStream);
}
 
源代码9 项目: turbine   文件: ZipTest.java
private static void createEntry(ZipOutputStream jos, String name, byte[] bytes)
    throws IOException {
  JarEntry je = new JarEntry(name);
  je.setMethod(JarEntry.STORED);
  je.setSize(bytes.length);
  je.setCrc(Hashing.crc32().hashBytes(bytes).padToLong());
  jos.putNextEntry(je);
  jos.write(bytes);
}
 
/**
 * Add the directory entries for the given path to the jar.
 *
 * @param destinationPath the path to add
 * @param correspondingFile the corresponding file in the file system
 *  or <code>null</code> if it doesn't exist
 * @throws IOException if an I/O error has occurred
 */
private void addDirectories(IPath destinationPath, File correspondingFile) throws IOException {
	String path= destinationPath.toString().replace(File.separatorChar, '/');
	int lastSlash= path.lastIndexOf('/');
	List<JarEntry> directories= new ArrayList<JarEntry>(2);
	while(lastSlash != -1) {
		path= path.substring(0, lastSlash + 1);
		if (!fDirectories.add(path))
			break;

		if (correspondingFile != null)
			correspondingFile= correspondingFile.getParentFile();
		long timeStamp= correspondingFile != null && correspondingFile.exists()
			? correspondingFile.lastModified()
			: System.currentTimeMillis();

		JarEntry newEntry= new JarEntry(path);
		newEntry.setMethod(ZipEntry.STORED);
		newEntry.setSize(0);
		newEntry.setCrc(0);
		newEntry.setTime(timeStamp);
		directories.add(newEntry);

		lastSlash= path.lastIndexOf('/', lastSlash - 1);
	}

	for(int i= directories.size() - 1; i >= 0; --i) {
		fJarOutputStream.putNextEntry(directories.get(i));
	}
}
 
源代码11 项目: dragonwell8_jdk   文件: UnpackerImpl.java
private void unpackSegment(InputStream in, JarOutputStream out) throws IOException {
    props.setProperty(java.util.jar.Pack200.Unpacker.PROGRESS,"0");
    // Process the output directory or jar output.
    new PackageReader(pkg, in).read();

    if (props.getBoolean("unpack.strip.debug"))    pkg.stripAttributeKind("Debug");
    if (props.getBoolean("unpack.strip.compile"))  pkg.stripAttributeKind("Compile");
    props.setProperty(java.util.jar.Pack200.Unpacker.PROGRESS,"50");
    pkg.ensureAllClassFiles();
    // Now write out the files.
    Set<Package.Class> classesToWrite = new HashSet<>(pkg.getClasses());
    for (Package.File file : pkg.getFiles()) {
        String name = file.nameString;
        JarEntry je = new JarEntry(Utils.getJarEntryName(name));
        boolean deflate;

        deflate = (keepDeflateHint)
                  ? (((file.options & Constants.FO_DEFLATE_HINT) != 0) ||
                    ((pkg.default_options & Constants.AO_DEFLATE_HINT) != 0))
                  : deflateHint;

        boolean needCRC = !deflate;  // STORE mode requires CRC

        if (needCRC)  crc.reset();
        bufOut.reset();
        if (file.isClassStub()) {
            Package.Class cls = file.getStubClass();
            assert(cls != null);
            new ClassWriter(cls, needCRC ? crcOut : bufOut).write();
            classesToWrite.remove(cls);  // for an error check
        } else {
            // collect data & maybe CRC
            file.writeTo(needCRC ? crcOut : bufOut);
        }
        je.setMethod(deflate ? JarEntry.DEFLATED : JarEntry.STORED);
        if (needCRC) {
            if (verbose > 0)
                Utils.log.info("stored size="+bufOut.size()+" and crc="+crc.getValue());

            je.setMethod(JarEntry.STORED);
            je.setSize(bufOut.size());
            je.setCrc(crc.getValue());
        }
        if (keepModtime) {
            je.setTime(file.modtime);
            // Convert back to milliseconds
            je.setTime((long)file.modtime * 1000);
        } else {
            je.setTime((long)modtime * 1000);
        }
        out.putNextEntry(je);
        bufOut.writeTo(out);
        out.closeEntry();
        if (verbose > 0)
            Utils.log.info("Writing "+Utils.zeString((ZipEntry)je));
    }
    assert(classesToWrite.isEmpty());
    props.setProperty(java.util.jar.Pack200.Unpacker.PROGRESS,"100");
    pkg.reset();  // reset for the next segment, if any
}
 
源代码12 项目: dragonwell8_jdk   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }
 
源代码13 项目: bazel   文件: JarHelper.java
/**
 * Copies file or directory entries from the file system into the jar. Directory entries will be
 * detected and their names automatically '/' suffixed.
 */
protected void copyEntry(JarOutputStream out, String name, Path path) throws IOException {
  if (!names.contains(name)) {
    if (!Files.exists(path)) {
      throw new FileNotFoundException(path.toAbsolutePath() + " (No such file or directory)");
    }
    boolean isDirectory = Files.isDirectory(path);
    if (isDirectory && !name.endsWith("/")) {
      name = name + '/'; // always normalize directory names before checking set
    }
    if (names.add(name)) {
      if (verbose) {
        System.err.println("adding " + path);
      }
      // Create a new entry
      long size = isDirectory ? 0 : Files.size(path);
      JarEntry outEntry = new JarEntry(name);
      long newtime =
          normalize ? normalizedTimestamp(name) : Files.getLastModifiedTime(path).toMillis();
      outEntry.setTime(newtime);
      outEntry.setSize(size);
      if (size == 0L) {
        outEntry.setMethod(JarEntry.STORED);
        outEntry.setCrc(0);
        out.putNextEntry(outEntry);
      } else {
        outEntry.setMethod(storageMethod);
        if (storageMethod == JarEntry.STORED) {
          // ZipFile requires us to calculate the CRC-32 for any STORED entry.
          // It would be nicer to do this via DigestInputStream, but
          // the architecture of ZipOutputStream requires us to know the CRC-32
          // before we write the data to the stream.
          byte[] bytes = Files.readAllBytes(path);
          CRC32 crc = new CRC32();
          crc.update(bytes);
          outEntry.setCrc(crc.getValue());
          out.putNextEntry(outEntry);
          out.write(bytes);
        } else {
          out.putNextEntry(outEntry);
          Files.copy(path, out);
        }
      }
      out.closeEntry();
    }
  }
}
 
源代码14 项目: TencentKona-8   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }
 
源代码15 项目: jdk8u60   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }
 
源代码16 项目: openjdk-jdk8u   文件: UnpackerImpl.java
private void unpackSegment(InputStream in, JarOutputStream out) throws IOException {
    props.setProperty(java.util.jar.Pack200.Unpacker.PROGRESS,"0");
    // Process the output directory or jar output.
    new PackageReader(pkg, in).read();

    if (props.getBoolean("unpack.strip.debug"))    pkg.stripAttributeKind("Debug");
    if (props.getBoolean("unpack.strip.compile"))  pkg.stripAttributeKind("Compile");
    props.setProperty(java.util.jar.Pack200.Unpacker.PROGRESS,"50");
    pkg.ensureAllClassFiles();
    // Now write out the files.
    Set<Package.Class> classesToWrite = new HashSet<>(pkg.getClasses());
    for (Package.File file : pkg.getFiles()) {
        String name = file.nameString;
        JarEntry je = new JarEntry(Utils.getJarEntryName(name));
        boolean deflate;

        deflate = (keepDeflateHint)
                  ? (((file.options & Constants.FO_DEFLATE_HINT) != 0) ||
                    ((pkg.default_options & Constants.AO_DEFLATE_HINT) != 0))
                  : deflateHint;

        boolean needCRC = !deflate;  // STORE mode requires CRC

        if (needCRC)  crc.reset();
        bufOut.reset();
        if (file.isClassStub()) {
            Package.Class cls = file.getStubClass();
            assert(cls != null);
            new ClassWriter(cls, needCRC ? crcOut : bufOut).write();
            classesToWrite.remove(cls);  // for an error check
        } else {
            // collect data & maybe CRC
            file.writeTo(needCRC ? crcOut : bufOut);
        }
        je.setMethod(deflate ? JarEntry.DEFLATED : JarEntry.STORED);
        if (needCRC) {
            if (verbose > 0)
                Utils.log.info("stored size="+bufOut.size()+" and crc="+crc.getValue());

            je.setMethod(JarEntry.STORED);
            je.setSize(bufOut.size());
            je.setCrc(crc.getValue());
        }
        if (keepModtime) {
            je.setTime(file.modtime);
            // Convert back to milliseconds
            je.setTime((long)file.modtime * 1000);
        } else {
            je.setTime((long)modtime * 1000);
        }
        out.putNextEntry(je);
        bufOut.writeTo(out);
        out.closeEntry();
        if (verbose > 0)
            Utils.log.info("Writing "+Utils.zeString((ZipEntry)je));
    }
    assert(classesToWrite.isEmpty());
    props.setProperty(java.util.jar.Pack200.Unpacker.PROGRESS,"100");
    pkg.reset();  // reset for the next segment, if any
}
 
源代码17 项目: openjdk-jdk8u   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }
 
源代码18 项目: openjdk-jdk8u-backup   文件: UnpackerImpl.java
private void unpackSegment(InputStream in, JarOutputStream out) throws IOException {
    props.setProperty(java.util.jar.Pack200.Unpacker.PROGRESS,"0");
    // Process the output directory or jar output.
    new PackageReader(pkg, in).read();

    if (props.getBoolean("unpack.strip.debug"))    pkg.stripAttributeKind("Debug");
    if (props.getBoolean("unpack.strip.compile"))  pkg.stripAttributeKind("Compile");
    props.setProperty(java.util.jar.Pack200.Unpacker.PROGRESS,"50");
    pkg.ensureAllClassFiles();
    // Now write out the files.
    Set<Package.Class> classesToWrite = new HashSet<>(pkg.getClasses());
    for (Package.File file : pkg.getFiles()) {
        String name = file.nameString;
        JarEntry je = new JarEntry(Utils.getJarEntryName(name));
        boolean deflate;

        deflate = (keepDeflateHint)
                  ? (((file.options & Constants.FO_DEFLATE_HINT) != 0) ||
                    ((pkg.default_options & Constants.AO_DEFLATE_HINT) != 0))
                  : deflateHint;

        boolean needCRC = !deflate;  // STORE mode requires CRC

        if (needCRC)  crc.reset();
        bufOut.reset();
        if (file.isClassStub()) {
            Package.Class cls = file.getStubClass();
            assert(cls != null);
            new ClassWriter(cls, needCRC ? crcOut : bufOut).write();
            classesToWrite.remove(cls);  // for an error check
        } else {
            // collect data & maybe CRC
            file.writeTo(needCRC ? crcOut : bufOut);
        }
        je.setMethod(deflate ? JarEntry.DEFLATED : JarEntry.STORED);
        if (needCRC) {
            if (verbose > 0)
                Utils.log.info("stored size="+bufOut.size()+" and crc="+crc.getValue());

            je.setMethod(JarEntry.STORED);
            je.setSize(bufOut.size());
            je.setCrc(crc.getValue());
        }
        if (keepModtime) {
            je.setTime(file.modtime);
            // Convert back to milliseconds
            je.setTime((long)file.modtime * 1000);
        } else {
            je.setTime((long)modtime * 1000);
        }
        out.putNextEntry(je);
        bufOut.writeTo(out);
        out.closeEntry();
        if (verbose > 0)
            Utils.log.info("Writing "+Utils.zeString((ZipEntry)je));
    }
    assert(classesToWrite.isEmpty());
    props.setProperty(java.util.jar.Pack200.Unpacker.PROGRESS,"100");
    pkg.reset();  // reset for the next segment, if any
}
 
源代码19 项目: jdk8u-jdk   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }
 
源代码20 项目: hottub   文件: LargeJarEntry.java
public static void main(String[] args) throws Exception {

        String srcDir = System.getProperty("test.src", ".");
        String keystore = srcDir + "/JarSigning.keystore";
        String jarName = "largeJarEntry.jar";

        // Set java.io.tmpdir to the current working dir (see 6474350)
        System.setProperty("java.io.tmpdir", System.getProperty("user.dir"));

        // first, create jar file with 8M uncompressed entry
        // note, we set the max heap size to 8M in @run tag above
        byte[] bytes = new byte[1000000];
        CRC32 crc = new CRC32();
        for (int i=0; i<8; i++) {
            crc.update(bytes);
        }
        JarEntry je = new JarEntry("large");
        je.setSize(8000000l);
        je.setMethod(JarEntry.STORED);
        je.setCrc(crc.getValue());
        File file = new File(jarName);
        FileOutputStream os = new FileOutputStream(file);
        JarOutputStream jos = new JarOutputStream(os);
        jos.setMethod(JarEntry.STORED);
        jos.putNextEntry(je);
        for (int i=0; i<8; i++) {
            jos.write(bytes, 0, bytes.length);
        }
        jos.close();

        String[] jsArgs = { "-keystore", keystore, "-storepass", "bbbbbb",
                jarName, "b" };
        // now, try to sign it
        try {
            sun.security.tools.jarsigner.Main.main(jsArgs);
        } catch (OutOfMemoryError err) {
            throw new Exception("Test failed with OutOfMemoryError", err);
        } finally {
            // remove jar file
            file.delete();
        }
    }