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);
}
}
use of java.util.jar.JarOutputStream in project jersey by jersey.
the class JarUtils method createJarFile.
public static File createJarFile(final String name, final Suffix s, final String base, final Map<String, String> entries) throws IOException {
final File tempJar = File.createTempFile(name, "." + s);
tempJar.deleteOnExit();
final JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar)), new Manifest());
final Set<String> usedSegments = new HashSet<String>();
for (final Map.Entry<String, String> entry : entries.entrySet()) {
for (final String path : getPaths(entry.getValue())) {
if (usedSegments.contains(path)) {
continue;
}
usedSegments.add(path);
final JarEntry e = new JarEntry(path);
jos.putNextEntry(e);
jos.closeEntry();
}
final JarEntry e = new JarEntry(entry.getValue());
jos.putNextEntry(e);
final InputStream f = new BufferedInputStream(new FileInputStream(base + entry.getKey()));
final byte[] buf = new byte[1024];
int read = 1024;
while ((read = f.read(buf, 0, read)) != -1) {
jos.write(buf, 0, read);
}
jos.closeEntry();
}
jos.close();
return tempJar;
}
use of java.util.jar.JarOutputStream in project rest.li by linkedin.
the class TestUtil method createSchemaJar.
public static void createSchemaJar(String jarFileName, Map<String, String> fileToSchemaMap, boolean debug) throws IOException {
if (debug)
out.println("creating " + jarFileName);
FileOutputStream jarFileStream = new FileOutputStream(jarFileName);
JarOutputStream jarStream = new JarOutputStream(jarFileStream, new Manifest());
for (Map.Entry<String, String> entry : fileToSchemaMap.entrySet()) {
String key = entry.getKey();
// JARs use resource separator as the file separator
String filename = "pegasus" + key.replace(File.separatorChar, '/');
if (debug)
out.println(" adding " + filename);
JarEntry jarEntry = new JarEntry(filename);
jarStream.putNextEntry(jarEntry);
jarStream.write(entry.getValue().getBytes(Data.UTF_8_CHARSET));
}
jarStream.close();
jarFileStream.close();
}
use of java.util.jar.JarOutputStream in project pinpoint by naver.
the class AgentDirGenerator method createJarFile.
private void createJarFile(File parentDir, String filepath) throws IOException {
final String jarPath = parentDir.getPath() + File.separator + filepath;
logger.debug("create jar:{}", jarPath);
JarOutputStream jos = null;
try {
Manifest manifest = new Manifest();
FileOutputStream out = new FileOutputStream(jarPath);
jos = new JarOutputStream(out, manifest);
} finally {
IOUtils.closeQuietly(jos);
}
}
use of java.util.jar.JarOutputStream in project dex2jar by pxb1988.
the class AbstractJarSign method sign.
public void sign(File in, File out) throws IOException, GeneralSecurityException {
JarFile inputJar = null;
JarOutputStream outputJar = null;
FileOutputStream outputFile = null;
try {
// Assume the certificate is valid for at least an hour.
long timestamp = System.currentTimeMillis();
// Don't verify.
inputJar = new JarFile(in, false);
OutputStream outputStream = outputFile = new FileOutputStream(out);
outputJar = new JarOutputStream(outputStream);
outputJar.setLevel(9);
JarEntry je;
// MANIFEST.MF
Manifest manifest = addDigestsToManifest(inputJar);
je = new JarEntry(JarFile.MANIFEST_NAME);
je.setTime(timestamp);
outputJar.putNextEntry(je);
manifest.write(outputJar);
// CERT.SF
Signature signature = Signature.getInstance(signAlg);
signature.initSign(privateKey);
je = new JarEntry("META-INF/CERT.SF");
je.setTime(timestamp);
outputJar.putNextEntry(je);
writeSignatureFile(manifest, new SignatureOutputStream(outputJar, signature));
int i = digestAlg.toLowerCase().indexOf("with");
String ext;
if (i > 0) {
ext = digestAlg.substring(i + 4);
} else {
ext = "RSA";
}
// CERT.RSA
je = new JarEntry("META-INF/CERT." + ext);
je.setTime(timestamp);
outputJar.putNextEntry(je);
writeSignatureBlock(signature.sign(), outputJar);
// Everything else
copyFiles(manifest, inputJar, outputJar, timestamp);
outputJar.close();
outputJar = null;
outputStream.flush();
} finally {
try {
if (inputJar != null) {
inputJar.close();
}
if (outputFile != null) {
outputFile.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
Aggregations