Search in sources :

Example 36 with JarOutputStream

use of java.util.jar.JarOutputStream in project hadoop by apache.

the class JarFinder method createJar.

private static void createJar(File dir, File jarFile) throws IOException {
    Preconditions.checkNotNull(dir, "dir");
    Preconditions.checkNotNull(jarFile, "jarFile");
    File jarDir = jarFile.getParentFile();
    if (!jarDir.exists()) {
        if (!jarDir.mkdirs()) {
            throw new IOException(MessageFormat.format("could not create dir [{0}]", jarDir));
        }
    }
    JarOutputStream zos = new JarOutputStream(new FileOutputStream(jarFile));
    jarDir(dir, "", zos);
}
Also used : FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) File(java.io.File)

Example 37 with JarOutputStream

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

the class ClassPatchManager method setup.

public void setup(Side side) {
    Pattern binpatchMatcher = Pattern.compile(String.format("binpatch/%s/.*.binpatch", side.toString().toLowerCase(Locale.ENGLISH)));
    JarInputStream jis;
    try {
        InputStream binpatchesCompressed = getClass().getResourceAsStream("/binpatches.pack.lzma");
        if (binpatchesCompressed == null) {
            FMLRelaunchLog.log(Level.ERROR, "The binary patch set is missing. Either you are in a development environment, or things are not going to work!");
            return;
        }
        LzmaInputStream binpatchesDecompressed = new LzmaInputStream(binpatchesCompressed);
        ByteArrayOutputStream jarBytes = new ByteArrayOutputStream();
        JarOutputStream jos = new JarOutputStream(jarBytes);
        Pack200.newUnpacker().unpack(binpatchesDecompressed, jos);
        jis = new JarInputStream(new ByteArrayInputStream(jarBytes.toByteArray()));
    } catch (Exception e) {
        FMLRelaunchLog.log(Level.ERROR, e, "Error occurred reading binary patches. Expect severe problems!");
        throw Throwables.propagate(e);
    }
    patches = ArrayListMultimap.create();
    do {
        try {
            JarEntry entry = jis.getNextJarEntry();
            if (entry == null) {
                break;
            }
            if (binpatchMatcher.matcher(entry.getName()).matches()) {
                ClassPatch cp = readPatch(entry, jis);
                if (cp != null) {
                    patches.put(cp.sourceClassName, cp);
                }
            } else {
                jis.closeEntry();
            }
        } catch (IOException e) {
        }
    } while (true);
    FMLRelaunchLog.fine("Read %d binary patches", patches.size());
    if (DEBUG)
        FMLRelaunchLog.fine("Patch list :\n\t%s", Joiner.on("\t\n").join(patches.asMap().entrySet()));
    patchedClasses.clear();
}
Also used : Pattern(java.util.regex.Pattern) LzmaInputStream(LZMA.LzmaInputStream) JarInputStream(java.util.jar.JarInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) JarInputStream(java.util.jar.JarInputStream) LzmaInputStream(LZMA.LzmaInputStream) InputStream(java.io.InputStream) JarOutputStream(java.util.jar.JarOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) JarEntry(java.util.jar.JarEntry) IOException(java.io.IOException)

Example 38 with JarOutputStream

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

the class ApBuildTask method createAP.

