public void close() throws IOException { getZipFile().close(); }
public void close() throws IOException { getZipFile().close(); }
public void close() throws IOException { getZipFile().close(); }
/** * {@inheritDoc} */ @Override public void handle(IdentificationRequest request) throws IOException { final ZipFile zipFile = new ZipFile(new ReaderReadOnlyFile(request.getWindowReader())); try { Iterable<ZipEntry> iterable = new Iterable<ZipEntry>() { @Override public final Iterator<ZipEntry> iterator() { return new ZipFileIterator(zipFile); } }; ZipArchiveWalker walker = new ZipArchiveWalker(request.getIdentifier(), zipFile); walker.walk(iterable); } finally { if (zipFile != null) { zipFile.close(); } } }
/** * {@inheritDoc} */ @Override public void handle(IdentificationRequest request) throws IOException { final ZipFile zipFile = new ZipFile(new TrueZipReader(request.getWindowReader())); try { Iterable<ZipEntry> iterable = new Iterable<ZipEntry>() { @Override public final Iterator<ZipEntry> iterator() { return new ZipFileIterator(zipFile); } }; ZipArchiveWalker walker = new ZipArchiveWalker(request.getIdentifier(), zipFile); walker.walk(iterable); } finally { if (zipFile != null) { zipFile.close(); } } }
@Test public final void testGoodGetCheckedInputStream() throws IOException { // Create test ZIP file. final String name = "entry"; final ZipOutputStream zipOut = newZipOutputStream(new FileOutputStream(file)); zipOut.putNextEntry(newEntry(name)); zipOut.write(data); zipOut.close(); final ZipFile zipIn = newZipFile(file); // Open checked input stream and join immediately. InputStream in = zipIn.getCheckedInputStream(name); in.close(); // Open checked input stream and read fully, using multiple methods. in = zipIn.getCheckedInputStream(name); final int n = data.length / 4; in.skip(n); in.read(new byte[n]); in.read(new byte[n], 0, n); while (in.read() != -1) { // read until EOF } in.close(); zipIn.close(); }
@Test public final void testWriteAndReadSingleBytes() throws IOException { final ZipOutputStream zipOut = newZipOutputStream(new FileOutputStream(file)); zipOut.putNextEntry(newEntry("file")); for (int i = 0; i < data.length; i++) zipOut.write(data[i]); zipOut.close(); final ZipFile zipIn = newZipFile(file); InputStream in = zipIn.getInputStream("file"); for (int i = 0, c; (c = in.read()) != -1; i++) assertEquals(data[i] & 0xFF, c); in.close(); zipIn.close(); }
@Test public final void testPreambleOfEmptyZipFile() throws IOException { // Create empty ZIP file. newZipOutputStream(new FileOutputStream(file)).close(); // Assert that the empty ZIP file has no preamble. final ZipFile zipIn = newZipFile(file); try { assertEquals(0, zipIn.getPreambleLength()); final InputStream in = zipIn.getPreambleInputStream(); try { assertEquals(-1, in.read()); } finally { in.close(); } } finally { zipIn.close(); } }
private void append( final int off, final int len, final byte[] data) throws IOException { final ZipOutputStream out; if (file.exists()) { final ZipFile in = newZipFile(file); in.close(); out = newZipOutputStream(new FileOutputStream(file, true), in); } else { out = newZipOutputStream(new FileOutputStream(file)); } try { for (int i = 0; i < len; i++) { final String name = off + i + ".txt"; out.putNextEntry(newEntry(name)); out.write(data); } } finally { out.close(); } } }
zipFile.close();
@Test public final void testGetInputStream() throws IOException { final ZipOutputStream zipOut = newZipOutputStream(new FileOutputStream(file)); try { zipOut.putNextEntry(newEntry("foo")); } finally { zipOut.close(); } final ZipFile zipIn = newZipFile(file); try { zipIn.getInputStream("foo").close(); assertNull(zipIn.getInputStream("bar")); } finally { zipIn.close(); } }
runConcurrent(nThreads, new CheckAllEntriesFactory()).join(); } finally { zin.close();