java.util.jar.JarInputStream#getManifest ( )源码实例Demo

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

源代码1 项目: 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
}
 
源代码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 项目: 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
}
 
源代码4 项目: 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
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: 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
}
 
源代码6 项目: 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
}
 
源代码7 项目: 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
}
 
源代码8 项目: 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
}
 
public Manifest getManifest() throws IOException {
    if (jarFile != null) {
        return jarFile.getManifest();
    } else {
        try {
            JarInputStream is = new JarInputStream(new ByteArrayInputStream(this.content));
            return is.getManifest();
        } catch (IOException e) {
        }
    }
    return null;
}
 
@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.ForJarFile(file);
    target.write(manifest).close();
    JarInputStream inputStream = new JarInputStream(new FileInputStream(file));
    try {
        Manifest readManifest = inputStream.getManifest();
        assertThat(readManifest.getMainAttributes().get(Attributes.Name.MANIFEST_VERSION), is((Object) "1.0"));
        assertThat(inputStream.getNextJarEntry(), nullValue(JarEntry.class));
    } finally {
        inputStream.close();
    }
}
 
源代码11 项目: AVM   文件: Utilities.java
public static String extractMainClassName(JarInputStream jarReader, NameStyle nameStyle) {
    Manifest manifest = jarReader.getManifest();
    if (null != manifest && manifest.getMainAttributes() != null) {
        String mainClassName = manifest.getMainAttributes().getValue(Attributes.Name.MAIN_CLASS);
        if (nameStyle.equals(NameStyle.SLASH_NAME)) {
            mainClassName = Utilities.fulllyQualifiedNameToInternalName(mainClassName);
        }
        return mainClassName;
    } else {
        throw new RuntimeException("Manifest file required");
    }
}
 
源代码12 项目: knopflerfish.org   文件: Archive.java
/**
 * Create an Archive based on contents of an InputStream, get file object for
 * the stream and use it. Native code is not allowed.
 *
 * @param is Jar file data in an InputStream.
 */
@SuppressWarnings("resource") // The input stream, is, must not be closed here.
Archive(BundleArchiveImpl ba, InputStream is) throws IOException {
  this.ba = ba;
  path = ".";
  final JarInputStream ji = new JarInputStream(is);
  manifest = ji.getManifest();
  if (manifest == null) {
    throw new IOException("Bundle manifest is missing");
  }
  content = loadJarStream(ji);
}
 
源代码13 项目: uavstack   文件: JarUtil.java
/**
 * 提取jar包的Manifest
 * 
 * @param jarFilePath
 * @return
 */
public static Manifest getJarManifest(String jarFilePath) {

    try {
        @SuppressWarnings("resource")
        JarInputStream jis = new JarInputStream(new FileInputStream(jarFilePath));
        return jis.getManifest();
    }
    catch (IOException e) {
        // ignore
    }
    return null;
}
 
源代码14 项目: TencentKona-8   文件: PackerImpl.java
void run(JarInputStream in, OutputStream out) throws IOException {
    // First thing we do is get the manifest, as JIS does
    // not provide the Manifest as an entry.
    if (in.getManifest() != null) {
        ByteArrayOutputStream tmp = new ByteArrayOutputStream();
        in.getManifest().write(tmp);
        InputStream tmpIn = new ByteArrayInputStream(tmp.toByteArray());
        pkg.addFile(readFile(JarFile.MANIFEST_NAME, tmpIn));
    }
    for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
        InFile inFile = new InFile(je);

        String name = inFile.name;
        Package.File bits = readFile(name, in);
        Package.File file = null;
        // (5078608) : discount the resource files in META-INF
        // from segment computation.
        long inflen = (isMetaInfFile(name))
                      ? 0L
                      : inFile.getInputLength();

        if ((segmentSize += inflen) > segmentLimit) {
            segmentSize -= inflen;
            int nextCount = -1;  // don't know; it's a stream
            flushPartial(out, nextCount);
        }
        if (verbose > 1) {
            Utils.log.fine("Reading " + name);
        }

        assert(je.isDirectory() == name.endsWith("/"));

        if (isClassFile(name)) {
            file = readClass(name, bits.getInputStream());
        }
        if (file == null) {
            file = bits;
            pkg.addFile(file);
        }
        inFile.copyTo(file);
        noteRead(inFile);
    }
    flushAll(out);
}
 
