當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。