< prev index next >

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

Print this page




 989          * be different from the CEN extra data size. Since we cannot trust
 990          * the CEN extra data size, we need to read the LOC to determine
 991          * the entry data offset.
 992          */
 993         private long initDataOffset() throws IOException {
 994             if (pos <= 0) {
 995                 byte[] loc = new byte[LOCHDR];
 996                 pos = -pos;
 997                 int len = ZipFile.this.res.zsrc.readFullyAt(loc, 0, loc.length, pos);
 998                 if (len != LOCHDR) {
 999                     throw new ZipException("ZipFile error reading zip file");
1000                 }
1001                 if (LOCSIG(loc) != LOCSIG) {
1002                     throw new ZipException("ZipFile invalid LOC header (bad signature)");
1003                 }
1004                 pos += LOCHDR + LOCNAM(loc) + LOCEXT(loc);
1005             }
1006             return pos;
1007         }
1008 
1009         public int read(byte b[], int off, int len) throws IOException {
1010             synchronized (ZipFile.this) {
1011                 ensureOpenOrZipException();
1012                 initDataOffset();
1013                 if (rem == 0) {
1014                     return -1;
1015                 }
1016                 if (len > rem) {
1017                     len = (int) rem;
1018                 }
1019                 if (len <= 0) {
1020                     return 0;
1021                 }
1022                 len = ZipFile.this.res.zsrc.readAt(b, off, len, pos);
1023                 if (len > 0) {
1024                     pos += len;
1025                     rem -= len;
1026                 }
1027             }
1028             if (rem == 0) {
1029                 close();




 989          * be different from the CEN extra data size. Since we cannot trust
 990          * the CEN extra data size, we need to read the LOC to determine
 991          * the entry data offset.
 992          */
 993         private long initDataOffset() throws IOException {
 994             if (pos <= 0) {
 995                 byte[] loc = new byte[LOCHDR];
 996                 pos = -pos;
 997                 int len = ZipFile.this.res.zsrc.readFullyAt(loc, 0, loc.length, pos);
 998                 if (len != LOCHDR) {
 999                     throw new ZipException("ZipFile error reading zip file");
1000                 }
1001                 if (LOCSIG(loc) != LOCSIG) {
1002                     throw new ZipException("ZipFile invalid LOC header (bad signature)");
1003                 }
1004                 pos += LOCHDR + LOCNAM(loc) + LOCEXT(loc);
1005             }
1006             return pos;
1007         }
1008 
1009         public int read(byte[] b, int off, int len) throws IOException {
1010             synchronized (ZipFile.this) {
1011                 ensureOpenOrZipException();
1012                 initDataOffset();
1013                 if (rem == 0) {
1014                     return -1;
1015                 }
1016                 if (len > rem) {
1017                     len = (int) rem;
1018                 }
1019                 if (len <= 0) {
1020                     return 0;
1021                 }
1022                 len = ZipFile.this.res.zsrc.readAt(b, off, len, pos);
1023                 if (len > 0) {
1024                     pos += len;
1025                     rem -= len;
1026                 }
1027             }
1028             if (rem == 0) {
1029                 close();


< prev index next >