src/java.base/share/classes/java/util/zip/ZipFile.java
changeset 58864 fba8635290df
parent 57670 cffcc4c5a5ba
child 59201 b24f4caa1411
equal deleted inserted replaced
58863:c16ac7a2eba4 58864:fba8635290df
   865      * (possibly compressed) zip file entry.
   865      * (possibly compressed) zip file entry.
   866      */
   866      */
   867     private class ZipFileInputStream extends InputStream {
   867     private class ZipFileInputStream extends InputStream {
   868         private volatile boolean closeRequested;
   868         private volatile boolean closeRequested;
   869         private   long pos;     // current position within entry data
   869         private   long pos;     // current position within entry data
       
   870         private   long startingPos; // Start position for the entry data
   870         protected long rem;     // number of remaining bytes within entry
   871         protected long rem;     // number of remaining bytes within entry
   871         protected long size;    // uncompressed size of this entry
   872         protected long size;    // uncompressed size of this entry
   872 
   873 
   873         ZipFileInputStream(byte[] cen, int cenpos) {
   874         ZipFileInputStream(byte[] cen, int cenpos) {
   874             rem = CENSIZ(cen, cenpos);
   875             rem = CENSIZ(cen, cenpos);
   936                 }
   937                 }
   937                 if (LOCSIG(loc) != LOCSIG) {
   938                 if (LOCSIG(loc) != LOCSIG) {
   938                     throw new ZipException("ZipFile invalid LOC header (bad signature)");
   939                     throw new ZipException("ZipFile invalid LOC header (bad signature)");
   939                 }
   940                 }
   940                 pos += LOCHDR + LOCNAM(loc) + LOCEXT(loc);
   941                 pos += LOCHDR + LOCNAM(loc) + LOCEXT(loc);
       
   942                 startingPos = pos; // Save starting position for the entry
   941             }
   943             }
   942             return pos;
   944             return pos;
   943         }
   945         }
   944 
   946 
   945         public int read(byte b[], int off, int len) throws IOException {
   947         public int read(byte b[], int off, int len) throws IOException {
   977         }
   979         }
   978 
   980 
   979         public long skip(long n) throws IOException {
   981         public long skip(long n) throws IOException {
   980             synchronized (ZipFile.this) {
   982             synchronized (ZipFile.this) {
   981                 initDataOffset();
   983                 initDataOffset();
   982                 if (n > rem) {
   984                 long newPos = pos + n;
   983                     n = rem;
   985                 if (n > 0) {
       
   986                     // If we overflowed adding the skip value or are moving
       
   987                     // past EOF, set the skip value to number of bytes remaining
       
   988                     // to reach EOF
       
   989                     if (newPos < 0 || n > rem) {
       
   990                         n = rem;
       
   991                     }
       
   992                 } else if (newPos < startingPos) {
       
   993                     // Tried to position before BOF so set position to the
       
   994                     // BOF and return the number of bytes we moved backwards
       
   995                     // to reach BOF
       
   996                     n = startingPos - pos;
   984                 }
   997                 }
   985                 pos += n;
   998                 pos += n;
   986                 rem -= n;
   999                 rem -= n;
   987             }
  1000             }
   988             if (rem == 0) {
  1001             if (rem == 0) {