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