use of java.util.zip.ZipFile in project robovm by robovm.
the class OldJarURLConnectionTest method test_getJarFile.
public void test_getJarFile() throws IOException {
URL url = createContent("lf.jar", "missing");
JarURLConnection connection = (JarURLConnection) url.openConnection();
try {
connection.connect();
fail("Did not throw exception on connect");
} catch (IOException e) {
// expected
}
try {
connection.getJarFile();
fail("Did not throw exception after connect");
} catch (IOException e) {
// expected
}
URL invURL = createContent("InvalidJar.jar", "Test.class");
JarURLConnection juConn = (JarURLConnection) invURL.openConnection();
try {
juConn.getJarFile();
fail("IOException was not thrown.");
} catch (java.io.IOException io) {
//expected
}
File resources = Support_Resources.createTempFolder();
Support_Resources.copyFile(resources, null, "hyts_att.jar");
File file = new File(resources.toString() + "/hyts_att.jar");
URL fUrl1 = new URL("jar:file:" + file.getPath() + "!/");
JarURLConnection con1 = (JarURLConnection) fUrl1.openConnection();
ZipFile jf1 = con1.getJarFile();
JarURLConnection con2 = (JarURLConnection) fUrl1.openConnection();
ZipFile jf2 = con2.getJarFile();
assertTrue("file: JarFiles not the same", jf1 == jf2);
jf1.close();
assertTrue("File should exist", file.exists());
fUrl1 = createContent("lf.jar", "");
con1 = (JarURLConnection) fUrl1.openConnection();
jf1 = con1.getJarFile();
con2 = (JarURLConnection) fUrl1.openConnection();
jf2 = con2.getJarFile();
assertTrue("http: JarFiles not the same", jf1 == jf2);
jf1.close();
}
use of java.util.zip.ZipFile in project robovm by robovm.
the class OldAndroidZipFileTest method scanZip.
static void scanZip(String fileName) throws IOException {
ZipFile zipFile = new ZipFile(fileName);
Enumeration fileList;
int idx = 0;
// System.out.println("Contents of " + zipFile + ":");
for (fileList = zipFile.entries(); fileList.hasMoreElements(); ) {
ZipEntry entry = (ZipEntry) fileList.nextElement();
// System.out.println(" " + entry.getName());
assertEquals(entry.getName(), "file-" + idx);
idx++;
}
zipFile.close();
}
use of java.util.zip.ZipFile in project robovm by robovm.
the class OldAndroidZipFileTest method read2.
/*
* Read compressed data from two different entries at the same time,
* to verify that the streams aren't getting confused. If we do
* something wrong, the inflater will choke and throw a ZipException.
*
* This doesn't test synchronization in multi-threaded use.
*/
static void read2(String fileName) throws IOException {
ZipFile zipFile;
ZipEntry entry1, entry2;
byte[] buf = new byte[16384];
InputStream stream1, stream2;
int len, totalLen1, totalLen2;
/* use file-1 and file-2 because the compressed data is large */
zipFile = new ZipFile(fileName);
entry1 = zipFile.getEntry("file-1");
entry2 = zipFile.getEntry("file-2");
/* make sure we got the right thing */
assertEquals("file-1", entry1.getName());
assertEquals("file-2", entry2.getName());
/* create streams */
stream1 = zipFile.getInputStream(entry1);
stream2 = zipFile.getInputStream(entry2);
/*
* Read a piece of file #1.
*/
totalLen1 = stream1.read(buf);
assertTrue("initial read failed on #1", totalLen1 >= 0);
/*
* Read a piece of file #2.
*/
totalLen2 = stream2.read(buf);
assertTrue("initial read failed on #2", totalLen2 >= 0);
/*
* Read the rest of file #1, and close the stream.
*
* If our streams are crossed up, we'll fail here.
*/
while ((len = stream1.read(buf)) > 0) {
totalLen1 += len;
}
assertEquals(SAMPLE_SIZE, totalLen1);
stream1.close();
/*
* Read the rest of file #2, and close the stream.
*/
while ((len = stream2.read(buf)) > 0) {
totalLen2 += len;
}
assertEquals(SAMPLE_SIZE, totalLen2);
stream2.close();
/*
* Open a new one.
*/
stream1 = zipFile.getInputStream(zipFile.getEntry("file-0"));
/*
* Close the ZipFile. According to the RI, none if its InputStreams can
* be read after this point.
*/
zipFile.close();
Exception error = null;
try {
stream1.read(buf);
} catch (Exception ex) {
error = ex;
}
assertNotNull("ZipFile shouldn't allow reading of closed files.", error);
}
use of java.util.zip.ZipFile in project robovm by robovm.
the class OldAndroidZipStressTest method testZipStressAllFiles.
public void testZipStressAllFiles() throws Exception {
long time0 = System.currentTimeMillis();
byte[] buffer = new byte[512];
for (File file : getFiles()) {
System.out.println("ZIP stress test processing " + file + "...");
ZipFile zip = new ZipFile(file);
Enumeration<? extends ZipEntry> entries = zip.entries();
while (entries.hasMoreElements()) {
InputStream stream = zip.getInputStream(entries.nextElement());
int j = stream.read(buffer);
while (j != -1) {
j = stream.read(buffer);
}
stream.close();
}
}
long time1 = System.currentTimeMillis();
System.out.println("ZIP stress test finished, time was " + (time1 - time0) + "ms");
}
use of java.util.zip.ZipFile in project robovm by robovm.
the class OldZipFileTest method setUp.
/**
* Sets up the fixture, for example, open a network connection. This method
* is called before a test is executed.
*/
@Override
protected void setUp() throws IOException {
// Create a local copy of the file since some tests want to alter information.
tempFileName = System.getProperty("java.io.tmpdir");
String separator = System.getProperty("file.separator");
if (tempFileName.charAt(tempFileName.length() - 1) == separator.charAt(0)) {
tempFileName = Support_PlatformFile.getNewPlatformFile(tempFileName, "gabba.zip");
} else {
tempFileName = Support_PlatformFile.getNewPlatformFile(tempFileName + separator, "gabba.zip");
}
File f = new File(tempFileName);
f.delete();
InputStream is = Support_Resources.getStream("hyts_ZipFile.zip");
FileOutputStream fos = new FileOutputStream(f);
byte[] rbuf = getAllBytesFromStream(is);
fos.write(rbuf, 0, rbuf.length);
is.close();
fos.close();
zfile = new ZipFile(f);
}
Aggregations