< prev index next >

src/share/demo/nio/zipfs/src/com/sun/nio/zipfs/ZipFileSystem.java

Print this page




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     {




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 
1071             name = (name.length >0 && name[0] == 47) ? Arrays.copyOfRange(name, 1, name.length) : name;
1072 
1073             if(name.length > 0)
1074             {
1075                 IndexNode inode = new IndexNode(name, pos);
1076                 inodes.put(inode, inode);
1077             }
1078 
1079             // skip ext and comment
1080             pos += (CENHDR + nlen + elen + clen);
1081         }
1082         if (pos + ENDHDR != cen.length) {
1083             zerror("invalid CEN header (bad header size)");
1084         }
1085         buildNodeTree();
1086         return cen;
1087     }
1088 
1089     private void ensureOpen() throws IOException {
1090         if (!isOpen)
1091             throw new ClosedFileSystemException();
1092     }
1093 
1094     // Creates a new empty temporary file in the same directory as the
1095     // specified file.  A variant of Files.createTempFile.
1096     private Path createTempFileInSameDirectoryAs(Path path)
1097         throws IOException
1098     {


< prev index next >