java.util.jar.JarFile#MANIFEST_NAME源码实例Demo

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

源代码1 项目: hbase   文件: JarFinder.java
public static void jarDir(File dir, String relativePath, ZipOutputStream zos)
  throws IOException {
  Preconditions.checkNotNull(relativePath, "relativePath");
  Preconditions.checkNotNull(zos, "zos");

  // by JAR spec, if there is a manifest, it must be the first entry in the
  // ZIP.
  File manifestFile = new File(dir, JarFile.MANIFEST_NAME);
  ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME);
  if (!manifestFile.exists()) {
    zos.putNextEntry(manifestEntry);
    new Manifest().write(new BufferedOutputStream(zos));
    zos.closeEntry();
  } else {
    copyToZipStream(manifestFile, manifestEntry, zos);
  }
  zos.closeEntry();
  zipDir(dir, relativePath, zos, true);
  zos.close();
}
 
源代码2 项目: TencentKona-8   文件: Utils.java
static void copyJarFile(JarInputStream in, JarOutputStream out) throws IOException {
    if (in.getManifest() != null) {
        ZipEntry me = new ZipEntry(JarFile.MANIFEST_NAME);
        out.putNextEntry(me);
        in.getManifest().write(out);
        out.closeEntry();
    }
    byte[] buffer = new byte[1 << 14];
    for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
        out.putNextEntry(je);
        for (int nr; 0 < (nr = in.read(buffer)); ) {
            out.write(buffer, 0, nr);
        }
    }
    in.close();
    markJarFile(out);  // add PACK200 comment
}
 
源代码3 项目: jdk8u60   文件: Utils.java
static void copyJarFile(JarInputStream in, JarOutputStream out) throws IOException {
    if (in.getManifest() != null) {
        ZipEntry me = new ZipEntry(JarFile.MANIFEST_NAME);
        out.putNextEntry(me);
        in.getManifest().write(out);
        out.closeEntry();
    }
    byte[] buffer = new byte[1 << 14];
    for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
        out.putNextEntry(je);
        for (int nr; 0 < (nr = in.read(buffer)); ) {
            out.write(buffer, 0, nr);
        }
    }
    in.close();
    markJarFile(out);  // add PACK200 comment
}
 
@Test
public void testManifest() throws Exception {
    File file = new File(folder, JarFile.MANIFEST_NAME);
    assertThat(file.getParentFile().mkdir(), is(true));
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    OutputStream outputStream = new FileOutputStream(file);
    try {
        manifest.write(outputStream);
    } finally {
        outputStream.close();
    }
    Plugin.Engine.Source.Origin origin = new Plugin.Engine.Source.ForFolder(folder).read();
    try {
        Manifest readManifest = origin.getManifest();
        assertThat(readManifest, notNullValue(Manifest.class));
        assertThat(readManifest.getMainAttributes().getValue(Attributes.Name.MANIFEST_VERSION), is("1.0"));
    } finally {
        origin.close();
    }
    assertThat(file.delete(), is(true));
    assertThat(file.getParentFile().delete(), is(true));
}
 
源代码5 项目: servicecomb-java-chassis   文件: TestJvmUtils.java
@Test
public void findMainClass_jar_normal() throws Exception {

  URL url = PowerMockito.mock(URL.class);

  String command = "a.jar";
  String manifestUri = "jar:file:" + new File(command).getAbsolutePath() + "!/" + JarFile.MANIFEST_NAME;
  PowerMockito.whenNew(URL.class).withParameterTypes(String.class)
      .withArguments(manifestUri).thenReturn(url);

  String content = String.format("Manifest-Version: 1.0\nMain-Class: %s\n", TestJvmUtils.class.getName());
  InputStream inputStream = new ByteArrayInputStream(content.getBytes());
  PowerMockito.when(url.openStream()).thenReturn(inputStream);

  System.setProperty(JvmUtils.SUN_JAVA_COMMAND, command + " arg");

  Assert.assertEquals(TestJvmUtils.class, JvmUtils.findMainClass());
}
 
