1049 if (readFullyAt(cen, 0, cen.length, cenpos) != end.cenlen + ENDHDR) {
1050 zerror("read CEN tables failed");
1051 }
1052 // Iterate through the entries in the central directory
1053 inodes = new LinkedHashMap<>(end.centot + 1);
1054 int pos = 0;
1055 int limit = cen.length - ENDHDR;
1056 while (pos < limit) {
1057 if (CENSIG(cen, pos) != CENSIG)
1058 zerror("invalid CEN header (bad signature)");
1059 int method = CENHOW(cen, pos);
1060 int nlen = CENNAM(cen, pos);
1061 int elen = CENEXT(cen, pos);
1062 int clen = CENCOM(cen, pos);
1063 if ((CENFLG(cen, pos) & 1) != 0)
1064 zerror("invalid CEN header (encrypted entry)");
1065 if (method != METHOD_STORED && method != METHOD_DEFLATED)
1066 zerror("invalid CEN header (unsupported compression method: " + method + ")");
1067 if (pos + CENHDR + nlen > limit)
1068 zerror("invalid CEN header (bad header size)");
1069 byte[] name = Arrays.copyOfRange(cen, pos + CENHDR, pos + CENHDR + nlen);
1070 IndexNode inode = new IndexNode(name, pos);
1071 inodes.put(inode, inode);
1072 // skip ext and comment
1073 pos += (CENHDR + nlen + elen + clen);
1074 }
1075 if (pos + ENDHDR != cen.length) {
1076 zerror("invalid CEN header (bad header size)");
1077 }
1078 buildNodeTree();
1079 return cen;
1080 }
1081
1082 private void ensureOpen() throws IOException {
1083 if (!isOpen)
1084 throw new ClosedFileSystemException();
1085 }
1086
1087 // Creates a new empty temporary file in the same directory as the
1088 // specified file. A variant of Files.createTempFile.
1089 private Path createTempFileInSameDirectoryAs(Path path)
1090 throws IOException
1091 {
|
1049 if (readFullyAt(cen, 0, cen.length, cenpos) != end.cenlen + ENDHDR) {
1050 zerror("read CEN tables failed");
1051 }
1052 // Iterate through the entries in the central directory
1053 inodes = new LinkedHashMap<>(end.centot + 1);
1054 int pos = 0;
1055 int limit = cen.length - ENDHDR;
1056 while (pos < limit) {
1057 if (CENSIG(cen, pos) != CENSIG)
1058 zerror("invalid CEN header (bad signature)");
1059 int method = CENHOW(cen, pos);
1060 int nlen = CENNAM(cen, pos);
1061 int elen = CENEXT(cen, pos);
1062 int clen = CENCOM(cen, pos);
1063 if ((CENFLG(cen, pos) & 1) != 0)
1064 zerror("invalid CEN header (encrypted entry)");
1065 if (method != METHOD_STORED && method != METHOD_DEFLATED)
1066 zerror("invalid CEN header (unsupported compression method: " + method + ")");
1067 if (pos + CENHDR + nlen > limit)
1068 zerror("invalid CEN header (bad header size)");
1069 int startIndex = pos + CENHDR;
1070 int endIndex = startIndex + nlen;
1071 startIndex = ((nlen > 0) && (char)cen[startIndex] == '/') ? startIndex + 1 : startIndex;
1072 byte[] name = Arrays.copyOfRange(cen, startIndex, endIndex);
1073 if(name.length > 0){
1074 IndexNode inode = new IndexNode(name, pos);
1075 inodes.put(inode, inode);
1076 }
1077 // skip ext and comment
1078 pos += (CENHDR + nlen + elen + clen);
1079 }
1080 if (pos + ENDHDR != cen.length) {
1081 zerror("invalid CEN header (bad header size)");
1082 }
1083 buildNodeTree();
1084 return cen;
1085 }
1086
1087 private void ensureOpen() throws IOException {
1088 if (!isOpen)
1089 throw new ClosedFileSystemException();
1090 }
1091
1092 // Creates a new empty temporary file in the same directory as the
1093 // specified file. A variant of Files.createTempFile.
1094 private Path createTempFileInSameDirectoryAs(Path path)
1095 throws IOException
1096 {
|