Java Code Examples for org.apache.commons.compress.archivers.zip.ZipArchiveInputStream#read()

The following examples show how to use org.apache.commons.compress.archivers.zip.ZipArchiveInputStream#read() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GPXFileSystem.java    From tuxguitar with GNU Lesser General Public License v2.1 6 votes vote down vote up
public InputStream getFileContentsAsStream(String resource) throws Throwable {
	byte[] resourceBytes = null;

	ZipArchiveInputStream zipInputStream = new ZipArchiveInputStream(new ByteArrayInputStream(this.fsBuffer));
	ArchiveEntry zipEntry = null;
	while ((zipEntry = zipInputStream.getNextEntry()) != null) {
		if (zipEntry.getName().equals(resource)) {
			ByteArrayOutputStream out = new ByteArrayOutputStream();

			byte buffer[] = new byte[2048];
			int read = 0;
			while ((read = zipInputStream.read(buffer)) > 0) {
				out.write(buffer, 0, read);
			}

			resourceBytes = out.toByteArray();

			out.close();
		}
	}
	zipInputStream.close();

	return (resourceBytes != null ? new ByteArrayInputStream(resourceBytes) : null);
}
 
Example 2
Source File: ZipStreamer.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
public void extractTo(ZipArchiveInputStream zis, ArchiveEntry entry) throws IOException {
    int count = 0;
    int curCount = 0;
    byte[] data = new byte[BUFFER];

    while ((count = zis.read(data, 0, BUFFER)) != -1) {
        curCount += count;
        processInputData(entry.getName(), curCount);
   }

}