源代码6 项目: jdk8u-dev-jdk   文件: Utils.java
static void copyJarFile(JarInputStream in, JarOutputStream out) throws IOException {
    if (in.getManifest() != null) {
        ZipEntry me = new ZipEntry(JarFile.MANIFEST_NAME);
        out.putNextEntry(me);
        in.getManifest().write(out);
        out.closeEntry();
    }
    byte[] buffer = new byte[1 << 14];
    for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
        out.putNextEntry(je);
        for (int nr; 0 < (nr = in.read(buffer)); ) {
            out.write(buffer, 0, nr);
        }
    }
    in.close();
    markJarFile(out);  // add PACK200 comment
}
 
源代码7 项目: Mixin   文件: MainAttributes.java
private static Attributes getDirAttributes(File dir) {
    File manifestFile = new File(dir, JarFile.MANIFEST_NAME);
    if (manifestFile.isFile()) {
        ByteSource source = Files.asByteSource(manifestFile);
        InputStream inputStream = null;
        try {
            inputStream = source.openBufferedStream();
            Manifest manifest = new Manifest(inputStream);
            return manifest.getMainAttributes();
        } catch (IOException ex) {
            // be quiet checkstyle
        } finally {
            try {
                if (inputStream != null) {
                    inputStream.close();
                }
            } catch (IOException e) {
                // ignore
            }
        }
    }
    
    return null;
}
 
源代码8 项目: openjdk-jdk9   文件: Utils.java
static void copyJarFile(JarInputStream in, JarOutputStream out) throws IOException {
    if (in.getManifest() != null) {
        ZipEntry me = new ZipEntry(JarFile.MANIFEST_NAME);
        out.putNextEntry(me);
        in.getManifest().write(out);
        out.closeEntry();
    }
    byte[] buffer = new byte[1 << 14];
    for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
        out.putNextEntry(je);
        for (int nr; 0 < (nr = in.read(buffer)); ) {
            out.write(buffer, 0, nr);
        }
    }
    in.close();
    markJarFile(out);  // add PACK200 comment
}
 
@Test
public void testManifest() throws Exception {
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    Plugin.Engine.Target target = new Plugin.Engine.Target.ForFolder(folder);
    target.write(manifest).close();
    File file = new File(folder, JarFile.MANIFEST_NAME);
    assertThat(file.isFile(), is(true));
    InputStream inputStream = new FileInputStream(file);
    try {
        Manifest readManifest = new Manifest(inputStream);
        assertThat(readManifest.getMainAttributes().get(Attributes.Name.MANIFEST_VERSION), is((Object) "1.0"));
    } finally {
        inputStream.close();
    }
    assertThat(file.delete(), is(true));
    assertThat(file.getParentFile().delete(), is(true));
}
 
源代码10 项目: jdk8u-jdk   文件: Utils.java
static void copyJarFile(JarInputStream in, JarOutputStream out) throws IOException {
    if (in.getManifest() != null) {
        ZipEntry me = new ZipEntry(JarFile.MANIFEST_NAME);
        out.putNextEntry(me);
        in.getManifest().write(out);
        out.closeEntry();
    }
    byte[] buffer = new byte[1 << 14];
    for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
        out.putNextEntry(je);
        for (int nr; 0 < (nr = in.read(buffer)); ) {
            out.write(buffer, 0, nr);
        }
    }
    in.close();
    markJarFile(out);  // add PACK200 comment
}
 
源代码11 项目: hottub   文件: Utils.java
static void copyJarFile(JarInputStream in, JarOutputStream out) throws IOException {
    if (in.getManifest() != null) {
        ZipEntry me = new ZipEntry(JarFile.MANIFEST_NAME);
        out.putNextEntry(me);
        in.getManifest().write(out);
        out.closeEntry();
    }
    byte[] buffer = new byte[1 << 14];
    for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
        out.putNextEntry(je);
        for (int nr; 0 < (nr = in.read(buffer)); ) {
            out.write(buffer, 0, nr);
        }
    }
    in.close();
    markJarFile(out);  // add PACK200 comment
}
 
