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


Java JarFile.getInputStream方法代码示例

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


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

示例1: findClassInJarFile

import java.util.jar.JarFile; //导入方法依赖的package包/类
protected Class<?> findClassInJarFile(String qualifiedClassName) throws ClassNotFoundException {
    URI classUri = URIUtil.buildUri(StandardLocation.CLASS_OUTPUT, qualifiedClassName);
    String internalClassName = classUri.getPath().substring(1);
    JarFile jarFile = null;
    try {
        for (int i = 0; i < jarFiles.size(); i++) {
            jarFile = jarFiles.get(i);
            JarEntry jarEntry = jarFile.getJarEntry(internalClassName);
            if (jarEntry != null) {
                InputStream inputStream = jarFile.getInputStream(jarEntry);
                try {
                    byte[] byteCode = new byte[(int) jarEntry.getSize()];
                    ByteStreams.read(inputStream, byteCode, 0, byteCode.length);
                    return defineClass(qualifiedClassName, byteCode, 0, byteCode.length);
                } finally {
                    Closeables.closeQuietly(inputStream);
                }
            }
        }
    } catch (IOException e) {
        throw new IllegalStateException(String.format("Failed to lookup class %s in jar file %s", qualifiedClassName, jarFile), e);
    }
    return null;
}
 
开发者ID:twosigma,项目名称:beaker-notebook-archive,代码行数:25,代码来源:SimpleClassLoader.java

示例2: getAllFilesHash

import java.util.jar.JarFile; //导入方法依赖的package包/类
private Set<MFEntry> getAllFilesHash(JarFile jar) throws Exception {
	Set<MFEntry> fileSet = new HashSet<MFEntry>();
	Enumeration<java.util.jar.JarEntry> entries = jar.entries();
	while (entries.hasMoreElements()) {
		java.util.jar.JarEntry entry = entries.nextElement();
		String entryName = entry.getName();

		MFEntry mf = new MFEntry();
		if (!entry.isDirectory() && !entryName.endsWith(".MF") && !entryName.endsWith(".SF")
				&& !entryName.endsWith(".RSA") && !entryName.endsWith(".DSA") && !entryName.endsWith(".EC")) {
			InputStream ios = jar.getInputStream(entry);
			byte[] b = new byte[ios.available()];
			Streams.readFully(ios, b);
			mf.setFileName(entry.getName());
			mf.setDigestValue(
					java.util.Base64.getEncoder().encodeToString(EncryptUtils.sha(b, getShaTypeByMFFile())));
			collectJarFileName.add(entry.getName());
			fileSet.add(mf);
			ios.close();
		}
	}
	return fileSet;
}
 
开发者ID:mugua2015,项目名称:VerifySignedJar,代码行数:24,代码来源:VerifyJarHelper.java

示例3: processEntry

