src/share/classes/java/util/zip/ZipFile.java

Print this page




 683 
 684     /*
 685      * Inner class implementing the input stream used to read a
 686      * (possibly compressed) zip file entry.
 687      */
 688    private class ZipFileInputStream extends InputStream {
 689         private volatile boolean closeRequested = false;
 690         protected long jzentry; // address of jzentry data
 691         private   long pos;     // current position within entry data
 692         protected long rem;     // number of remaining bytes within entry
 693         protected long size;    // uncompressed size of this entry
 694 
 695         ZipFileInputStream(long jzentry) {
 696             pos = 0;
 697             rem = getEntryCSize(jzentry);
 698             size = getEntrySize(jzentry);
 699             this.jzentry = jzentry;
 700         }
 701 
 702         public int read(byte b[], int off, int len) throws IOException {

 703             if (rem == 0) {
 704                 return -1;
 705             }
 706             if (len <= 0) {
 707                 return 0;
 708             }
 709             if (len > rem) {
 710                 len = (int) rem;
 711             }
 712             synchronized (ZipFile.this) {
 713                 ensureOpenOrZipException();
 714 

 715                 len = ZipFile.read(ZipFile.this.jzfile, jzentry, pos, b,
 716                                    off, len);
 717             }
 718             if (len > 0) {
 719                 pos += len;
 720                 rem -= len;
 721             }

 722             if (rem == 0) {
 723                 close();
 724             }
 725             return len;
 726         }
 727 
 728         public int read() throws IOException {
 729             byte[] b = new byte[1];
 730             if (read(b, 0, 1) == 1) {
 731                 return b[0] & 0xff;
 732             } else {
 733                 return -1;
 734             }
 735         }
 736 
 737         public long skip(long n) {
 738             if (n > rem)
 739                 n = rem;
 740             pos += n;
 741             rem -= n;




 683 
 684     /*
 685      * Inner class implementing the input stream used to read a
 686      * (possibly compressed) zip file entry.
 687      */
 688    private class ZipFileInputStream extends InputStream {
 689         private volatile boolean closeRequested = false;
 690         protected long jzentry; // address of jzentry data
 691         private   long pos;     // current position within entry data
 692         protected long rem;     // number of remaining bytes within entry
 693         protected long size;    // uncompressed size of this entry
 694 
 695         ZipFileInputStream(long jzentry) {
 696             pos = 0;
 697             rem = getEntryCSize(jzentry);
 698             size = getEntrySize(jzentry);
 699             this.jzentry = jzentry;
 700         }
 701 
 702         public int read(byte b[], int off, int len) throws IOException {
 703             synchronized (ZipFile.this) {
 704                 if (rem == 0) {
 705                     return -1;
 706                 }
 707                 if (len <= 0) {
 708                     return 0;
 709                 }
 710                 if (len > rem) {
 711                     len = (int) rem;
 712                 }


 713 
 714                 ensureOpenOrZipException();
 715                 len = ZipFile.read(ZipFile.this.jzfile, jzentry, pos, b,
 716                                    off, len);

 717                 if (len > 0) {
 718                     pos += len;
 719                     rem -= len;
 720                 }
 721             }
 722             if (rem == 0) {
 723                 close();
 724             }
 725             return len;
 726         }
 727 
 728         public int read() throws IOException {
 729             byte[] b = new byte[1];
 730             if (read(b, 0, 1) == 1) {
 731                 return b[0] & 0xff;
 732             } else {
 733                 return -1;
 734             }
 735         }
 736 
 737         public long skip(long n) {
 738             if (n > rem)
 739                 n = rem;
 740             pos += n;
 741             rem -= n;