java.util.jar.JarInputStream#read ( )源码实例Demo

下面列出了java.util.jar.JarInputStream#read ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: Utils.java
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
}
 
源代码2 项目: TencentKona-8   文件: Utils.java
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
}
 
源代码3 项目: jdk8u-jdk   文件: Utils.java
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
}
 
源代码4 项目: jdk8u-dev-jdk   文件: Utils.java
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
}
 
源代码5 项目: metron   文件: MergeAndShadeTransformer.java
/**
 * Merges two jars.  The first jar will get merged into the output jar.
 * A running set of jar entries is kept so that duplicates are skipped.
 * This has the side-effect that the first instance of a given entry will be added
 * and all subsequent entries are skipped.
 *
 * @param jin The input jar
 * @param jout The output jar
 * @param entries The set of existing entries.  Note that this set will be mutated as part of this call.
 * @return The set of entries.
 * @throws IOException
 */
private Set<String> copy(JarInputStream jin, JarOutputStream jout, Set<String> entries) throws IOException {
  byte[] buffer = new byte[1024];
  for(JarEntry entry = jin.getNextJarEntry(); entry != null; entry = jin.getNextJarEntry()) {
    if(entries.contains(entry.getName())) {
      continue;
    }
    LOG.debug("Merging jar entry {}", entry.getName());
    entries.add(entry.getName());
    jout.putNextEntry(entry);
    int len = 0;
    while( (len = jin.read(buffer)) > 0 ) {
      jout.write(buffer, 0, len);
    }
  }
  return entries;
}
 
源代码6 项目: openjdk-jdk8u-backup   文件: Utils.java
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
}
 
源代码7 项目: openjdk-jdk9   文件: Utils.java
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
}
 
源代码8 项目: jdk8u-jdk   文件: Utils.java
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
}
 
源代码9 项目: JReFrameworker   文件: JarModifier.java
public byte[] extractEntry(String entry) throws IOException {
	JarInputStream zin = new JarInputStream(new BufferedInputStream(new FileInputStream(jarFile)));
	JarEntry currentEntry = null;
	while ((currentEntry = zin.getNextJarEntry()) != null) {
		if (currentEntry.getName().equals(entry)) {
			// currentEntry.getSize() may not be accurate, so read bytes into a stream first
			ByteArrayOutputStream baos = new ByteArrayOutputStream();
			byte[] buf = new byte[4096];
			while (true) {
				int n = zin.read(buf);
				if (n < 0){
					break;
				}
				baos.write(buf, 0, n);
			}
			zin.close();
			return baos.toByteArray();
		}
	}
	zin.close();
	return null;
}
 
源代码10 项目: hottub   文件: Utils.java
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
}
 
源代码11 项目: openjdk-8-source   文件: Utils.java
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
}
 
源代码12 项目: openjdk-8   文件: Utils.java
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
}
 
源代码13 项目: jdk8u_jdk   文件: Utils.java
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
}
 
源代码14 项目: flink   文件: JarHelper.java
/**
 * Given an InputStream on a jar file, unjars the contents into the given
 * directory.
 */
public void unjar(InputStream in, File destDir) throws IOException {
	BufferedOutputStream dest = null;
	JarInputStream jis = new JarInputStream(in);
	JarEntry entry;
	while ((entry = jis.getNextJarEntry()) != null) {
		if (entry.isDirectory()) {
			File dir = new File(destDir, entry.getName());
			dir.mkdir();
			if (entry.getTime() != -1) {
				dir.setLastModified(entry.getTime());
			}
			continue;
		}
		int count;
		byte[] data = new byte[BUFFER_SIZE];
		File destFile = new File(destDir, entry.getName());
		if (mVerbose) {
			System.out.println("unjarring " + destFile +
				" from " + entry.getName());
		}
		FileOutputStream fos = new FileOutputStream(destFile);
		dest = new BufferedOutputStream(fos, BUFFER_SIZE);
		try {
			while ((count = jis.read(data, 0, BUFFER_SIZE)) != -1) {
				dest.write(data, 0, count);
			}
			dest.flush();
		} finally {
			dest.close();
		}
		if (entry.getTime() != -1) {
			destFile.setLastModified(entry.getTime());
		}
	}
	jis.close();
}
 
源代码15 项目: kogito-runtimes   文件: MarshallingTest.java
/**
 * In this case we are dealing with facts which are not on the systems classpath.
 */
@Test
public void testSerializabilityWithJarFacts() throws Exception {
    MapBackedClassLoader loader = new MapBackedClassLoader( this.getClass().getClassLoader() );

    JarInputStream jis = new JarInputStream( this.getClass().getResourceAsStream( "/billasurf.jar" ) );

    JarEntry entry = null;
    byte[] buf = new byte[1024];
    int len = 0;
    while ( (entry = jis.getNextJarEntry()) != null ) {
        if ( !entry.isDirectory() ) {
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            while ( (len = jis.read( buf )) >= 0 ) {
                out.write( buf,
                           0,
                           len );
            }
            loader.addResource( entry.getName(),
                                out.toByteArray() );
        }
    }

    String drl = "package foo.bar \n" +
                 "import com.billasurf.Board\n" +
                 "rule 'MyGoodRule' \n dialect 'mvel' \n when " +
                 "   Board() " +
                 "then \n" +
                 " System.err.println(42); \n" +
                 "end\n";


    KnowledgeBuilderConfiguration kbuilderConf = KnowledgeBuilderFactory.newKnowledgeBuilderConfiguration(null, loader);

    Collection<KiePackage>  kpkgs = loadKnowledgePackagesFromString(kbuilderConf, drl);

    kpkgs = SerializationHelper.serializeObject( kpkgs, loader );

}
 
