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


Java JarInputStream类代码示例

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


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

示例1: readJar

import java.util.jar.JarInputStream; //导入依赖的package包/类
public static Application readJar(Path path) throws IOException {
	Application application = new Application();

	try (JarInputStream in = new JarInputStream(new BufferedInputStream(Files.newInputStream(path)))) {
		JarEntry entry;
		while ((entry = in.getNextJarEntry()) != null) {
			String name = entry.getName();
			if (!name.endsWith(".class")) continue;

			name = name.replaceAll(".class$", "");

			ClassNode node = new ClassNode();
			ClassReader reader = new ClassReader(in);
			reader.accept(node, ClassReader.SKIP_DEBUG);

			application.classes.put(name, node);
		}
	}

	return application;
}
 
开发者ID:jonathanedgecombe,项目名称:mithril,代码行数:22,代码来源:Application.java

示例2: processJar

import java.util.jar.JarInputStream; //导入依赖的package包/类
/**
 * Store all class names found in this jar file
 */
private static LinkedList<String> processJar(File jarfile, String basepath) {
	// System.out.println("Processing JAR " + jarfile.getPath());
	LinkedList<String> addlist = new LinkedList<String>();
	try {
		JarInputStream jarIS = new JarInputStream(new FileInputStream(
				jarfile));

		JarEntry entry = null;
		while ((entry = jarIS.getNextJarEntry()) != null) {
			String name = entry.getName();
			if (name.endsWith(".class")) {
				// System.out.println( entry.getAttributes().toString() );
				if (!add(name, jarfile.getPath(), basepath).isEmpty())
					addlist.addAll(add(name, jarfile.getPath(), basepath));
			}
		}
	} catch (Exception e) {
	}
	return addlist;
}
 
开发者ID:etomica,项目名称:etomica,代码行数:24,代码来源:Lister.java

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

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

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

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

示例7: dumpJarContent

import java.util.jar.JarInputStream; //导入依赖的package包/类
/**
 * Dumps the entries of a jar and return them as a String. This method can
 * be memory expensive depending on the jar size.
 * 
 * @param jis
 * @return
 * @throws Exception
 */
public static String dumpJarContent(JarInputStream jis) {
	StringBuilder buffer = new StringBuilder();

	try {
		JarEntry entry;
		while ((entry = jis.getNextJarEntry()) != null) {
			buffer.append(entry.getName());
			buffer.append("\n");
		}
	}
	catch (IOException ioException) {
		buffer.append("reading from stream failed");
	}
	finally {
		closeStream(jis);
	}

	return buffer.toString();
}
 
开发者ID:eclipse,项目名称:gemini.blueprint,代码行数:28,代码来源:JarUtils.java

示例8: assertExistingJarFile

