当前位置: 首页>>代码示例>>Java>>正文


Java JarInputStream.getManifest方法代码示例

本文整理汇总了Java中java.util.jar.JarInputStream.getManifest方法的典型用法代码示例。如果您正苦于以下问题:Java JarInputStream.getManifest方法的具体用法?Java JarInputStream.getManifest怎么用?Java JarInputStream.getManifest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.util.jar.JarInputStream的用法示例。


在下文中一共展示了JarInputStream.getManifest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: copyJarFile

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
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
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:18,代码来源:Utils.java

示例2: extract

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
/**Find the jar I was loaded from and extract all entries except my own
  * class file.
  *@throws Exception if anything doesn't work, punt
  */
 public void extract() throws Exception {
   URL jarURL =
     this.getClass().getProtectionDomain().getCodeSource().getLocation();

   InputStream is = jarURL.openStream();
   JarInputStream jis = new JarInputStream( is);
   
   Manifest mf = null;

   for ( JarEntry je;; ) {
     je = jis.getNextJarEntry();
     if ( je == null )
     	break;
     if ( null == mf ) {
       mf = jis.getManifest();
if ( null != mf )
  setDefaults( mf.getMainAttributes());
     }
     if ( ! je.getName().equals( me) )
extract( je, jis);
     jis.closeEntry();
   }
   
   jis.close();
 }
 
开发者ID:greenplum-db,项目名称:pljava,代码行数:30,代码来源:JarX.java

