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
}
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
}
}
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);
}
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());
}
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");
}
}
Aggregations