use of java.util.jar.JarFile in project robovm by robovm.
the class JarFileTest method test_getEntryLjava_lang_String.
/**
* @throws IOException
* java.util.jar.JarFile#getJarEntry(java.lang.String)
*/
public void test_getEntryLjava_lang_String() throws IOException {
try {
Support_Resources.copyFile(resources, null, jarName);
JarFile jarFile = new JarFile(new File(resources, jarName));
assertEquals("Error in returned entry", 311, jarFile.getEntry(entryName).getSize());
jarFile.close();
} catch (Exception e) {
fail("Exception during test: " + e.toString());
}
Support_Resources.copyFile(resources, null, jarName);
JarFile jarFile = new JarFile(new File(resources, jarName));
Enumeration<JarEntry> enumeration = jarFile.entries();
assertTrue(enumeration.hasMoreElements());
while (enumeration.hasMoreElements()) {
JarEntry je = enumeration.nextElement();
jarFile.getEntry(je.getName());
}
enumeration = jarFile.entries();
assertTrue(enumeration.hasMoreElements());
JarEntry je = enumeration.nextElement();
try {
jarFile.close();
jarFile.getEntry(je.getName());
// fail("IllegalStateException expected.");
} catch (IllegalStateException ee) {
// Per documentation exception
// may be thrown.
// expected
}
}
use of java.util.jar.JarFile in project robovm by robovm.
the class JarFileTest method test_ConstructorLjava_io_File.
/**
* java.util.jar.JarFile#JarFile(java.io.File)
*/
public void test_ConstructorLjava_io_File() {
try {
JarFile jarFile = new JarFile(new File("Wrong.file"));
fail("Should throw IOException");
} catch (IOException e) {
// expected
}
try {
Support_Resources.copyFile(resources, null, jarName);
JarFile jarFile = new JarFile(new File(resources, jarName));
} catch (IOException e) {
fail("Should not throw IOException");
}
}
use of java.util.jar.JarFile in project robovm by robovm.
the class JarFileTest method test_ConstructorLjava_lang_StringZ.
/**
* java.util.jar.JarFile#JarFile(java.lang.String, boolean)
*/
public void test_ConstructorLjava_lang_StringZ() {
try {
JarFile jarFile = new JarFile("Wrong.file", false);
fail("Should throw IOException");
} catch (IOException e) {
// expected
}
try {
Support_Resources.copyFile(resources, null, jarName);
String fileName = (new File(resources, jarName)).getCanonicalPath();
JarFile jarFile = new JarFile(fileName, true);
} catch (IOException e) {
fail("Should not throw IOException");
}
}
use of java.util.jar.JarFile in project robovm by robovm.
the class JarFileTest method test_getInputStreamLjava_util_jar_JarEntry.
/**
* @throws IOException
* java.util.jar.JarFile#getInputStream(java.util.zip.ZipEntry)
*/
public void test_getInputStreamLjava_util_jar_JarEntry() throws IOException {
File localFile = null;
try {
Support_Resources.copyFile(resources, null, jarName);
localFile = new File(resources, jarName);
} catch (Exception e) {
fail("Failed to create local file: " + e);
}
byte[] b = new byte[1024];
try {
JarFile jf = new JarFile(localFile);
java.io.InputStream is = jf.getInputStream(jf.getEntry(entryName));
// BEGIN android-removed
// jf.close();
// END android-removed
assertTrue("Returned invalid stream", is.available() > 0);
int r = is.read(b, 0, 1024);
is.close();
StringBuffer sb = new StringBuffer(r);
for (int i = 0; i < r; i++) {
sb.append((char) (b[i] & 0xff));
}
String contents = sb.toString();
assertTrue("Incorrect stream read", contents.indexOf("bar") > 0);
// BEGIN android-added
jf.close();
// END android-added
} catch (Exception e) {
fail("Exception during test: " + e.toString());
}
try {
JarFile jf = new JarFile(localFile);
InputStream in = jf.getInputStream(new JarEntry("invalid"));
assertNull("Got stream for non-existent entry", in);
} catch (Exception e) {
fail("Exception during test 2: " + e);
}
try {
Support_Resources.copyFile(resources, null, jarName);
File signedFile = new File(resources, jarName);
JarFile jf = new JarFile(signedFile);
JarEntry jre = new JarEntry("foo/bar/A.class");
jf.getInputStream(jre);
// InputStream returned in any way, exception can be thrown in case
// of reading from this stream only.
// fail("Should throw ZipException");
} catch (ZipException ee) {
// expected
}
try {
Support_Resources.copyFile(resources, null, jarName);
File signedFile = new File(resources, jarName);
JarFile jf = new JarFile(signedFile);
JarEntry jre = new JarEntry("foo/bar/A.class");
jf.close();
jf.getInputStream(jre);
// InputStream returned in any way, exception can be thrown in case
// of reading from this stream only.
// The same for IOException
fail("Should throw IllegalStateException");
} catch (IllegalStateException ee) {
// expected
}
}
use of java.util.jar.JarFile in project robovm by robovm.
the class DalvikExecTest method test_execExistingJar.
// Execute an existing JAR on dalvikvm using -classpath option.",
public void test_execExistingJar() throws IOException, InterruptedException {
String res;
File jarFile;
if (System.getProperty("java.vendor").contains("Android")) {
//
// Test against Android:
//
File tempDir = Support_Resources.createTempFolder();
jarFile = Support_Resources.copyFile(tempDir, null, "cts_dalvikExecTest.jar");
res = execDalvik(jarFile.getAbsolutePath(), "dalvikExecTest.HelloWorld");
assertEquals("Hello Android World!", "Hello Android World!\n", res);
res = execDalvik(jarFile.getAbsolutePath(), "dalvikExecTest.ResourceDumper");
assertTrue("Android Resource Dumper started", res.contains("Android Resource Dumper started"));
assertTrue("This Resource contains some text.", res.contains("This Resource contains some text."));
} else {
//
// Test against RI:
//
// Do nothing!
}
}
Aggregations