Search in sources :

Example 66 with JarFile

use of java.util.jar.JarFile in project robovm by robovm.

the class OldJarFileTest method test_close.

public void test_close() throws IOException {
    String modifiedJarName = "Modified_SF_EntryAttributes.jar";
    Support_Resources.copyFile(resources, null, modifiedJarName);
    JarFile jarFile = new JarFile(new File(resources, modifiedJarName), true);
    jarFile.entries();
    jarFile.close();
    jarFile.close();
// Can not check IOException
}
Also used : JarFile(java.util.jar.JarFile) JarFile(java.util.jar.JarFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 67 with JarFile

use of java.util.jar.JarFile in project robovm by robovm.

the class OldJarURLConnectionTest method test_getCertificates.

public void test_getCertificates() throws Exception {
    URL u = createContent("TestCodeSigners.jar", "Test.class");
    juc = (JarURLConnection) u.openConnection();
    assertNull(juc.getCertificates());
    JarEntry je = juc.getJarEntry();
    JarFile jf = juc.getJarFile();
    InputStream is = jf.getInputStream(je);
    is.skip(je.getSize());
    Certificate[] certs = juc.getCertificates();
    assertEquals(3, certs.length);
    URL invURL = createContent("InvalidJar.jar", "Test.class");
    JarURLConnection juConn = (JarURLConnection) invURL.openConnection();
    try {
        juConn.getCertificates();
        fail("IOException was not thrown.");
    } catch (java.io.IOException io) {
    //expected
    }
}
Also used : InputStream(java.io.InputStream) JarURLConnection(java.net.JarURLConnection) IOException(java.io.IOException) JarEntry(java.util.jar.JarEntry) JarFile(java.util.jar.JarFile) URL(java.net.URL) Certificate(java.security.cert.Certificate)

Example 68 with JarFile

use of java.util.jar.JarFile in project robovm by robovm.

the class OldJarURLConnectionTest method createContent.

private URL createContent(String jarFile, String inFile) throws MalformedURLException {
    File resources = Support_Resources.createTempFolder();
    Support_Resources.copyFile(resources, "net", jarFile);
    File file = new File(resources.toString() + "/net/" + jarFile);
    return new URL("jar:file:" + file.getPath() + "!/" + inFile);
}
Also used : JarFile(java.util.jar.JarFile) File(java.io.File) ZipFile(java.util.zip.ZipFile) URL(java.net.URL)

Example 69 with JarFile

use of java.util.jar.JarFile in project robovm by robovm.

the class OldJarURLConnectionTest method test_getInputStream_DeleteJarFileUsingURLConnection.

public void test_getInputStream_DeleteJarFileUsingURLConnection() throws Exception {
    String entry = "text.txt";
    String cts = System.getProperty("java.io.tmpdir");
    File tmpDir = new File(cts);
    File jarFile = File.createTempFile("file", ".jar", tmpDir);
    String jarFileName = jarFile.getPath();
    FileOutputStream jarFileOutputStream = new FileOutputStream(jarFileName);
    JarOutputStream out = new JarOutputStream(new BufferedOutputStream(jarFileOutputStream));
    JarEntry jarEntry = new JarEntry(entry);
    out.putNextEntry(jarEntry);
    out.write(new byte[] { 'a', 'b', 'c' });
    out.close();
    URL url = new URL("jar:file:" + jarFileName + "!/" + entry);
    URLConnection conn = url.openConnection();
    conn.setUseCaches(false);
    InputStream is = conn.getInputStream();
    is.close();
    assertTrue(jarFile.delete());
}
Also used : InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) JarEntry(java.util.jar.JarEntry) JarFile(java.util.jar.JarFile) File(java.io.File) ZipFile(java.util.zip.ZipFile) BufferedOutputStream(java.io.BufferedOutputStream) URL(java.net.URL) URLConnection(java.net.URLConnection) JarURLConnection(java.net.JarURLConnection)

Example 70 with JarFile

use of java.util.jar.JarFile in project robovm by robovm.

the class OldAndroidZipStressTest method checkJarCertificates.

/**
     * JarEntry.getCertificates() is really slow. http://b/1046174
     */
public void checkJarCertificates(File file) throws Exception {
    JarFile jarFile = new JarFile(file);
    JarEntry je = jarFile.getJarEntry("AndroidManifest.xml");
    byte[] readBuffer = new byte[1024];
    long t0 = System.currentTimeMillis();
    // We must read the stream for the JarEntry to retrieve its certificates.
    InputStream is = jarFile.getInputStream(je);
    while (is.read(readBuffer, 0, readBuffer.length) != -1) {
    }
    is.close();
    Certificate[] certs = je != null ? je.getCertificates() : null;
    long t1 = System.currentTimeMillis();
    System.out.println("loadCertificates() took " + (t1 - t0) + " ms");
    if (certs == null) {
        System.out.println("We have no certificates");
    } else {
        System.out.println("We have " + certs.length + " certificates");
    }
}
Also used : InputStream(java.io.InputStream) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) Certificate(java.security.cert.Certificate)

Aggregations

JarFile (java.util.jar.JarFile)509 File (java.io.File)289 JarEntry (java.util.jar.JarEntry)230 IOException (java.io.IOException)212 URL (java.net.URL)92 ZipEntry (java.util.zip.ZipEntry)92 InputStream (java.io.InputStream)90 Manifest (java.util.jar.Manifest)81 ZipFile (java.util.zip.ZipFile)74 FileOutputStream (java.io.FileOutputStream)71 Test (org.junit.Test)66 ArrayList (java.util.ArrayList)54 JarURLConnection (java.net.JarURLConnection)48 Attributes (java.util.jar.Attributes)43 JarOutputStream (java.util.jar.JarOutputStream)41 MalformedURLException (java.net.MalformedURLException)31 FileInputStream (java.io.FileInputStream)30 Support_PlatformFile (tests.support.Support_PlatformFile)26 Enumeration (java.util.Enumeration)24 HashSet (java.util.HashSet)20