源代码15 项目: openjdk-jdk8u   文件: PackerImpl.java
void run(JarInputStream in, OutputStream out) throws IOException {
    // First thing we do is get the manifest, as JIS does
    // not provide the Manifest as an entry.
    if (in.getManifest() != null) {
        ByteArrayOutputStream tmp = new ByteArrayOutputStream();
        in.getManifest().write(tmp);
        InputStream tmpIn = new ByteArrayInputStream(tmp.toByteArray());
        pkg.addFile(readFile(JarFile.MANIFEST_NAME, tmpIn));
    }
    for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
        InFile inFile = new InFile(je);

        String name = inFile.name;
        Package.File bits = readFile(name, in);
        Package.File file = null;
        // (5078608) : discount the resource files in META-INF
        // from segment computation.
        long inflen = (isMetaInfFile(name))
                      ? 0L
                      : inFile.getInputLength();

        if ((segmentSize += inflen) > segmentLimit) {
            segmentSize -= inflen;
            int nextCount = -1;  // don't know; it's a stream
            flushPartial(out, nextCount);
        }
        if (verbose > 1) {
            Utils.log.fine("Reading " + name);
        }

        assert(je.isDirectory() == name.endsWith("/"));

        if (isClassFile(name)) {
            file = readClass(name, bits.getInputStream());
        }
        if (file == null) {
            file = bits;
            pkg.addFile(file);
        }
        inFile.copyTo(file);
        noteRead(inFile);
    }
    flushAll(out);
}
 
源代码16 项目: openjdk-jdk8u-backup   文件: PackerImpl.java
void run(JarInputStream in, OutputStream out) throws IOException {
    // First thing we do is get the manifest, as JIS does
    // not provide the Manifest as an entry.
    if (in.getManifest() != null) {
        ByteArrayOutputStream tmp = new ByteArrayOutputStream();
        in.getManifest().write(tmp);
        InputStream tmpIn = new ByteArrayInputStream(tmp.toByteArray());
        pkg.addFile(readFile(JarFile.MANIFEST_NAME, tmpIn));
    }
    for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
        InFile inFile = new InFile(je);

        String name = inFile.name;
        Package.File bits = readFile(name, in);
        Package.File file = null;
        // (5078608) : discount the resource files in META-INF
        // from segment computation.
        long inflen = (isMetaInfFile(name))
                      ? 0L
                      : inFile.getInputLength();

        if ((segmentSize += inflen) > segmentLimit) {
            segmentSize -= inflen;
            int nextCount = -1;  // don't know; it's a stream
            flushPartial(out, nextCount);
        }
        if (verbose > 1) {
            Utils.log.fine("Reading " + name);
        }

        assert(je.isDirectory() == name.endsWith("/"));

        if (isClassFile(name)) {
            file = readClass(name, bits.getInputStream());
        }
        if (file == null) {
            file = bits;
            pkg.addFile(file);
        }
        inFile.copyTo(file);
        noteRead(inFile);
    }
    flushAll(out);
}
 
源代码17 项目: jdk8u-dev-jdk   文件: PackerImpl.java
void run(JarInputStream in, OutputStream out) throws IOException {
    // First thing we do is get the manifest, as JIS does
    // not provide the Manifest as an entry.
    if (in.getManifest() != null) {
        ByteArrayOutputStream tmp = new ByteArrayOutputStream();
        in.getManifest().write(tmp);
        InputStream tmpIn = new ByteArrayInputStream(tmp.toByteArray());
        pkg.addFile(readFile(JarFile.MANIFEST_NAME, tmpIn));
    }
    for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
        InFile inFile = new InFile(je);

        String name = inFile.name;
        Package.File bits = readFile(name, in);
        Package.File file = null;
        // (5078608) : discount the resource files in META-INF
        // from segment computation.
        long inflen = (isMetaInfFile(name))
                      ? 0L
                      : inFile.getInputLength();

        if ((segmentSize += inflen) > segmentLimit) {
            segmentSize -= inflen;
            int nextCount = -1;  // don't know; it's a stream
            flushPartial(out, nextCount);
        }
        if (verbose > 1) {
            Utils.log.fine("Reading " + name);
        }

        assert(je.isDirectory() == name.endsWith("/"));

        if (isClassFile(name)) {
            file = readClass(name, bits.getInputStream());
        }
        if (file == null) {
            file = bits;
            pkg.addFile(file);
        }
        inFile.copyTo(file);
        noteRead(inFile);
    }
    flushAll(out);
}
 
