Search in sources :

Example 16 with JarOutputStream

use of java.util.jar.JarOutputStream in project buck by facebook.

the class ClassesImpl method createJar.

@Override
public void createJar(Path jarPath) throws IOException {
    try (JarOutputStream jar = new JarOutputStream(Files.newOutputStream(jarPath))) {
        List<Path> files = Files.walk(root.getRoot().toPath()).filter(path -> path.toFile().isFile()).collect(Collectors.toList());
        for (Path file : files) {
            ZipEntry entry = new ZipEntry(MorePaths.pathWithUnixSeparators(root.getRoot().toPath().relativize(file)));
            jar.putNextEntry(entry);
            ByteStreams.copy(Files.newInputStream(file), jar);
            jar.closeEntry();
        }
    }
}
Also used : Files(java.nio.file.Files) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) File(java.io.File) MorePaths(com.facebook.buck.io.MorePaths) List(java.util.List) ClassReader(org.objectweb.asm.ClassReader) ByteStreams(com.google.common.io.ByteStreams) ClassVisitor(org.objectweb.asm.ClassVisitor) Path(java.nio.file.Path) JarOutputStream(java.util.jar.JarOutputStream) ZipEntry(java.util.zip.ZipEntry) TemporaryFolder(org.junit.rules.TemporaryFolder) InputStream(java.io.InputStream) Path(java.nio.file.Path) ZipEntry(java.util.zip.ZipEntry) JarOutputStream(java.util.jar.JarOutputStream)

Example 17 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 18 with JarOutputStream

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

the class AnalyzerGuruTest method testJar.

@Test
public void testJar() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    JarOutputStream jos = new JarOutputStream(baos);
    jos.putNextEntry(new JarEntry("dummy"));
    jos.closeEntry();
    jos.close();
    InputStream in = new ByteArrayInputStream(baos.toByteArray());
    FileAnalyzer fa = AnalyzerGuru.getAnalyzer(in, "dummy");
    assertSame(JarAnalyzer.class, fa.getClass());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JarOutputStream(java.util.jar.JarOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JarEntry(java.util.jar.JarEntry) Test(org.junit.Test)

Example 19 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 20 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)

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