当前位置: 首页>>代码示例>>Java>>正文


Java ZipFile.OPEN_READ属性代码示例

本文整理汇总了Java中java.util.zip.ZipFile.OPEN_READ属性的典型用法代码示例。如果您正苦于以下问题:Java ZipFile.OPEN_READ属性的具体用法?Java ZipFile.OPEN_READ怎么用?Java ZipFile.OPEN_READ使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在java.util.zip.ZipFile的用法示例。


在下文中一共展示了ZipFile.OPEN_READ属性的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testVersioning

@Test(dataProvider="versions")
public void testVersioning(Runtime.Version value, int xpected) throws Exception {
    Runtime.Version expected = Runtime.Version.parse(String.valueOf(xpected));
    Runtime.Version base = JarFile.baseVersion();

    // multi-release jar, opened as unversioned
    try (JarFile jar = new JarFile(multirelease)) {
        Assert.assertEquals(jar.getVersion(), base);
    }

    System.err.println("test versioning for Release " + value);
    try (JarFile jf = new JarFile(multirelease, true, ZipFile.OPEN_READ, value)) {
        Assert.assertEquals(jf.getVersion(), expected);
    }

    // regular, unversioned, jar
    try (JarFile jf = new JarFile(unversioned, true, ZipFile.OPEN_READ, value)) {
        Assert.assertEquals(jf.getVersion(), base);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:MultiReleaseJarAPI.java

示例2: testNames

@Test
public void testNames() throws Exception {
    String rname = "version/Version.class";
    String vname = "META-INF/versions/9/version/Version.class";
    ZipEntry ze1;
    ZipEntry ze2;
    try (JarFile jf = new JarFile(multirelease)) {
        ze1 = jf.getEntry(vname);
    }
    Assert.assertEquals(ze1.getName(), vname);
    try (JarFile jf = new JarFile(multirelease, true, ZipFile.OPEN_READ, Runtime.Version.parse("9"))) {
        ze2 = jf.getEntry(rname);
    }
    Assert.assertEquals(ze2.getName(), rname);
    Assert.assertNotEquals(ze1.getName(), ze2.getName());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:MultiReleaseJarAPI.java

示例3: getApplicationName

/**
 * get application name
 *
 * @param apkPath apkPath
 * @return String
 */
public static String getApplicationName(String apkPath) {
    if (apkPath == null || "".equals(apkPath)) {
        return null;
    }
    try {
        ZipFile zipFile = new ZipFile(new File(apkPath), ZipFile.OPEN_READ);
        ZipEntry manifestXmlEntry = zipFile.getEntry(ApkManifestReader.DEFAULT_XML);
        String manifestXML = ApkManifestReader.getManifestXMLFromAPK(zipFile, manifestXmlEntry);
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser parser = factory.newPullParser();
        parser.setInput(new StringReader(manifestXML));
        String applicationName = parseApplicationNameByManifest(parser);
        return applicationName;
    } catch (Exception e1) {
    }
    return "";
}
 
开发者ID:LiangMaYong,项目名称:android-apkbox,代码行数:24,代码来源:ApkManifestParser.java

示例4: getInputStream

@Override
public InputStream getInputStream() throws IOException {
    final ZipFile z = new ZipFile(getZipfile(), ZipFile.OPEN_READ);
    ZipEntry ze = z.getEntry(super.getName());
    if (ze == null) {
        z.close();
        throw new BuildException("no entry " + getName() + " in "
                                 + getArchive());
    }
    return z.getInputStream(ze);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:11,代码来源:LayerIndex.java

示例5: newJarFile

static JarFile newJarFile(Path path) {
    try {
        return new JarFile(new File(path.toString()),
                           true,                       // verify
                           ZipFile.OPEN_READ,
                           JarFile.runtimeVersion());
    } catch (IOException ioe) {
        throw new UncheckedIOException(ioe);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:10,代码来源:ModuleReferences.java

示例6: testCustomMultiReleaseValue

private void testCustomMultiReleaseValue(String value,
        Map<String, String> extraAttributes, boolean expected)
        throws Exception {
    String fileName = "custom-mr" + JAR_COUNT.incrementAndGet() + ".jar";
    creator.buildCustomMultiReleaseJar(fileName, value, extraAttributes);
    File custom = new File(userdir, fileName);
    try (JarFile jf = new JarFile(custom, true, ZipFile.OPEN_READ, Runtime.version())) {
        Assert.assertEquals(jf.isMultiRelease(), expected);
    }
    Files.delete(custom.toPath());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:11,代码来源:MultiReleaseJarAPI.java

示例7: testCertsAndSigners

@Test
public void testCertsAndSigners() throws IOException {
    try (JarFile jf = new JarFile(signedmultirelease, true, ZipFile.OPEN_READ, Runtime.version())) {
        CertsAndSigners vcas = new CertsAndSigners(jf, jf.getJarEntry("version/Version.class"));
        CertsAndSigners rcas = new CertsAndSigners(jf, jf.getJarEntry("META-INF/versions/" + MAJOR_VERSION + "/version/Version.class"));
        Assert.assertTrue(Arrays.equals(rcas.getCertificates(), vcas.getCertificates()));
        Assert.assertTrue(Arrays.equals(rcas.getCodeSigners(), vcas.getCodeSigners()));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:9,代码来源:MultiReleaseJarSecurity.java

示例8: checkMultiRelease

protected void checkMultiRelease(String jarFile,
                                 boolean expected) throws IOException {
    try (JarFile jf = new JarFile(new File(jarFile), true,
            ZipFile.OPEN_READ, JarFile.runtimeVersion())) {
        assertEquals(jf.isMultiRelease(), expected);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:7,代码来源:MRTestBase.java

示例9: ensureZipFile

private void ensureZipFile() throws IOException {
    if (this.zipFile == null) {
        this.zipFile = new ZipFile(bundleFile, ZipFile.OPEN_READ);
    }
}
 
开发者ID:alibaba,项目名称:atlas,代码行数:5,代码来源:BundleArchiveRevision.java

示例10: URLJarFile

public URLJarFile(File file, URLJarFileCloseController closeController) throws IOException {
    super(file, true, ZipFile.OPEN_READ | ZipFile.OPEN_DELETE);
    this.closeController = closeController;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:4,代码来源:URLJarFile.java

示例11: isMultiReleaseJar

@Test
public void isMultiReleaseJar() throws Exception {
    try (JarFile jf = new JarFile(unversioned)) {
        Assert.assertFalse(jf.isMultiRelease());
    }

    try (JarFile jf = new JarFile(unversioned, true, ZipFile.OPEN_READ, Runtime.version())) {
        Assert.assertFalse(jf.isMultiRelease());
    }

    try (JarFile jf = new JarFile(multirelease)) {
        Assert.assertTrue(jf.isMultiRelease());
    }

    try (JarFile jf = new JarFile(multirelease, true, ZipFile.OPEN_READ, Runtime.version())) {
        Assert.assertTrue(jf.isMultiRelease());
    }

    testCustomMultiReleaseValue("true", true);
    testCustomMultiReleaseValue("true\r\nOther: value", true);
    testCustomMultiReleaseValue("true\nOther: value", true);
    testCustomMultiReleaseValue("true\rOther: value", true);

    testCustomMultiReleaseValue("false", false);
    testCustomMultiReleaseValue(" true", false);
    testCustomMultiReleaseValue("true ", false);
    testCustomMultiReleaseValue("true\n ", false);
    testCustomMultiReleaseValue("true\r ", false);
    testCustomMultiReleaseValue("true\n true", false);
    testCustomMultiReleaseValue("true\r\n true", false);

    // generate "random" Strings to use as extra attributes, and
    // verify that Multi-Release: true is always properly matched
    for (int i = 0; i < 100; i++) {
        byte[] keyBytes = new byte[RANDOM.nextInt(70) + 1];
        Arrays.fill(keyBytes, (byte)('a' + RANDOM.nextInt(24)));
        byte[] valueBytes = new byte[RANDOM.nextInt(70) + 1];
        Arrays.fill(valueBytes, (byte)('a' + RANDOM.nextInt(24)));

        String key = new String(keyBytes, StandardCharsets.UTF_8);
        String value = new String(valueBytes, StandardCharsets.UTF_8);
        // test that Multi-Release: true anywhere in the manifest always
        // return true
        testCustomMultiReleaseValue("true", Map.of(key, value), true);

        // test that we don't get any false positives
        testCustomMultiReleaseValue("false", Map.of(key, value), false);
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:49,代码来源:MultiReleaseJarAPI.java

示例12: testCustomManifest

@Test
public void testCustomManifest() throws Throwable {
    String jarfile = "test.jar";

    compile("test01");

    Path classes = Paths.get("classes");
    Path manifest = Paths.get("Manifest.txt");

    // create
    Files.write(manifest, "Class-Path: MyUtils.jar\n".getBytes());

    jar("cfm", jarfile, manifest.toString(),
            "-C", classes.resolve("base").toString(), ".",
            "--release", "10", "-C", classes.resolve("v10").toString(), ".")
            .shouldHaveExitValue(SUCCESS)
            .shouldBeEmpty();

    try (JarFile jf = new JarFile(new File(jarfile), true,
            ZipFile.OPEN_READ, JarFile.runtimeVersion())) {
        assertTrue(jf.isMultiRelease(), "Not multi-release jar");
        assertEquals(jf.getManifest()
                        .getMainAttributes()
                        .getValue("Class-Path"),
                "MyUtils.jar");
    }

    // update
    Files.write(manifest, "Multi-release: false\n".getBytes());

    jar("ufm", jarfile, manifest.toString(),
            "-C", classes.resolve("base").toString(), ".",
            "--release", "9", "-C", classes.resolve("v10").toString(), ".")
            .shouldHaveExitValue(SUCCESS)
            .shouldContain("WARNING: Duplicate name in Manifest: Multi-release.");

    try (JarFile jf = new JarFile(new File(jarfile), true,
            ZipFile.OPEN_READ, JarFile.runtimeVersion())) {
        assertTrue(jf.isMultiRelease(), "Not multi-release jar");
        assertEquals(jf.getManifest()
                        .getMainAttributes()
                        .getValue("Class-Path"),
                "MyUtils.jar");
    }

    FileUtils.deleteFileIfExistsWithRetry(Paths.get(jarfile));
    FileUtils.deleteFileTreeWithRetry(Paths.get(usr, "classes"));
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:48,代码来源:Basic.java

示例13: JarFile

/**
 * Creates a new {@code JarFile} to read from the specified
 * file {@code name}. The {@code JarFile} will be verified if
 * it is signed.
 * @param name the name of the jar file to be opened for reading
 * @throws IOException if an I/O error has occurred
 * @throws SecurityException if access to the file is denied
 *         by the SecurityManager
 */
public JarFile(String name) throws IOException {
    this(new File(name), true, ZipFile.OPEN_READ);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:12,代码来源:JarFile.java


注:本文中的java.util.zip.ZipFile.OPEN_READ属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。