Search in sources :

Example 1 with JarEntry

use of com.alipay.sofa.ark.loader.jar.JarEntry in project sofa-ark by alipay.

the class JarFileTest method testJarFile.

@Test
public void testJarFile() throws IOException {
    JarFile jarFile = new JarFile(getTempDemoZip());
    Manifest manifest = jarFile.getManifest();
    Assert.assertTrue(manifest.getMainAttributes().getValue("k1").equals("v1"));
    Assert.assertTrue(manifest.getMainAttributes().getValue("k2").equals("v2"));
    Assert.assertTrue(jarFile.containsEntry(TEST_ENTRY));
    ZipEntry zipEntry = jarFile.getEntry(TEST_ENTRY);
    Assert.assertTrue(zipEntry.getName().equals(TEST_ENTRY));
    Assert.assertTrue(zipEntry.getComment().equals(TEST_ENTRY_COMMENT));
    Assert.assertTrue(compareByteArray(zipEntry.getExtra(), TEST_ENTRY_EXTRA.getBytes()));
    JarEntry jarEntry = jarFile.getJarEntry("lib/junit-4.12.jar");
    JarFile nestJarFile = jarFile.getNestedJarFile(jarEntry);
    Manifest nestManifest = nestJarFile.getManifest();
    Assert.assertTrue(nestManifest.getMainAttributes().getValue("Implementation-Title").equals("JUnit"));
    Assert.assertTrue(nestManifest.getMainAttributes().getValue("Implementation-Version").equals("4.12"));
}
Also used : ZipEntry(java.util.zip.ZipEntry) JarFile(com.alipay.sofa.ark.loader.jar.JarFile) Manifest(java.util.jar.Manifest) JarEntry(com.alipay.sofa.ark.loader.jar.JarEntry) BaseTest(com.alipay.sofa.ark.loader.test.base.BaseTest) Test(org.junit.Test)

Aggregations

JarEntry (com.alipay.sofa.ark.loader.jar.JarEntry)1 JarFile (com.alipay.sofa.ark.loader.jar.JarFile)1 BaseTest (com.alipay.sofa.ark.loader.test.base.BaseTest)1 Manifest (java.util.jar.Manifest)1 ZipEntry (java.util.zip.ZipEntry)1 Test (org.junit.Test)1