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


Java JarInputStream.close方法代码示例

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


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

示例1: testNoManifest

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
@Test
public void testNoManifest() throws Exception {
  File dir = new File(System.getProperty("test.build.dir", "target/test-dir"),
                      TestJarFinder.class.getName() + "-testNoManifest");
  delete(dir);
  dir.mkdirs();
  File propsFile = new File(dir, "props.properties");
  Writer writer = new FileWriter(propsFile);
  new Properties().store(writer, "");
  writer.close();
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  JarOutputStream zos = new JarOutputStream(baos);
  JarFinder.jarDir(dir, "", zos);
  JarInputStream jis =
    new JarInputStream(new ByteArrayInputStream(baos.toByteArray()));
  Assert.assertNotNull(jis.getManifest());
  jis.close();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:19,代码来源:TestJarFinder.java

示例2: readManifest

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
@SuppressWarnings("PMD.EmptyCatchBlock")
private InputStream readManifest(InputStream binaryExtension) throws IOException {
    JarInputStream jar = new JarInputStream(binaryExtension);
    try {
        JarEntry entry;
        do {
            entry = jar.getNextJarEntry();
            if (entry != null && MANIFEST_LOCATION.equals(entry.getName())) {
                return jar;
            }
        } while (entry != null);

        jar.close();
        return null;
    } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception e) {
        try {
            jar.close();
        } catch (@SuppressWarnings("PMD.AvoidCatchingGenericException") Exception ex2) {
            // ignore
        }
        throw SyndesisServerException.launderThrowable(e);
    }
}
 
开发者ID:syndesisio,项目名称:syndesis,代码行数:24,代码来源:ExtensionAnalyzer.java

