Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ZipInputStream zis = new ZipInputStream(inputStream);
- ZipEntry ze;
- long totalBytesRead = 0;
- while ((ze = zis.getNextEntry()) != null) {
- BufferedOutputStream outStream = new BufferedOutputStream(new FileOutputStream(ze.getName()));
- byte[] buffer = new byte[4096];
- int i;
- while ((i = zis.read(buffer)) != -1) {
- totalBytesRead+=i;
- outStream.write(buffer,0,i);
- }
- outStream.close();
- }
- inputStream.close();
- import java.io.FilterInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- /**
- *
- */
- /**
- * @author clint
- *
- */
- public class ByteCountingInputStream extends FilterInputStream {
- public int totalRead = 0;
- /**
- * @param in
- */
- protected ByteCountingInputStream(InputStream in) {
- super(in);
- // TODO Auto-generated constructor stub
- }
- /* (non-Javadoc)
- * @see java.io.FilterInputStream#read()
- */
- @Override
- public int read() throws IOException {
- int ret = super.read();
- totalRead++;
- return ret;
- }
- /* (non-Javadoc)
- * @see java.io.FilterInputStream#read(byte[], int, int)
- */
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- int ret = super.read(b, off, len);
- totalRead += ret;
- return ret;
- }
- /* (non-Javadoc)
- * @see java.io.FilterInputStream#read(byte[])
- */
- @Override
- public int read(byte[] b) throws IOException {
- int ret = super.read(b);
- totalRead += ret;
- return ret;
- }
- /* (non-Javadoc)
- * @see java.io.FilterInputStream#skip(long)
- */
- @Override
- public long skip(long n) throws IOException {
- //What to do?
- return super.skip(n);
- }
- /**
- * @return the totalRead
- */
- protected int getTotalRead() {
- return this.totalRead;
- }
- }
- ZipInputStream zis = new ZipInputStream(new ByteCountingInputStream(inputStream));
- import java.io.FilterInputStream;
- import java.io.IOException;
- import java.io.InputStream;
- public class CountingInputStream extends FilterInputStream {
- private long totalBytes = 0;
- protected CountingInputStream(InputStream in) {
- super(in);
- }
- public int getTotalBytesRead() {
- return totalBytes;
- }
- @Override
- public int read() throws IOException {
- int byteValue = super.read();
- if (byteValue != -1) totalBytes++;
- return byteValue;
- }
- @Override
- public int read(byte[] b) throws IOException {
- int bytesRead = super.read(b);
- if (bytesRead != -1) totalBytes+=bytesRead;
- return bytesRead;
- }
- @Override
- public int read(byte[] b, int off, int len) throws IOException {
- int bytesRead = super.read(b,off,len);
- if (bytesRead != -1) totalBytes+=bytesRead;
- return bytesRead;
- }
- }
Add Comment
Please, Sign In to add comment