Search in sources :

Example 16 with Manifest

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();
}
Also used : ZipEntry(java.util.zip.ZipEntry) Manifest(java.util.jar.Manifest) JarFile(java.util.jar.JarFile) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 17 with Manifest

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;
}
Also used : Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest) Date(java.sql.Date)

Example 18 with 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);
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) Manifest(java.util.jar.Manifest) BufferedOutputStream(java.io.BufferedOutputStream) File(java.io.File)

Example 19 with Manifest

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);
    }
}
Also used : JarOutputStream(java.util.jar.JarOutputStream) PatchException(com.taobao.android.differ.dex.PatchException) Manifest(java.util.jar.Manifest)

Example 20 with Manifest

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());
}
Also used : Attributes(java.util.jar.Attributes) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Manifest(java.util.jar.Manifest) Test(org.junit.Test)

Aggregations

Manifest (java.util.jar.Manifest)1226 Attributes (java.util.jar.Attributes)392 File (java.io.File)391 IOException (java.io.IOException)336 JarFile (java.util.jar.JarFile)231 InputStream (java.io.InputStream)184 URL (java.net.URL)177 JarOutputStream (java.util.jar.JarOutputStream)145 FileOutputStream (java.io.FileOutputStream)131 Test (org.junit.Test)129 FileInputStream (java.io.FileInputStream)119 Jar (aQute.bnd.osgi.Jar)105 JarInputStream (java.util.jar.JarInputStream)104 Builder (aQute.bnd.osgi.Builder)99 ZipEntry (java.util.zip.ZipEntry)99 ByteArrayOutputStream (java.io.ByteArrayOutputStream)96 JarEntry (java.util.jar.JarEntry)96 ByteArrayInputStream (java.io.ByteArrayInputStream)93 ArrayList (java.util.ArrayList)83 Map (java.util.Map)83