use of java.util.jar.Manifest in project hadoop by apache.
the class JarFinder method jarDir.
public static void jarDir(File dir, String relativePath, ZipOutputStream zos) throws IOException {
Preconditions.checkNotNull(relativePath, "relativePath");
Preconditions.checkNotNull(zos, "zos");
// by JAR spec, if there is a manifest, it must be the first entry in the
// ZIP.
File manifestFile = new File(dir, JarFile.MANIFEST_NAME);
ZipEntry manifestEntry = new ZipEntry(JarFile.MANIFEST_NAME);
if (!manifestFile.exists()) {
zos.putNextEntry(manifestEntry);
new Manifest().write(new BufferedOutputStream(zos));
zos.closeEntry();
} else {
copyToZipStream(manifestFile, manifestEntry, zos);
}
zos.closeEntry();
zipDir(dir, relativePath, zos, true);
zos.close();
}
use of java.util.jar.Manifest in project atlas by alibaba.
the class TPatchTool method createManifest.
/**
* 创建tpatch的manifest信息
*
* @return
*/
private Manifest createManifest() {
Manifest manifest = new Manifest();
Attributes main = manifest.getMainAttributes();
main.putValue("Manifest-Version", "1.0");
main.putValue("Created-By", "1.0 (DexPatch)");
main.putValue("Created-Time", new Date(System.currentTimeMillis()).toGMTString());
return manifest;
}
use of java.util.jar.Manifest 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.Manifest 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.Manifest in project buck by facebook.
the class DeterministicJarManifestWriterTest method testLinesSplitLikeJavaImpl.
@Test
public void testLinesSplitLikeJavaImpl() throws IOException {
final String entryName = "test";
final String key = "12345678";
final String value = "138-char value + 8 char key + 2 char padding = 148 chars. |" + "69-character second line |" + "last line";
manifestWriter.setEntryAttribute(entryName, key, value);
manifestWriter.write();
Manifest jdkManifest = new Manifest();
Attributes attrs = new Attributes();
attrs.putValue(key, value);
jdkManifest.getEntries().put(entryName, attrs);
ByteArrayOutputStream expected = new ByteArrayOutputStream();
jdkManifest.write(expected);
assertArrayEquals(expected.toByteArray(), outputStream.toByteArray());
}
Aggregations