Search in sources :

Example 21 with JarOutputStream

use of java.util.jar.JarOutputStream in project atlas by alibaba.

the class PatchFileBuilder method zipBundleSo.

/**
     * 生成主dex的so
     *
     * @param bundleFolder
     * @param soOutputFile
     */
private void zipBundleSo(File bundleFolder, File soOutputFile) throws PatchException {
    try {
        Manifest manifest = createManifest();
        FileOutputStream fileOutputStream = new FileOutputStream(soOutputFile);
        JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(fileOutputStream), manifest);
        // Add ZIP entry to output stream.
        //            jos.setComment(patchVersion+"@"+targetVersion);
        File[] files = bundleFolder.listFiles();
        for (File file : files) {
            if (file.isDirectory()) {
                addDirectory(jos, file, file.getName());
            } else {
                addFile(jos, file);
            }
        }
        IOUtils.closeQuietly(jos);
        if (null != fileOutputStream)
            IOUtils.closeQuietly(fileOutputStream);
    } catch (IOException e) {
        throw new PatchException(e.getMessage(), e);
    }
}
Also used : JarOutputStream(java.util.jar.JarOutputStream) PatchException(com.taobao.android.differ.dex.PatchException) Manifest(java.util.jar.Manifest)

Example 22 with JarOutputStream

use of java.util.jar.JarOutputStream in project jersey by jersey.

the class JarUtils method createJarFile.

public static File createJarFile(final String name, final Suffix s, final String base, final Map<String, String> entries) throws IOException {
    final File tempJar = File.createTempFile(name, "." + s);
    tempJar.deleteOnExit();
    final JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar)), new Manifest());
    final Set<String> usedSegments = new HashSet<String>();
    for (final Map.Entry<String, String> entry : entries.entrySet()) {
        for (final String path : getPaths(entry.getValue())) {
            if (usedSegments.contains(path)) {
                continue;
            }
            usedSegments.add(path);
            final JarEntry e = new JarEntry(path);
            jos.putNextEntry(e);
            jos.closeEntry();
        }
        final JarEntry e = new JarEntry(entry.getValue());
        jos.putNextEntry(e);
        final InputStream f = new BufferedInputStream(new FileInputStream(base + entry.getKey()));
        final byte[] buf = new byte[1024];
        int read = 1024;
        while ((read = f.read(buf, 0, read)) != -1) {
            jos.write(buf, 0, read);
        }
        jos.closeEntry();
    }
    jos.close();
    return tempJar;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) JarOutputStream(java.util.jar.JarOutputStream) Manifest(java.util.jar.Manifest) JarEntry(java.util.jar.JarEntry) FileInputStream(java.io.FileInputStream) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 23 with JarOutputStream

use of java.util.jar.JarOutputStream in project rest.li by linkedin.

the class TestUtil method createSchemaJar.

public static void createSchemaJar(String jarFileName, Map<String, String> fileToSchemaMap, boolean debug) throws IOException {
    if (debug)
        out.println("creating " + jarFileName);
    FileOutputStream jarFileStream = new FileOutputStream(jarFileName);
    JarOutputStream jarStream = new JarOutputStream(jarFileStream, new Manifest());
    for (Map.Entry<String, String> entry : fileToSchemaMap.entrySet()) {
        String key = entry.getKey();
        // JARs use resource separator as the file separator
        String filename = "pegasus" + key.replace(File.separatorChar, '/');
        if (debug)
            out.println("  adding " + filename);
        JarEntry jarEntry = new JarEntry(filename);
        jarStream.putNextEntry(jarEntry);
        jarStream.write(entry.getValue().getBytes(Data.UTF_8_CHARSET));
    }
    jarStream.close();
    jarFileStream.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) Manifest(java.util.jar.Manifest) JarEntry(java.util.jar.JarEntry) HashMap(java.util.HashMap) Map(java.util.Map) IdentityHashMap(java.util.IdentityHashMap)