private File createAP(File apkFile, BaseVariantOutputData variantOutputData, AppVariantContext appVariantContext) throws IOException {
    File jarshrinkLog = new File(variantOutputData.getOutputFile().getParentFile().getParentFile(), "jar-shrink.log");
    File proguardOut = new File(String.valueOf(variantOutputData.getScope().getGlobalScope().getBuildDir()) + "/outputs/mapping/" + variantOutputData.getScope().getVariantScope().getVariantConfiguration().getDirName());
    // 生成build.ap
    String path = apkFile.getAbsolutePath();
    int index = path.lastIndexOf(".apk");
    File APFile = new File(path.substring(0, index) + ".ap");
    FileOutputStream fileOutputStream = new FileOutputStream(APFile);
    JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(fileOutputStream));
    addFile(jos, variantOutputData.manifestProcessorTask.getManifestOutputFile(), "AndroidManifest.xml");
    addFile(jos, apkFile, "android.apk");
    addFile(jos, new File(variantOutputData.processResourcesTask.getTextSymbolOutputDir(), "R.txt"), "R.txt");
    addFile(jos, appBuildInfo.getPackageIdFile());
    addFile(jos, appBuildInfo.getDependenciesFile());
    addFile(jos, appBuildInfo.getBuildInfoFile());
    addFile(jos, appBuildInfo.getVersionPropertiesFile());
    for (File file : appBuildInfo.getOtherFiles()) {
        addFile(jos, file);
    }
    for (String filePath : appBuildInfo.getOtherFilesMap().keySet()) {
        addFile(jos, filePath, appBuildInfo.getOtherFilesMap().get(filePath));
    }
    addFile(jos, jarshrinkLog, jarshrinkLog.getName());
    addFile(jos, getApkFiles(APFile.getParentFile().getParentFile(), appVariantContext), "apk-files.txt");
    // 如果存在着proguard文件,加入结果信息
    if (null != proguardOut && proguardOut.exists() && (new File(proguardOut, "mapping.txt").exists() || new File(proguardOut, "full-mapping.txt").exists())) {
        File usageFile = new File(proguardOut, "usage.txt");
        File mappingFile = new File(proguardOut, "mapping.txt");
        addFile(jos, usageFile, "usage.txt");
        addFile(jos, mappingFile, "mapping.txt");
        addFile(jos, new File(proguardOut, "full-mapping.txt"), "full-mapping.txt");
        addFile(jos, new File(proguardOut, "mapping.data"), "mapping.data");
    } else if (null != appVariantContext.apContext.getApExploredFolder() && appVariantContext.apContext.getApExploredFolder().exists()) {
        File lastApDir = appVariantContext.apContext.getApExploredFolder();
        File usageFile = new File(lastApDir, "usage.txt");
        File mappingFile = new File(lastApDir, "mapping.txt");
        addFile(jos, usageFile, "usage.txt");
        addFile(jos, mappingFile, "mapping.txt");
        addFile(jos, new File(lastApDir, "full-mapping.txt"), "full-mapping.txt");
        addFile(jos, new File(lastApDir, "mapping.data"), "mapping.data");
    }
    IOUtils.closeQuietly(jos);
    if (null != fileOutputStream) {
        IOUtils.closeQuietly(fileOutputStream);
    }
    return APFile;
}
Also used : FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) File(java.io.File) InputFile(org.gradle.api.tasks.InputFile) BufferedOutputStream(java.io.BufferedOutputStream)

Example 39 with JarOutputStream

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

the class TPatchTool method zipBundle.

/**
     * 将一个文件夹转换为so
     *
     * @param toZipFolder
     * @param soOutputFile
     */
private void zipBundle(File toZipFolder, File soOutputFile) throws IOException {
    FileOutputStream fileOutputStream = null;
    JarOutputStream jos = null;
    try {
        // 生成so文件
        Manifest manifest = createManifest();
        fileOutputStream = new FileOutputStream(soOutputFile);
        jos = new JarOutputStream(new BufferedOutputStream(fileOutputStream), manifest);
        jos.setLevel(9);
        //            jos.setComment(baseApkVersion+"@"+newApkVersion);
        // Add ZIP entry to output stream.
        File[] files = toZipFolder.listFiles();
        for (File file : files) {
            if (file.isDirectory()) {
                addDirectory(jos, file, file.getName());
            } else {
                addFile(jos, file);
            }
        }
    } finally {
        IOUtils.closeQuietly(jos);
        if (null != fileOutputStream) {
            IOUtils.closeQuietly(fileOutputStream);
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) Manifest(java.util.jar.Manifest) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File)

Example 40 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)

Aggregations

JarOutputStream (java.util.jar.JarOutputStream)273 FileOutputStream (java.io.FileOutputStream)171 File (java.io.File)145 JarEntry (java.util.jar.JarEntry)109 Manifest (java.util.jar.Manifest)80 IOException (java.io.IOException)60 ZipEntry (java.util.zip.ZipEntry)60 JarFile (java.util.jar.JarFile)53 Test (org.junit.Test)43 FileInputStream (java.io.FileInputStream)42 InputStream (java.io.InputStream)41 ByteArrayOutputStream (java.io.ByteArrayOutputStream)38 ByteArrayInputStream (java.io.ByteArrayInputStream)30 JarInputStream (java.util.jar.JarInputStream)28 BufferedOutputStream (java.io.BufferedOutputStream)25 ArrayList (java.util.ArrayList)23 OutputStream (java.io.OutputStream)22 Path (java.nio.file.Path)21 Map (java.util.Map)19 HashMap (java.util.HashMap)16