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();
}
}
}
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();
}
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());
}
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;
}
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);
}
}
}
Aggregations