Example 24 with JarOutputStream

use of java.util.jar.JarOutputStream in project pinpoint by naver.

the class AgentDirGenerator method createJarFile.

private void createJarFile(File parentDir, String filepath) throws IOException {
    final String jarPath = parentDir.getPath() + File.separator + filepath;
    logger.debug("create jar:{}", jarPath);
    JarOutputStream jos = null;
    try {
        Manifest manifest = new Manifest();
        FileOutputStream out = new FileOutputStream(jarPath);
        jos = new JarOutputStream(out, manifest);
    } finally {
        IOUtils.closeQuietly(jos);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) Manifest(java.util.jar.Manifest)

Example 25 with JarOutputStream

use of java.util.jar.JarOutputStream in project dex2jar by pxb1988.

the class AbstractJarSign method sign.

public void sign(File in, File out) throws IOException, GeneralSecurityException {
    JarFile inputJar = null;
    JarOutputStream outputJar = null;
    FileOutputStream outputFile = null;
    try {
        // Assume the certificate is valid for at least an hour.
        long timestamp = System.currentTimeMillis();
        // Don't verify.
        inputJar = new JarFile(in, false);
        OutputStream outputStream = outputFile = new FileOutputStream(out);
        outputJar = new JarOutputStream(outputStream);
        outputJar.setLevel(9);
        JarEntry je;
        // MANIFEST.MF
        Manifest manifest = addDigestsToManifest(inputJar);
        je = new JarEntry(JarFile.MANIFEST_NAME);
        je.setTime(timestamp);
        outputJar.putNextEntry(je);
        manifest.write(outputJar);
        // CERT.SF
        Signature signature = Signature.getInstance(signAlg);
        signature.initSign(privateKey);
        je = new JarEntry("META-INF/CERT.SF");
        je.setTime(timestamp);
        outputJar.putNextEntry(je);
        writeSignatureFile(manifest, new SignatureOutputStream(outputJar, signature));
        int i = digestAlg.toLowerCase().indexOf("with");
        String ext;
        if (i > 0) {
            ext = digestAlg.substring(i + 4);
        } else {
            ext = "RSA";
        }
        // CERT.RSA
        je = new JarEntry("META-INF/CERT." + ext);
        je.setTime(timestamp);
        outputJar.putNextEntry(je);
        writeSignatureBlock(signature.sign(), outputJar);
        // Everything else
        copyFiles(manifest, inputJar, outputJar, timestamp);
        outputJar.close();
        outputJar = null;
        outputStream.flush();
    } finally {
        try {
            if (inputJar != null) {
                inputJar.close();
            }
            if (outputFile != null) {
                outputFile.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FilterOutputStream(java.io.FilterOutputStream) DigestOutputStream(java.security.DigestOutputStream) Signature(java.security.Signature) JarOutputStream(java.util.jar.JarOutputStream) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) Manifest(java.util.jar.Manifest)

Aggregations

JarOutputStream (java.util.jar.JarOutputStream)244 FileOutputStream (java.io.FileOutputStream)151 File (java.io.File)126 JarEntry (java.util.jar.JarEntry)99 Manifest (java.util.jar.Manifest)72 ZipEntry (java.util.zip.ZipEntry)56 IOException (java.io.IOException)53 JarFile (java.util.jar.JarFile)46 Test (org.junit.Test)43 FileInputStream (java.io.FileInputStream)35 InputStream (java.io.InputStream)34 ByteArrayOutputStream (java.io.ByteArrayOutputStream)33 ByteArrayInputStream (java.io.ByteArrayInputStream)27 JarInputStream (java.util.jar.JarInputStream)26 BufferedOutputStream (java.io.BufferedOutputStream)22 OutputStream (java.io.OutputStream)21 Path (java.nio.file.Path)21 ArrayList (java.util.ArrayList)20 URL (java.net.URL)13 HashMap (java.util.HashMap)13