}
try
{
WeakZipFileFactory factory = new WeakZipFileFactory(1);
WeakZipFile zipFile = factory.create(tmpZip);
assertTrue("Zip file not recorded.",
factory.getZipZiles().contains(zipFile));
assertTrue("Open zip file not recorded.",
factory.getOpenZipZiles().contains(zipFile));
ZipEntry ze = zipFile.getEntry(ENTRY_NAME);
assertNotNull("Zip entry not found", ze);
byte[] firstHalf = new byte[contentBytes.length / 2];
byte[] secondHalf = new byte[contentBytes.length - firstHalf.length];
InputStream is = zipFile.getInputStream(ze);
is.read(firstHalf);
zipFile.closeWeakly();
assertTrue("Zip file not recorded.",
factory.getZipZiles().contains(zipFile));
assertFalse("Open zip file still recorded.",
factory.getOpenZipZiles().contains(zipFile));
is.read(secondHalf);
assertTrue("Zip file not recorded.",
factory.getZipZiles().contains(zipFile));
assertTrue("Open zip file not recorded.",
factory.getOpenZipZiles().contains(zipFile));
byte[] complete = new byte[firstHalf.length + secondHalf.length];
System.arraycopy(firstHalf, 0, complete, 0, firstHalf.length);
System.arraycopy(secondHalf, 0, complete, firstHalf.length, secondHalf.length);
String completeString = new String(complete);
assertEquals(contentString, completeString);
zipFile.close();
}
catch (IOException ex)
{
fail("Unable to read zip file entry: " + ex);
}