use of java.io.BufferedOutputStream in project MinecraftForge by MinecraftForge.
the class AccessTransformer method processJar.
private static void processJar(File inFile, File outFile, AccessTransformer[] transformers) throws IOException {
ZipInputStream inJar = null;
ZipOutputStream outJar = null;
try {
try {
inJar = new ZipInputStream(new BufferedInputStream(new FileInputStream(inFile)));
} catch (FileNotFoundException e) {
throw new FileNotFoundException("Could not open input file: " + e.getMessage());
}
try {
outJar = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outFile)));
} catch (FileNotFoundException e) {
throw new FileNotFoundException("Could not open output file: " + e.getMessage());
}
ZipEntry entry;
while ((entry = inJar.getNextEntry()) != null) {
if (entry.isDirectory()) {
outJar.putNextEntry(entry);
continue;
}
byte[] data = new byte[4096];
ByteArrayOutputStream entryBuffer = new ByteArrayOutputStream();
int len;
do {
len = inJar.read(data);
if (len > 0) {
entryBuffer.write(data, 0, len);
}
} while (len != -1);
byte[] entryData = entryBuffer.toByteArray();
String entryName = entry.getName();
if (entryName.endsWith(".class") && !entryName.startsWith(".")) {
ClassNode cls = new ClassNode();
ClassReader rdr = new ClassReader(entryData);
rdr.accept(cls, 0);
String name = cls.name.replace('/', '.').replace('\\', '.');
for (AccessTransformer trans : transformers) {
entryData = trans.transform(name, name, entryData);
}
}
ZipEntry newEntry = new ZipEntry(entryName);
outJar.putNextEntry(newEntry);
outJar.write(entryData);
}
} finally {
IOUtils.closeQuietly(outJar);
IOUtils.closeQuietly(inJar);
}
}
use of java.io.BufferedOutputStream in project MinecraftForge by MinecraftForge.
the class MarkerTransformer method processJar.
private static void processJar(File inFile, File outFile, MarkerTransformer[] transformers) throws IOException {
ZipInputStream inJar = null;
ZipOutputStream outJar = null;
try {
try {
inJar = new ZipInputStream(new BufferedInputStream(new FileInputStream(inFile)));
} catch (FileNotFoundException e) {
throw new FileNotFoundException("Could not open input file: " + e.getMessage());
}
try {
outJar = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(outFile)));
} catch (FileNotFoundException e) {
throw new FileNotFoundException("Could not open output file: " + e.getMessage());
}
ZipEntry entry;
while ((entry = inJar.getNextEntry()) != null) {
if (entry.isDirectory()) {
outJar.putNextEntry(entry);
continue;
}
byte[] data = new byte[4096];
ByteArrayOutputStream entryBuffer = new ByteArrayOutputStream();
int len;
do {
len = inJar.read(data);
if (len > 0) {
entryBuffer.write(data, 0, len);
}
} while (len != -1);
byte[] entryData = entryBuffer.toByteArray();
String entryName = entry.getName();
if (entryName.endsWith(".class") && !entryName.startsWith(".")) {
ClassNode cls = new ClassNode();
ClassReader rdr = new ClassReader(entryData);
rdr.accept(cls, 0);
String name = cls.name.replace('/', '.').replace('\\', '.');
for (MarkerTransformer trans : transformers) {
entryData = trans.transform(name, name, entryData);
}
}
ZipEntry newEntry = new ZipEntry(entryName);
outJar.putNextEntry(newEntry);
outJar.write(entryData);
}
} finally {
IOUtils.closeQuietly(outJar);
IOUtils.closeQuietly(inJar);
}
}
use of java.io.BufferedOutputStream in project archaius by Netflix.
the class DynamicURLConfigurationTestWithFileURL method populateFile.
private void populateFile(File temporary, String prop1, String prop2) throws IOException {
String s = prop1 + "\n" + prop2 + "\n";
byte[] data = s.getBytes("UTF-8");
OutputStream out = null;
try {
out = new BufferedOutputStream(new FileOutputStream(temporary, true), 8 * 1024);
out.write(data, 0, data.length);
} finally {
if (null != out) {
out.flush();
out.close();
}
}
}
use of java.io.BufferedOutputStream 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.io.BufferedOutputStream 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