源代码12 项目: openjdk-8-source   文件: Utils.java
static void copyJarFile(JarInputStream in, JarOutputStream out) throws IOException {
    if (in.getManifest() != null) {
        ZipEntry me = new ZipEntry(JarFile.MANIFEST_NAME);
        out.putNextEntry(me);
        in.getManifest().write(out);
        out.closeEntry();
    }
    byte[] buffer = new byte[1 << 14];
    for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
        out.putNextEntry(je);
        for (int nr; 0 < (nr = in.read(buffer)); ) {
            out.write(buffer, 0, nr);
        }
    }
    in.close();
    markJarFile(out);  // add PACK200 comment
}
 
源代码13 项目: big-c   文件: JarFinder.java
public static void jarDir(File dir, String relativePath, ZipOutputStream zos)
  throws IOException {
  Preconditions.checkNotNull(relativePath, "relativePath");
  Preconditions.checkNotNull(zos, "zos");

  // by JAR spec, if there is a manifest, it must be the first entry in the
  // ZIP.
  File manifestFile = new File(dir, JarFile.MANIFEST_NAME);
  ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME);
  if (!manifestFile.exists()) {
    zos.putNextEntry(manifestEntry);
    new Manifest().write(new BufferedOutputStream(zos));
    zos.closeEntry();
  } else {
    copyToZipStream(manifestFile, manifestEntry, zos);
  }
  zos.closeEntry();
  zipDir(dir, relativePath, zos, true);
  zos.close();
}
 
源代码14 项目: openjdk-8   文件: Utils.java
static void copyJarFile(JarInputStream in, JarOutputStream out) throws IOException {
    if (in.getManifest() != null) {
        ZipEntry me = new ZipEntry(JarFile.MANIFEST_NAME);
        out.putNextEntry(me);
        in.getManifest().write(out);
        out.closeEntry();
    }
    byte[] buffer = new byte[1 << 14];
    for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
        out.putNextEntry(je);
        for (int nr; 0 < (nr = in.read(buffer)); ) {
            out.write(buffer, 0, nr);
        }
    }
    in.close();
    markJarFile(out);  // add PACK200 comment
}
 
源代码15 项目: jdk8u_jdk   文件: Utils.java
static void copyJarFile(JarInputStream in, JarOutputStream out) throws IOException {
    if (in.getManifest() != null) {
        ZipEntry me = new ZipEntry(JarFile.MANIFEST_NAME);
        out.putNextEntry(me);
        in.getManifest().write(out);
        out.closeEntry();
    }
    byte[] buffer = new byte[1 << 14];
    for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
        out.putNextEntry(je);
        for (int nr; 0 < (nr = in.read(buffer)); ) {
            out.write(buffer, 0, nr);
        }
    }
    in.close();
    markJarFile(out);  // add PACK200 comment
}
 
源代码16 项目: AVM   文件: ImmortalDappModule.java
/**
 * Create the in-memory JAR containing all the classes in this module.
 */