import java.util.jar.JarFile; //导入方法依赖的package包/类
private static void processEntry(JobManager jobManager, JarFile jarFile, JarEntry jarEntry, JarOutputStream jarOutputStream, Map<String, String> replacements) {
    if (jarEntry.getName().equals("META-INF/MANIFEST.MF"))
        return;

    try (DataInputStream inputStream = new DataInputStream(new BufferedInputStream(jarFile.getInputStream(jarEntry)))) {

        if (!jarEntry.getName().endsWith(".class")) {
            jarOutputStream.putNextEntry(jarEntry);

            int count;
            byte[] buffer = new byte[1024];

            while ((count = inputStream.read(buffer)) > 0)
                jarOutputStream.write(buffer, 0, count);

            jarOutputStream.closeEntry();
        } else
            jobManager.scheduleJob(new InjectionJob(jarEntry.getName(), inputStream, replacements));

    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:Yamakaja,项目名称:jar-injector,代码行数:24,代码来源:Bootstrap.java

示例4: getFromJarFile

import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
 * Browse a jar file for the desired class.
 * @param jarFile The jar file to browse.
 * @param name The full name of the class to find.
 * @return A ClassFile in case of success, null otherwise.
 * @throws ClassFileException Thrown on fatal errors loading or parsing a class file.
 * @throws IOException Thrown on fatal problems reading or writing to the file system.
 */
private ClassFile getFromJarFile(JarFile jarFile, String name) throws ClassFileException, IOException {
	Enumeration<JarEntry> entries = jarFile.entries();
	while (entries.hasMoreElements()) {
		/*
		 * Just browse trough all entries, they probably will not be shown hierarchically or in
		 * a sorted order.
		 */
		JarEntry entry = entries.nextElement();
		if (entry != null && entry.getName().equals(name)) {
			// Construct the full path to the class file.
			String fullPath = jarFile.getName() + "|" + entry.getName();

			// Return the ClassFile.
			try {
				return new ClassFile(this, jarFile.getInputStream(entry), jarFile
						.getInputStream(entry), entry.getSize(), fullPath);
			} catch(Exception e) {
				e.printStackTrace();
				return null;
			}
		}
	}
	return null;
}
 
开发者ID:wwu-pi,项目名称:tap17-muggl-javaee,代码行数:33,代码来源:MugglClassLoader.java

示例5: testIndexV1WithOldTimestamp

import java.util.jar.JarFile; //导入方法依赖的package包/类
@Test(expected = RepoUpdater.UpdateException.class)
public void testIndexV1WithOldTimestamp() throws IOException, RepoUpdater.UpdateException {
    Repo repo = MultiRepoUpdaterTest.createRepo("Testy", TESTY_JAR, context, TESTY_CERT);
    repo.timestamp = System.currentTimeMillis() / 1000;
    IndexV1Updater updater = new IndexV1Updater(context, repo);
    JarFile jarFile = new JarFile(TestUtils.copyResourceToTempFile(TESTY_JAR), true);
    JarEntry indexEntry = (JarEntry) jarFile.getEntry(IndexV1Updater.DATA_FILE_NAME);
    InputStream indexInputStream = jarFile.getInputStream(indexEntry);
    updater.processIndexV1(indexInputStream, indexEntry, "fakeEtag");
    fail(); // it should never reach here, it should throw a SigningException
    getClass().getResourceAsStream("foo");
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:13,代码来源:IndexV1UpdaterTest.java

示例6: copyJarFile

import java.util.jar.JarFile; //导入方法依赖的package包/类
static void copyJarFile(JarFile in, JarOutputStream out) throws IOException {
    byte[] buffer = new byte[1 << 14];
    for (JarEntry je : Collections.list(in.entries())) {
        out.putNextEntry(je);
        InputStream ein = in.getInputStream(je);
        for (int nr; 0 < (nr = ein.read(buffer)); ) {
            out.write(buffer, 0, nr);
        }
    }
    in.close();
    markJarFile(out);  // add PACK200 comment
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:Utils.java

示例7: readClassFile

import java.util.jar.JarFile; //导入方法依赖的package包/类
protected ClassFile readClassFile(JarFile jarfile, JarEntry e) throws IOException {
    InputStream is = null;
    try {
        is = jarfile.getInputStream(e);
        return ClassFile.read(is);
    } catch (ConstantPoolException ex) {
        throw new ClassFileError(ex);
    } finally {
        if (is != null)
            is.close();
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:13,代码来源:ClassFileReader.java

示例8: getClass

import java.util.jar.JarFile; //导入方法依赖的package包/类
private static CtClass getClass(JarFile jar, JarEntry entry) throws IOException, NotFoundException {
	// read the class into a buffer
	ByteArrayOutputStream bos = new ByteArrayOutputStream();
	byte[] buf = new byte[Constants.KiB];
	int totalNumBytesRead = 0;
	InputStream in = jar.getInputStream(entry);
	while (in.available() > 0) {
		int numBytesRead = in.read(buf);
		if (numBytesRead < 0) {
			break;
		}
		bos.write(buf, 0, numBytesRead);
		
		// sanity checking
		totalNumBytesRead += numBytesRead;
		if (totalNumBytesRead > Constants.MiB) {
			throw new Error("Class file " + entry.getName() + " larger than 1 MiB! Something is wrong!");
		}
	}
	
	// get a javassist handle for the class
	String className = Descriptor.toJavaName(getClassEntry(entry).getName());
	ClassPool classPool = new ClassPool();
	classPool.appendSystemPath();
	classPool.insertClassPath(new ByteArrayClassPath(className, bos.toByteArray()));
	return classPool.get(className);
}
 
开发者ID:cccssw,项目名称:enigma-vk,代码行数:28,代码来源:JarClassIterator.java

示例9: testIndexV1WithWrongCert

import java.util.jar.JarFile; //导入方法依赖的package包/类
@Test(expected = RepoUpdater.SigningException.class)
public void testIndexV1WithWrongCert() throws IOException, RepoUpdater.UpdateException {
    String badCert = "308202ed308201d5a003020102020426ffa009300d06092a864886f70d01010b05003027310b300906035504061302444531183016060355040a130f4e4f47415050532050726f6a656374301e170d3132313030363132303533325a170d3337303933303132303533325a3027310b300906035504061302444531183016060355040a130f4e4f47415050532050726f6a65637430820122300d06092a864886f70d01010105000382010f003082010a02820101009a8d2a5336b0eaaad89ce447828c7753b157459b79e3215dc962ca48f58c2cd7650df67d2dd7bda0880c682791f32b35c504e43e77b43c3e4e541f86e35a8293a54fb46e6b16af54d3a4eda458f1a7c8bc1b7479861ca7043337180e40079d9cdccb7e051ada9b6c88c9ec635541e2ebf0842521c3024c826f6fd6db6fd117c74e859d5af4db04448965ab5469b71ce719939a06ef30580f50febf96c474a7d265bb63f86a822ff7b643de6b76e966a18553c2858416cf3309dd24278374bdd82b4404ef6f7f122cec93859351fc6e5ea947e3ceb9d67374fe970e593e5cd05c905e1d24f5a5484f4aadef766e498adf64f7cf04bddd602ae8137b6eea40722d0203010001a321301f301d0603551d0e04160414110b7aa9ebc840b20399f69a431f4dba6ac42a64300d06092a864886f70d01010b0500038201010007c32ad893349cf86952fb5a49cfdc9b13f5e3c800aece77b2e7e0e9c83e34052f140f357ec7e6f4b432dc1ed542218a14835acd2df2deea7efd3fd5e8f1c34e1fb39ec6a427c6e6f4178b609b369040ac1f8844b789f3694dc640de06e44b247afed11637173f36f5886170fafd74954049858c6096308fc93c1bc4dd5685fa7a1f982a422f2a3b36baa8c9500474cf2af91c39cbec1bc898d10194d368aa5e91f1137ec115087c31962d8f76cd120d28c249cf76f4c70f5baa08c70a7234ce4123be080cee789477401965cfe537b924ef36747e8caca62dfefdd1a6288dcb1c4fd2aaa6131a7ad254e9742022cfd597d2ca5c660ce9e41ff537e5a4041e37"; // NOCHECKSTYLE LineLength
    Repo repo = MultiRepoUpdaterTest.createRepo("Testy", TESTY_JAR, context, badCert);
    IndexV1Updater updater = new IndexV1Updater(context, repo);
    JarFile jarFile = new JarFile(TestUtils.copyResourceToTempFile(TESTY_JAR), true);
    JarEntry indexEntry = (JarEntry) jarFile.getEntry(IndexV1Updater.DATA_FILE_NAME);
    InputStream indexInputStream = jarFile.getInputStream(indexEntry);
    updater.processIndexV1(indexInputStream, indexEntry, "fakeEtag");
    fail(); // it should never reach here, it should throw a SigningException
    getClass().getResourceAsStream("foo");
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:13,代码来源:IndexV1UpdaterTest.java

示例10: unJar

import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
 * Unpack matching files from a jar. Entries inside the jar that do
 * not match the given pattern will be skipped.
 *
 * @param jarFile the .jar file to unpack
 * @param toDir the destination directory into which to unpack the jar
 * @param unpackRegex the pattern to match jar entries against
 */
public static void unJar(File jarFile, File toDir, Pattern unpackRegex)
  throws IOException {
  JarFile jar = new JarFile(jarFile);
  try {
    Enumeration<JarEntry> entries = jar.entries();
    while (entries.hasMoreElements()) {
      final JarEntry entry = entries.nextElement();
      if (!entry.isDirectory() &&
          unpackRegex.matcher(entry.getName()).matches()) {
        InputStream in = jar.getInputStream(entry);
        try {
          File file = new File(toDir, entry.getName());
          ensureDirectory(file.getParentFile());
          OutputStream out = new FileOutputStream(file);
          try {
            IOUtils.copyBytes(in, out, 8192);
          } finally {
            out.close();
          }
        } finally {
          in.close();
        }
      }
    }
  } finally {
    jar.close();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:37,代码来源:RunJar.java

示例11: readClassFile

import java.util.jar.JarFile; //导入方法依赖的package包/类
protected ClassFile readClassFile(JarFile jarfile, JarEntry e) throws IOException {
    try (InputStream is = jarfile.getInputStream(e)) {
        ClassFile cf = ClassFile.read(is);
        if (jarfile.isMultiRelease()) {
            VersionHelper.add(jarfile, e, cf);
        }
        return cf;
    } catch (ConstantPoolException ex) {
        throw new ClassFileError(ex);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:ClassFileReader.java

示例12: fakeOSGiInfoXml

import java.util.jar.JarFile; //导入方法依赖的package包/类
/**
 * Create the equivalent of {@code Info/info.xml} for an OSGi bundle.
 * @param jar a bundle
 * @return a {@code <module ...><manifest .../></module>} valid according to
 *         <a href="http://www.netbeans.org/dtds/autoupdate-info-2_5.dtd">DTD</a>
 */
private Element fakeOSGiInfoXml(JarFile jar, File whereFrom) throws IOException {
    Attributes attr = jar.getManifest().getMainAttributes();
    Properties localized = new Properties();
    String bundleLocalization = attr.getValue("Bundle-Localization");
    if (bundleLocalization != null) {
        try (InputStream is = jar.getInputStream(jar.getEntry(bundleLocalization + ".properties"))) {
            localized.load(is);
        }
    }
    return fakeOSGiInfoXml(attr, localized, whereFrom);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:18,代码来源:MakeUpdateDesc.java

示例13: processDownloadedFile

import java.util.jar.JarFile; //导入方法依赖的package包/类
public void processDownloadedFile(File downloadedFile) throws UpdateException {
    InputStream indexInputStream = null;
    try {
        if (downloadedFile == null || !downloadedFile.exists()) {
            throw new UpdateException(repo, downloadedFile + " does not exist!");
        }

        // Due to a bug in Android 5.0 Lollipop, the inclusion of spongycastle causes
        // breakage when verifying the signature of the downloaded .jar. For more
        // details, check out https://gitlab.com/fdroid/fdroidclient/issues/111.
        FDroidApp.disableSpongyCastleOnLollipop();

        JarFile jarFile = new JarFile(downloadedFile, true);
        JarEntry indexEntry = (JarEntry) jarFile.getEntry("index.xml");
        indexInputStream = new ProgressBufferedInputStream(jarFile.getInputStream(indexEntry),
                processIndexListener, new URL(repo.address), (int) indexEntry.getSize());

        // Process the index...
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setNamespaceAware(true);
        final SAXParser parser = factory.newSAXParser();
        final XMLReader reader = parser.getXMLReader();
        final RepoXMLHandler repoXMLHandler = new RepoXMLHandler(repo, createIndexReceiver());
        reader.setContentHandler(repoXMLHandler);
        reader.parse(new InputSource(indexInputStream));

        long timestamp = repoDetailsToSave.getAsLong(RepoTable.Cols.TIMESTAMP);
        if (timestamp < repo.timestamp) {
            throw new UpdateException(repo, "index.jar is older that current index! "
                    + timestamp + " < " + repo.timestamp);
        }

        signingCertFromJar = getSigningCertFromJar(indexEntry);

        // JarEntry can only read certificates after the file represented by that JarEntry
        // has been read completely, so verification cannot run until now...
        assertSigningCertFromXmlCorrect();
        commitToDb();
    } catch (SAXException | ParserConfigurationException | IOException e) {
        throw new UpdateException(repo, "Error parsing index", e);
    } finally {
        FDroidApp.enableSpongyCastleOnLollipop();
        Utils.closeQuietly(indexInputStream);
        if (downloadedFile != null) {
            if (!downloadedFile.delete()) {
                Log.w(TAG, "Couldn't delete file: " + downloadedFile.getAbsolutePath());
            }
        }
    }
}
 
开发者ID:uhuru-mobile,项目名称:mobile-store,代码行数:51,代码来源:RepoUpdater.java

示例14: copyJarResourcesRecursively

import java.util.jar.JarFile; //导入方法依赖的package包/类
public static boolean copyJarResourcesRecursively(
        final File destDir, final JarURLConnection jarConnection
) throws IOException {

    final JarFile jarFile = jarConnection.getJarFile();

    for (final Enumeration<JarEntry> e = jarFile.entries(); e.hasMoreElements(); ) {
        final JarEntry entry = e.nextElement();
        if (entry.getName().startsWith(jarConnection.getEntryName())) {
            final String filename = StringUtils.removeStart(
                    entry.getName(), //
                    jarConnection.getEntryName());

            final File f = new File(destDir, filename);
            if (!entry.isDirectory()) {
                final InputStream entryInputStream = jarFile.getInputStream(entry);
                if (!FileUtils.copyStream(entryInputStream, f)) {
                    return false;
                }
                entryInputStream.close();
            } else {
                if (!FileUtils.ensureDirectoryExists(f)) {
                    throw new IOException("Could not create directory: " + f.getAbsolutePath());
                }
            }
        }
    }
    return true;
}
 
开发者ID:airsonic,项目名称:airsonic,代码行数:30,代码来源:FileUtils.java

示例15: read

import java.util.jar.JarFile; //导入方法依赖的package包/类
static Map<String,byte[]> read(File jar) throws IOException {
    JarFile jf = new JarFile(jar, false);
    try {
        Map<String, byte[]> classfiles = new TreeMap<String, byte[]>();
        Enumeration<JarEntry> e = jf.entries();
        while (e.hasMoreElements()) {
            JarEntry entry = e.nextElement();
            String name = entry.getName();
            if (!name.endsWith(".class")) {
                continue;
            }
            String clazz = name.substring(0, name.length() - 6);
            ByteArrayOutputStream baos = new ByteArrayOutputStream(Math.max((int) entry.getSize(), 0));
            InputStream is = jf.getInputStream(entry);
            try {
                FileUtil.copy(is, baos);
            } finally {
                is.close();
            }
            classfiles.put(clazz, baos.toByteArray());
        }
        return classfiles;
    } catch (SecurityException x) {
        throw new IOException(x);
    } finally {
        jf.close();
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:29,代码来源:ClassDependencyIndexCreator.java


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