源代码18 项目: jdk8u-jdk   文件: PackerImpl.java
void run(JarInputStream in, OutputStream out) throws IOException {
    // First thing we do is get the manifest, as JIS does
    // not provide the Manifest as an entry.
    if (in.getManifest() != null) {
        ByteArrayOutputStream tmp = new ByteArrayOutputStream();
        in.getManifest().write(tmp);
        InputStream tmpIn = new ByteArrayInputStream(tmp.toByteArray());
        pkg.addFile(readFile(JarFile.MANIFEST_NAME, tmpIn));
    }
    for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
        InFile inFile = new InFile(je);

        String name = inFile.name;
        Package.File bits = readFile(name, in);
        Package.File file = null;
        // (5078608) : discount the resource files in META-INF
        // from segment computation.
        long inflen = (isMetaInfFile(name))
                      ? 0L
                      : inFile.getInputLength();

        if ((segmentSize += inflen) > segmentLimit) {
            segmentSize -= inflen;
            int nextCount = -1;  // don't know; it's a stream
            flushPartial(out, nextCount);
        }
        if (verbose > 1) {
            Utils.log.fine("Reading " + name);
        }

        assert(je.isDirectory() == name.endsWith("/"));

        if (isClassFile(name)) {
            file = readClass(name, bits.getInputStream());
        }
        if (file == null) {
            file = bits;
            pkg.addFile(file);
        }
        inFile.copyTo(file);
        noteRead(inFile);
    }
    flushAll(out);
}
 
源代码19 项目: jdk8u_jdk   文件: PackerImpl.java
void run(JarInputStream in, OutputStream out) throws IOException {
    // First thing we do is get the manifest, as JIS does
    // not provide the Manifest as an entry.
    if (in.getManifest() != null) {
        ByteArrayOutputStream tmp = new ByteArrayOutputStream();
        in.getManifest().write(tmp);
        InputStream tmpIn = new ByteArrayInputStream(tmp.toByteArray());
        pkg.addFile(readFile(JarFile.MANIFEST_NAME, tmpIn));
    }
    for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
        InFile inFile = new InFile(je);

        String name = inFile.name;
        Package.File bits = readFile(name, in);
        Package.File file = null;
        // (5078608) : discount the resource files in META-INF
        // from segment computation.
        long inflen = (isMetaInfFile(name))
                      ? 0L
                      : inFile.getInputLength();

        if ((segmentSize += inflen) > segmentLimit) {
            segmentSize -= inflen;
            int nextCount = -1;  // don't know; it's a stream
            flushPartial(out, nextCount);
        }
        if (verbose > 1) {
            Utils.log.fine("Reading " + name);
        }

        assert(je.isDirectory() == name.endsWith("/"));

        if (isClassFile(name)) {
            file = readClass(name, bits.getInputStream());
        }
        if (file == null) {
            file = bits;
            pkg.addFile(file);
        }
        inFile.copyTo(file);
        noteRead(inFile);
    }
    flushAll(out);
}
 
源代码20 项目: openjdk-8   文件: PackerImpl.java
void run(JarInputStream in, OutputStream out) throws IOException {
    // First thing we do is get the manifest, as JIS does
    // not provide the Manifest as an entry.
    if (in.getManifest() != null) {
        ByteArrayOutputStream tmp = new ByteArrayOutputStream();
        in.getManifest().write(tmp);
        InputStream tmpIn = new ByteArrayInputStream(tmp.toByteArray());
        pkg.addFile(readFile(JarFile.MANIFEST_NAME, tmpIn));
    }
    for (JarEntry je; (je = in.getNextJarEntry()) != null; ) {
        InFile inFile = new InFile(je);

        String name = inFile.name;
        Package.File bits = readFile(name, in);
        Package.File file = null;
        // (5078608) : discount the resource files in META-INF
        // from segment computation.
        long inflen = (isMetaInfFile(name))
                      ? 0L
                      : inFile.getInputLength();

        if ((segmentSize += inflen) > segmentLimit) {
            segmentSize -= inflen;
            int nextCount = -1;  // don't know; it's a stream
            flushPartial(out, nextCount);
        }
        if (verbose > 1) {
            Utils.log.fine("Reading " + name);
        }

        assert(je.isDirectory() == name.endsWith("/"));

        if (isClassFile(name)) {
            file = readClass(name, bits.getInputStream());
        }
        if (file == null) {
            file = bits;
            pkg.addFile(file);
        }
        inFile.copyTo(file);
        noteRead(inFile);
    }
    flushAll(out);
}