示例3: scanJar

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
protected void scanJar(URL jarUrl, Map<String, ResourceInfo> resInfos) throws IOException {
  JarInputStream jarInput = new JarInputStream(jarUrl.openStream(), false);
  JarEntry entry = null;
  while((entry = jarInput.getNextJarEntry()) != null) {
    String entryName = entry.getName();
    if(entryName != null && entryName.endsWith(".class")) {
      final String className = entryName.substring(0,
               entryName.length() - 6).replace('/', '.');
      if(!resInfos.containsKey(className)) {
        ClassReader classReader = new ClassReader(jarInput);
        ResourceInfo resInfo = new ResourceInfo(null, className, null);
        ResourceInfoVisitor visitor = new ResourceInfoVisitor(resInfo);

        classReader.accept(visitor, ClassReader.SKIP_CODE |
            ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
        if(visitor.isCreoleResource()) {
          resInfos.put(className, resInfo);
        }
      }
    }
  }

  jarInput.close();
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:25,代码来源:Plugin.java

示例4: tstConnectionToJarOnClassPath

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
public void tstConnectionToJarOnClassPath() throws Exception {
	URL url = bundle.getEntry("bundleclasspath/simple.jar");
	System.out.println("jar url is " + url);
	URLConnection con = url.openConnection();
	System.out.println(con);
	System.out.println(con.getContentType());
	InputStream stream = con.getInputStream();
	JarInputStream jis = new JarInputStream(stream);
	System.out.println(jis);
	System.out.println(jis.available());
	System.out.println(jis.getNextJarEntry());
	System.out.println(jis.getNextJarEntry());
	System.out.println(jis.getNextJarEntry());
	System.out.println(jis.available());
	System.out.println(jis.getNextJarEntry());
	System.out.println(jis.available());
	jis.close();
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:19,代码来源:BundleClassPathTest.java

示例5: pack

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
/**
 * Takes a JarInputStream and converts into a pack-stream.
 * <p>
 * Closes its input but not its output.  (Pack200 archives are appendable.)
 * <p>
 * The modification time and deflation hint attributes are not available,
 * for the jar-manifest file and the directory containing the file.
 *
 * @see #MODIFICATION_TIME
 * @see #DEFLATION_HINT
 * @param in a JarInputStream
 * @param out an OutputStream
 * @exception IOException if an error is encountered.
 */
public synchronized void pack(JarInputStream in, OutputStream out) throws IOException {
    assert(Utils.currentInstance.get() == null);
    TimeZone tz = (props.getBoolean(Utils.PACK_DEFAULT_TIMEZONE)) ? null :
        TimeZone.getDefault();
    try {
        Utils.currentInstance.set(this);
        if (tz != null) TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
        if ("0".equals(props.getProperty(Pack200.Packer.EFFORT))) {
            Utils.copyJarFile(in, out);
        } else {
            (new DoPack()).run(in, out);
        }
    } finally {
        Utils.currentInstance.set(null);
        if (tz != null) TimeZone.setDefault(tz);
        in.close();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:33,代码来源:PackerImpl.java

示例6: 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

示例7: pack

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
/**
 * Takes a JarInputStream and converts into a pack-stream.
 * <p>
 * Closes its input but not its output.  (Pack200 archives are appendable.)
 * <p>
 * The modification time and deflation hint attributes are not available,
 * for the jar-manifest file and the directory containing the file.
 *
 * @see #MODIFICATION_TIME
 * @see #DEFLATION_HINT
 * @param in a JarInputStream
 * @param out an OutputStream
 * @exception IOException if an error is encountered.
 */
public synchronized void pack(JarInputStream in, OutputStream out) throws IOException {
    assert (Utils.currentInstance.get() == null);
    boolean needUTC = !props.getBoolean(Utils.PACK_DEFAULT_TIMEZONE);
    try {
        Utils.currentInstance.set(this);
        if (needUTC) {
            Utils.changeDefaultTimeZoneToUtc();
        }
        if ("0".equals(props.getProperty(Pack200.Packer.EFFORT))) {
            Utils.copyJarFile(in, out);
        } else {
            (new DoPack()).run(in, out);
        }
    } finally {
        Utils.currentInstance.set(null);
        if (needUTC) {
            Utils.restoreDefaultTimeZone();
        }
        in.close();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:36,代码来源:PackerImpl.java

示例8: 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

示例9: 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

示例10: getFromJARFile

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
/**
 * 从jar包中加载class
 * @param loader
 * @param jar
 * @param packageName
 * @return
 * @throws IOException
 * @throws ClassNotFoundException
 */
private static Set<Class<?>> getFromJARFile(final ClassLoader loader, final String jar, final String packageName)
    throws IOException, ClassNotFoundException {
    final Set<Class<?>> classes = new HashSet<Class<?>>();
    final JarInputStream jarFile = new JarInputStream(new FileInputStream(jar));
    try {
        JarEntry jarEntry;
        do {
            jarEntry = jarFile.getNextJarEntry();
            if (jarEntry != null) {
                String className = jarEntry.getName();
                if (className.endsWith(".class") && getPackageName(className).equals(packageName)) {
                    className = stripFilenameExtension(className);
                        classes.add(Class.forName(className.replace('/', '.'), true, loader));
                }
            }
        } while (jarEntry != null);
    } finally {
        jarFile.close();
    }
    return classes;
}
 
开发者ID:codeWatching,项目名称:codePay,代码行数:31,代码来源:ReflectionUtils.java

示例11: main

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
public static final void main( String[] args ) {
    
    if ( args.length != 1 ) {
        System.out.println( "usage: TestReadJarEntries file.jar" );
        System.exit( 1 );
    }
    
    try {
        String jarFileName = args[0];
        InputStream inputStream = new FileInputStream( jarFileName );
        JarInputStream jarInputStream = new JarInputStream( inputStream );
        JarEntry jarEntry = jarInputStream.getNextJarEntry();
        while ( jarEntry != null ) {
            System.out.println( jarEntry.getName() );
            jarEntry = jarInputStream.getNextJarEntry();
        }
        jarInputStream.close();
    }
    catch ( IOException e ) {
        e.printStackTrace();
        System.exit( 1 );   
    }
}
 
开发者ID:mleoking,项目名称:PhET,代码行数:24,代码来源:TestReadJarEntries.java

示例12: 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

示例13: testExistingManifest

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
@Test
public void testExistingManifest() throws Exception {
  File dir = new File(System.getProperty("test.build.dir", "target/test-dir"),
                      TestJarFinder.class.getName() + "-testExistingManifest");
  delete(dir);
  dir.mkdirs();

  File metaInfDir = new File(dir, "META-INF");
  metaInfDir.mkdirs();
  File manifestFile = new File(metaInfDir, "MANIFEST.MF");
  Manifest manifest = new Manifest();
  OutputStream os = new FileOutputStream(manifestFile);
  manifest.write(os);
  os.close();

  File propsFile = new File(dir, "props.properties");
  Writer writer = new FileWriter(propsFile);
  new Properties().store(writer, "");
  writer.close();
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  JarOutputStream zos = new JarOutputStream(baos);
  JarFinder.jarDir(dir, "", zos);
  JarInputStream jis =
    new JarInputStream(new ByteArrayInputStream(baos.toByteArray()));
  Assert.assertNotNull(jis.getManifest());
  jis.close();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:28,代码来源:TestJarFinder.java

示例14: extractClassesFromJAR

import java.util.jar.JarInputStream; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private static List<Class<Class>> extractClassesFromJAR(File jar, ClassLoader cl) throws IOException { 
    List<Class<Class>> classes = new ArrayList<Class<Class>>();
    JarInputStream jaris = new JarInputStream(new FileInputStream(jar));
    JarEntry ent = null;
    while ((ent = jaris.getNextJarEntry()) != null) {
        if (ent.getName().toLowerCase().endsWith(".class")) {
            try {
                Class<Class> cls = (Class<Class>) cl.loadClass(ent.getName().substring(0, ent.getName().length() - 6).replace('/', '.'));
                if (JPluginLoader.isPluggableClass(cls)) {
                    classes.add((Class<Class>)cls);
                }
            } catch (ClassNotFoundException e) {
                String msg = "";
                if(lang != null) {
                    msg = String.format(lang.getProperty("cant_load_class", "Could not load Class \"%s\""), ent.getName());
                } else {
                    msg = "Can't load Class " + ent.getName();
                }
                if(logger != null) {
                    logger.logErr(msg, false);
                } else {
                    System.err.println(msg);
                }
                e.printStackTrace();
            }
        }
    }
    jaris.close();
    return classes;
}
 
开发者ID:Panzer1119,项目名称:JAddOn,代码行数:32,代码来源:JPluginLoader.java

示例15: 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


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