源代码16 项目: Albianj2   文件: AlbianClassLoader.java
private byte[] getBytes(JarInputStream jis) throws IOException {
    int len = 0;
    byte[] bytes = new byte[8192];
    ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
    while ((len = jis.read(bytes, 0, bytes.length)) != -1) {
        baos.write(bytes, 0, len);
    }
    return baos.toByteArray();
}
 
源代码17 项目: rscplus   文件: JClassLoader.java
/**
 * Fetches the game jar and loads and patches the classes
 *
 * @param jarURL The URL of the jar to be loaded and patched
 * @return If no exceptions occurred
 */
public boolean fetch(String jarURL) {
  Logger.Info("Fetching Jar: " + jarURL);

  try {
    JarInputStream in = new JarInputStream(Settings.getResourceAsStream(jarURL));
    Launcher.getInstance().setProgress(1, 1);

    JarEntry entry;
    while ((entry = in.getNextJarEntry()) != null) {
      // Check if file is needed
      String name = entry.getName();

      // Read class to byte array
      ByteArrayOutputStream bOut = new ByteArrayOutputStream();
      byte[] data = new byte[1024];
      int readSize;
      while ((readSize = in.read(data, 0, data.length)) != -1) bOut.write(data, 0, readSize);
      byte[] classData = bOut.toByteArray();
      bOut.close();

      Logger.Info("Loading file: " + name);
      Launcher.getInstance().setStatus("Loading " + name + "...");

      if (name.endsWith(".class")) {
        name = name.substring(0, name.indexOf(".class"));
        classData = JClassPatcher.getInstance().patch(classData);
        m_classData.put(name, classData);
      }
    }
    in.close();
  } catch (Exception e) {
    e.printStackTrace();
    return false;
  }
  return true;
}
 
源代码18 项目: netbeans   文件: NbModuleSuite.java
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;
}
 
源代码19 项目: isu   文件: ZipUtils.java
public static String generateUnhide(Context context, File output) {
    File temp = new File(context.getCacheDir(), "temp.apk");
    String pkg = "";
    Log.d(TAG, "try start ");
    try {
        JarInputStream source = new JarInputStream(new FileInputStream(new File(Tools.runCommand("pm path " + ISU_APK + "| head -n1 | cut -d: -f2", Tools.SuBinary(), context))));
        JarOutputStream dest = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(temp)));
        JarEntry entry;
        int size;
        byte buffer[] = new byte[4096];
        while ((entry = source.getNextJarEntry()) != null) {
            dest.putNextEntry(new JarEntry(entry.getName()));
            if (TextUtils.equals(entry.getName(), ANDROID_MANIFEST)) {
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                while ((size = source.read(buffer)) > 0) {
                    baos.write(buffer, 0, size);
                }

                byte xml[] = baos.toByteArray();
                boolean need_zero = false;
                int offset = Tools.FindOffSet(xml, COM_PKG_NAME);

                if (offset < 0) {
                    Log.d(TAG, "offset < 0 try appModZeros");
                    byte[] COM_PKG_NAME_ZERO = (Tools.appStringAddZeros(app_name)).getBytes();
                    offset = Tools.FindOffSet(xml, COM_PKG_NAME_ZERO);
                    need_zero = true;
                }
                if (offset < 0) {
                    Log.d(TAG, "offset < 0 again return");
                    return "";
                }

                Log.d(TAG, "offset " + offset + " leg " + COM_PKG_NAME.length);
                // Patch binary XML with new package name
                if (Tools.appInstaled(context)) {
                    if (need_zero)
                        pkg = Tools.appStringAddZeros(Tools.readString("hide_app_name", null, context));
                    else
                        pkg = Tools.readString("hide_app_name", null, context);
                } else
                    pkg = Tools.appStringMod(app_name, need_zero);
                System.arraycopy(pkg.getBytes(), 0, xml, offset, pkg.length());
                dest.write(xml);
            } else {
                while ((size = source.read(buffer)) > 0) {
                    dest.write(buffer, 0, size);
                }
            }
        }
        source.close();
        dest.close();
        signZip(context, temp, output, false);
        temp.delete();
    } catch (IOException e) {
        e.printStackTrace();
        return pkg;
    }
    Log.d(TAG, "pkg " + pkg.replace("\0", ""));
    return pkg;
}
 
源代码20 项目: steady   文件: VulasConfiguration.java
/**
 * Reads the content of the current {@link JarEntry} from the given {@link JarInputStream} into a byte array.
 * @param _jis
 * @return
 * @throws IOException
 */
private byte[] readContent(JarInputStream _jis) throws IOException {
	byte[] bytes = new byte[1024];
	while(_jis.read(bytes, 0, 1024)!=-1) {;} //read()
	return bytes;
}