import java.util.jar.JarInputStream; //导入依赖的package包/类
private void assertExistingJarFile(Path mtaArchiveFile, String fileName, String expectedContent) throws Exception {
    try (JarInputStream in = new JarInputStream(Files.newInputStream(mtaArchiveFile))) {
        for (ZipEntry e; (e = in.getNextEntry()) != null;) {
            if (fileName.equals(e.getName()) && !e.isDirectory()) {
                StringBuilder textBuilder = new StringBuilder();
                try (Reader reader = new BufferedReader(new InputStreamReader(in))) {
                    int c = 0;
                    while ((c = reader.read()) != -1) {
                        textBuilder.append((char) c);
                    }
                }
                assertEquals(expectedContent, textBuilder.toString());
                return;
            }
        }
        throw new AssertionError(MessageFormat.format("Zip archive file \"{0}\" could not be found", fileName));
    }
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:19,代码来源:MtaArchiveBuilderTest.java

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

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

示例11: pakArchiefBestandUit

import java.util.jar.JarInputStream; //导入依赖的package包/类
private Set<String> pakArchiefBestandUit(final Path tmpFolder) {
    getLog().debug("Unpacking artifact");
    Set<String> keys = new TreeSet<>();
    try (final JarInputStream archiefStream = new JarInputStream(new FileInputStream(artifact + ".bak"))) {

        final List<String> bestanden = new ArrayList<>();
        JarEntry archiefItem = archiefStream.getNextJarEntry();
        while (archiefItem != null) {
            final File archiefBestand = new File(tmpFolder.toFile(), archiefItem.getName());
            if (archiefItem.isDirectory()) {
                archiefBestand.mkdirs();
            } else {
                pakBestandUit(archiefStream, archiefBestand);
            }
            bestanden.add(archiefItem.getName());
            archiefStream.closeEntry();
            archiefItem = archiefStream.getNextJarEntry();
        }

        pakManifestUit(tmpFolder, archiefStream, bestanden);
        keys.addAll(bestanden);
    } catch (IOException | WrappedException e) {
        getLog().debug("Artifact cannot be fixed", e);
    }
    return keys;
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:27,代码来源:TimestampMojo.java

示例12: pakBestandUit

import java.util.jar.JarInputStream; //导入依赖的package包/类
private void pakBestandUit(final JarInputStream archiefStream, final File archiefBestand) throws IOException {
    final File parentBestand =
            new File(archiefBestand.getAbsolutePath().substring(0, archiefBestand.getAbsolutePath().lastIndexOf(File.separator)));
    parentBestand.mkdirs();
    if (archiefBestand.createNewFile()) {
        try (final FileOutputStream fos = new FileOutputStream(archiefBestand);
             final BufferedOutputStream bos = new BufferedOutputStream(fos)) {
            int len;
            byte[] buffer = new byte[BUFFER_SIZE];
            while ((len = archiefStream.read(buffer)) > 0) {
                bos.write(buffer, 0, len);
            }
            bos.flush();
        }
    }
}
 
开发者ID:MinBZK,项目名称:OperatieBRP,代码行数:17,代码来源:TimestampMojo.java

示例13: publicize

import java.util.jar.JarInputStream; //导入依赖的package包/类
private static void publicize(Path inPath, Path outPath) throws IOException {
	try (JarInputStream in = new JarInputStream(Files.newInputStream(inPath))) {
		try (JarOutputStream out = new JarOutputStream(Files.newOutputStream(outPath))) {
			JarEntry entry;
			while ((entry = in.getNextJarEntry()) != null) {
				if (entry.isDirectory()) {
					continue;
				}

				String name = entry.getName();
				out.putNextEntry(new JarEntry(name));

				if (name.endsWith(".class")) {
					ClassWriter writer = new ClassWriter(0);

					ClassReader reader = new ClassReader(in);
					reader.accept(new CheckClassAdapter(new ClassDefinalizer(new ClassPublicizer(writer)), true), 0);

					out.write(writer.toByteArray());
				} else {
					ByteStreams.copy(in, out);
				}
			}
		}
	}
}
 
开发者ID:jonathanedgecombe,项目名称:anvil,代码行数:27,代码来源:Publicizer.java

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

示例15: main

import java.util.jar.JarInputStream; //导入依赖的package包/类
public static void main(String...args) throws Throwable {
    try (JarInputStream jis = new JarInputStream(
             new FileInputStream(System.getProperty("test.src", ".") +
                                 System.getProperty("file.separator") +
                                 "BadSignedJar.jar")))
    {
        JarEntry je1 = jis.getNextJarEntry();
        while(je1!=null){
            System.out.println("Jar Entry1==>"+je1.getName());
            je1 = jis.getNextJarEntry(); // This should throw Security Exception
        }
        throw new RuntimeException(
            "Test Failed:Security Exception not being thrown");
    } catch (IOException ie){
        ie.printStackTrace();
    } catch (SecurityException e) {
        System.out.println("Test passed: Security Exception thrown as expected");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:20,代码来源:TestIndexedJarWithBadSignature.java


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