public byte[] createJar(long blockTimeStamp) throws IOException {
    // set jar file timestamp to block timestamp so the whole network is in agreement over this.
    FileTime timestamp = FileTime.fromMillis(blockTimeStamp);

    // manifest, we explicitly write it so that can can control its timestamps.
    Manifest manifest = new Manifest();
    manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
    manifest.getMainAttributes().put(Attributes.Name.MAIN_CLASS, this.mainClass);

    ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME);
    manifestEntry.setLastModifiedTime(timestamp);
    manifestEntry.setLastAccessTime(timestamp);
    manifestEntry.setCreationTime(timestamp);

    // Create a temporary memory location for this JAR.
    ByteArrayOutputStream tempJarStream = new ByteArrayOutputStream(MAX_JAR_BYTES);

    // create the jar file
    try (JarOutputStream target = new JarOutputStream(tempJarStream)) {
        // first, write the manifest file
        target.putNextEntry(manifestEntry);
        manifest.write(target);
        target.closeEntry();

        // add the classes
        for (String clazz : this.classes.keySet()) {
            JarEntry entry = new JarEntry(clazz.replace('.', '/') + ".class");
            entry.setLastModifiedTime(timestamp);
            entry.setLastAccessTime(timestamp);
            entry.setCreationTime(timestamp);
            target.putNextEntry(entry);
            target.write(this.classes.get(clazz));
            target.closeEntry();
        }
    }
    return tempJarStream.toByteArray();
}
 
源代码17 项目: spork   文件: Utils.java
public static void jarDir(File dir, String relativePath, ZipOutputStream zos)
        throws IOException {
    Preconditions.checkNotNull(relativePath, "relativePath");
    Preconditions.checkNotNull(zos, "zos");

    // by JAR spec, if there is a manifest, it must be the first entry in
    // the
    // ZIP.
    File manifestFile = new File(dir, JarFile.MANIFEST_NAME);
    ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME);
    if (!manifestFile.exists()) {
        zos.putNextEntry(manifestEntry);
        new Manifest().write(new BufferedOutputStream(zos));
        zos.closeEntry();
    } else {
        InputStream is = new FileInputStream(manifestFile);
        try {
            copyToZipStream(is, manifestEntry, zos);
        } finally {
            if (is != null) {
                is.close();
            }
            if (zos != null) {
                zos.closeEntry();
            }
        }
    }
    zos.closeEntry();
    zipDir(dir, relativePath, zos, true);
    zos.close();
}
 
源代码18 项目: openjdk-jdk9   文件: Main.java
/**
 * Creates a JAR file.
 *
 * Equivalent to {@code jar cfm <jarfile> <manifest> -C <dir> file...}
 *
 * The input files are resolved against the given directory. Any input
 * files that are directories are processed recursively.
 */
static void createJarFile(Path jarfile, Manifest man, Path dir, String... files)
    throws IOException
{
    // create the target directory
    Path parent = jarfile.getParent();
    if (parent != null)
        Files.createDirectories(parent);

    List<Path> entries = new ArrayList<>();
    for (String file : files) {
        Files.find(dir.resolve(file), Integer.MAX_VALUE,
                (p, attrs) -> attrs.isRegularFile())
                .map(e -> dir.relativize(e))
                .forEach(entries::add);
    }

    try (OutputStream out = Files.newOutputStream(jarfile);
         JarOutputStream jos = new JarOutputStream(out))
    {
        if (man != null) {
            JarEntry je = new JarEntry(JarFile.MANIFEST_NAME);
            jos.putNextEntry(je);
            man.write(jos);
            jos.closeEntry();
        }

        for (Path entry : entries) {
            String name = toJarEntryName(entry);
            jos.putNextEntry(new JarEntry(name));
            Files.copy(dir.resolve(entry), jos);
            jos.closeEntry();
        }
    }
}
 
源代码19 项目: byte-buddy   文件: Plugin.java
/**
 * {@inheritDoc}
 */
public Manifest getManifest() throws IOException {
    File file = new File(folder, JarFile.MANIFEST_NAME);
    if (file.exists()) {
        InputStream inputStream = new FileInputStream(file);
        try {
            return new Manifest(inputStream);
        } finally {
            inputStream.close();
        }
    } else {
        return NO_MANIFEST;
    }
}
 
源代码20 项目: spliceengine   文件: ManifestFinder.java
ManifestFinder() {
    this.spliceJarFilePattern = "/splice_machine";
    this.manifestResourcePath = JarFile.MANIFEST_NAME;
}