示例3: loadMainClassFromClasspathJar

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
private static MainPair loadMainClassFromClasspathJar(File jarFile, String[] args) throws Exception {
  final JarInputStream inputStream = new JarInputStream(new FileInputStream(jarFile));
  try {
    final Manifest manifest = inputStream.getManifest();
    final String vmParams = manifest.getMainAttributes().getValue("VM-Options");
    if (vmParams != null) {
      final HashMap vmOptions = new HashMap();
      parseVmOptions(vmParams, vmOptions);
      for (Iterator iterator = vmOptions.keySet().iterator(); iterator.hasNext(); ) {
        String optionName = (String)iterator.next();
        System.setProperty(optionName, (String)vmOptions.get(optionName));
      }
    }
  }
  finally {
    if (inputStream != null) {
      inputStream.close();
    }
    jarFile.deleteOnExit();
  }

  return new MainPair(Class.forName(args[1]), new String[args.length - 2]);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:CommandLineWrapper.java

示例4: loadManifestClasspath

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
public static String[] loadManifestClasspath(File file) {
  try {
    JarInputStream inputStream = new JarInputStream(new FileInputStream(file));
    try {
      final Manifest manifest = inputStream.getManifest();
      if (manifest != null) {
        final String classPath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
        if (classPath != null) {
          return classPath.split(" ");
        }
      }
    }
    finally {
      inputStream.close();
    }
  }
  catch (Exception ignore) { }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:ClassPath.java

示例5: testManifestWithJarsAndDirectories

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
@Test
public void testManifestWithJarsAndDirectories() throws Exception {
  final File tempDirectory = FileUtil.createTempDirectory("dirWithClasses", "suffix");
  File jarFile = null;
  try {
    final List<String> paths = Arrays.asList(tempDirectory.getAbsolutePath(), tempDirectory.getAbsolutePath() + "/directory with spaces/some.jar");
    jarFile = CommandLineWrapperUtil.createClasspathJarFile(new Manifest(), paths);
    final JarInputStream inputStream = new JarInputStream(new FileInputStream(jarFile));
    final Manifest manifest = inputStream.getManifest();
    final String classPath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
    final String tempDirectoryUrl = tempDirectory.toURI().toURL().toString();
    assertTrue(tempDirectoryUrl, tempDirectoryUrl.endsWith("/"));
    assertEquals(tempDirectoryUrl + " " + tempDirectoryUrl +"directory%20with%20spaces/some.jar", classPath);
  }
  finally {
    FileUtil.delete(tempDirectory);
    if (jarFile != null) {
      FileUtil.delete(jarFile);
    }
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:CommandLineWrapperUtilTest.java

示例6: getBundleSymbolicName

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
/**
 * Get the symbolic name from a bundle file by looking at the manifest
 * @param bundleFile bundle file
 * @return the name extracted from the manifest
 * @throws IOException if reading the jar failed
 */
public static String getBundleSymbolicName(File bundleFile) throws IOException {
    String name = null;
    final JarInputStream jis = new JarInputStream(new FileInputStream(bundleFile));
    try {
        final Manifest m = jis.getManifest();
        if (m == null) {
            throw new IOException("Manifest is null in " + bundleFile.getAbsolutePath());
        }
        name = m.getMainAttributes().getValue(Constants.BUNDLE_SYMBOLICNAME);
    } finally {
        jis.close();
    }
    return name;
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-testing-clients,代码行数:21,代码来源:OsgiConsoleClient.java

示例7: getBundleVersionFromFile

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
/**
 * Get the version form a bundle file by looking at the manifest
 * @param bundleFile bundle file
 * @return the version
 * @throws IOException if reading the bundle jar failed
 */
public static String getBundleVersionFromFile(File bundleFile) throws IOException {
    String version = null;
    final JarInputStream jis = new JarInputStream(new FileInputStream(bundleFile));
    try {
        final Manifest m = jis.getManifest();
        if(m == null) {
            throw new IOException("Manifest is null in " + bundleFile.getAbsolutePath());
        }
        version = m.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
    } finally {
        jis.close();
    }
    return version;
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-testing-clients,代码行数:21,代码来源:OsgiConsoleClient.java

示例8: getJarManifest

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
/**
 * 提取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;
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:19,代码来源:JarUtil.java

示例9: getManifest

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
private Manifest getManifest() throws IOException {

	File mainJar = new File(outputDirectory, mainJarFilename + ".jar");
	JarInputStream in =
	    new JarInputStream(new FileInputStream(mainJar));
	Manifest mf = in.getManifest();
	if (mf != null) {
	    Manifest copy = new Manifest(mf);
	    in.close();
	    return copy;
	}
	in.close();
	return null;
    }
 
开发者ID:creditkarma,项目名称:maven-exec-jar-plugin,代码行数:15,代码来源:ExecJarMojo.java

示例10: JarLoader

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
/**
 * Creates a loader to load a specified JAR file.
 *
 * We place no restrictions on what the <code>URL</code> points to here.
 * instead any access restrictions (from trusted java) are enforced by
 * the <code>Security Manager</code> defined in <code>Backend.java</code>.
 *
 * @param url : The URL to load
 * @return JarLoader : Classloader for a specified JAR
 * @throws IOException : when the Jar cannot be read
 *
 */
JarLoader(ClassLoader parent, URL url) throws IOException
{
	super(parent);

	m_url = url;
	m_entries = new HashMap();
	m_images  = new HashMap();

	// Just having a JAR in your CLASSPATH will cause us to load it,
	// which means you need security access to it.
	JarInputStream jis = new JarInputStream(url.openStream());
	ByteArrayOutputStream img = new ByteArrayOutputStream();
	byte[] buf = new byte[1024];
	JarEntry je;
	for (je = jis.getNextJarEntry();
		 je != null;
		 je = jis.getNextJarEntry())
	{
		if (je.isDirectory())
			continue;
		String entryName = je.getName();
		Attributes attr = je.getAttributes();
		int nBytes;

		img.reset();
		while ((nBytes = jis.read(buf)) > 0)
			img.write(buf, 0, nBytes);
		jis.closeEntry();

		m_entries.put(entryName, img.toByteArray());
	}
	m_manifest = jis.getManifest();
}
 
开发者ID:greenplum-db,项目名称:pljava,代码行数:46,代码来源:JarLoader.java

示例11: createBundleVersion

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
/**
 * creates a bundle version object for a local jar file
 * uses symbolic name, name and version in the manifest
 */
private BundleVersion createBundleVersion(File file, String type) throws FileNotFoundException, IOException {
	JarInputStream jarStream = new JarInputStream(new FileInputStream(file));
	Manifest mf = jarStream.getManifest();
	
	Attributes attr = mf.getMainAttributes();
	String symName = attr.getValue("Bundle-SymbolicName");
	String version = attr.getValue("Bundle-Version");
	version = Utils.formatVersion(version);
	String name = attr.getValue("Bundle-Name");
	if(name.contains("%")) {
		name = symName;
	}
	jarStream.close();
	if(!localHandler.getLocalRepository().containsBundle(symName) || (localHandler.getLocalRepository().getBundle(symName, version) == null)) {
		PVBundle bundle = new PVBundle();
		bundle.setName(name);
		bundle.setSymbolicName(symName);
		bundle.setType(type);
		bundle.setSource("local installation");
		
		BundleVersion bVer = new BundleVersion();
		bVer.setBundle(bundle);
		bVer.setVersion(version);
		File destFile = new File(localHandler.getLocalRepository().getUrl(), symName + "-" + version + ".jar");
		Utils.copyFile(file, destFile);
		bVer.setJarFile(destFile.getAbsolutePath());
		return bVer;
	}
	return null;
}
 
开发者ID:PathVisio,项目名称:pathvisio,代码行数:35,代码来源:PluginManager.java

示例12: rewrite

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
private static File rewrite(File jar, String[] mavenCP, String classpath) throws IOException { // #190992
    String[] classpathEntries = tokenizePath(classpath);
    StringBuilder classPathHeader = new StringBuilder();
    for (String artifact : mavenCP) {
        String[] grpArtVers = artifact.split(":");
        String partOfPath = File.separatorChar + grpArtVers[0].replace('.', File.separatorChar) + File.separatorChar + grpArtVers[1] + File.separatorChar + grpArtVers[2] + File.separatorChar + grpArtVers[1] + '-' + grpArtVers[2];
        File dep = null;
        for (String classpathEntry : classpathEntries) {
            if (classpathEntry.endsWith(".jar") && classpathEntry.contains(partOfPath)) {
                dep = new File(classpathEntry);
                break;
            }
        }
        if (dep == null) {
            throw new IOException("no match for " + artifact + " found in " + classpath);
        }
        File depCopy = File.createTempFile(artifact.replace(':', '-') + '-', ".jar");
        depCopy.deleteOnExit();
        NbTestCase.copytree(dep, depCopy);
        if (classPathHeader.length() > 0) {
            classPathHeader.append(' ');
        }
        classPathHeader.append(depCopy.getName());
    }
    String n = jar.getName();
    int dot = n.lastIndexOf('.');
    File jarCopy = File.createTempFile(n.substring(0, dot) + '-', n.substring(dot));
    jarCopy.deleteOnExit();
    InputStream is = new FileInputStream(jar);
    try {
        OutputStream os = new FileOutputStream(jarCopy);
        try {
            JarInputStream jis = new JarInputStream(is);
            Manifest mani = new Manifest(jis.getManifest());
            mani.getMainAttributes().putValue("Class-Path", classPathHeader.toString());
            JarOutputStream jos = new JarOutputStream(os, mani);
            JarEntry entry;
            while ((entry = jis.getNextJarEntry()) != null) {
                if (entry.getName().matches("META-INF/.+[.]SF")) {
                    throw new IOException("cannot handle signed JARs");
                }
                jos.putNextEntry(entry);
                byte[] buf = new byte[4092];
                for (;;) {
                    int more = jis.read(buf, 0, buf.length);
                    if (more == -1) {
                        break;
                    }
                    jos.write(buf, 0, more);
                }
            }
            jis.close();
            jos.close();
        } finally {
            os.close();
        }
    } finally {
        is.close();
    }
    return jarCopy;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:62,代码来源:NbModuleSuite.java

示例13: run

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
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);
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:45,代码来源:PackerImpl.java

示例14: run

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
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 = (inFile.isMetaInfFile())
                      ? 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 (inFile.mustProcess()) {
            file = readClass(name, bits.getInputStream());
        }
        if (file == null) {
            file = bits;
            pkg.addFile(file);
        }
        inFile.copyTo(file);
        noteRead(inFile);
    }
    flushAll(out);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:45,代码来源:PackerImpl.java

示例15: main

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
public static final void main( String[] args ) throws IOException {

        if ( args.length != 2 ) {
            System.out.println( "usage: TestJarInsert jarFile insertFile" );
            System.exit( 1 );
        }
        String jarFileName = args[0];
        String insertFileName = args[1];

        // the file to insert
        File insertFile = new File( insertFileName );
        InputStream insertStream = new FileInputStream( insertFile );

        // the original JAR file
        File jarFile = new File( jarFileName );
        JarInputStream jarStream = new JarInputStream( new FileInputStream( jarFile ) );
        Manifest manifest = jarStream.getManifest();
        if ( manifest == null ) {
            System.out.println( "JAR file is missing manifest" );
            System.exit( 1 );
        }

        // output goes to a temp JAR file
        String tmpFileName = jarFileName + ".tmp";
        File tmpFile = new File( tmpFileName );
        JarOutputStream tmpStream = new JarOutputStream( new FileOutputStream( tmpFile ), manifest );

        byte[] buffer = new byte[1024];
        int bytesRead;
        
        // copy all entries from input to output, skipping the insert file if it already exists
        JarEntry jarEntry = jarStream.getNextJarEntry();
        while ( jarEntry != null ) {
            if ( !jarEntry.getName().equals( insertFileName ) ) {
                tmpStream.putNextEntry( jarEntry );
                while ( ( bytesRead = jarStream.read( buffer ) ) > 0 ) {
                    tmpStream.write( buffer, 0, bytesRead );
                }
            }
            jarEntry = jarStream.getNextJarEntry();
        }

        // add properties file to output
        jarEntry = new JarEntry( insertFileName );
        tmpStream.putNextEntry( jarEntry );
        while ( ( bytesRead = insertStream.read( buffer ) ) != -1 ) {
            tmpStream.write( buffer, 0, bytesRead );
        }

        // close the streams
        insertStream.close();
        jarStream.close();
        tmpStream.close();

        // if everything went OK, move tmp file to JAR file
        boolean renameSuccess = tmpFile.renameTo( jarFile );
        if ( !renameSuccess ) {
            System.err.println( "failed to rename " + tmpFileName + " to " + jarFileName );
            System.exit( 1 );
        }
    }
 
开发者ID:mleoking,项目名称:PhET,代码行数:62,代码来源:TestJarInsert.java


注:本文中的java.util.jar.JarInputStream.getManifest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。