src/java.base/share/classes/java/util/jar/JarVerifier.java
changeset 51110 03f2bfdcb636
parent 50048 1c4fb292447c
child 52159 42244a052fbb
equal deleted inserted replaced
51109:6c5b01529873 51110:03f2bfdcb636
   435         VerifierStream(Manifest man,
   435         VerifierStream(Manifest man,
   436                        JarEntry je,
   436                        JarEntry je,
   437                        InputStream is,
   437                        InputStream is,
   438                        JarVerifier jv) throws IOException
   438                        JarVerifier jv) throws IOException
   439         {
   439         {
   440             this.is = is;
   440             this.is = Objects.requireNonNull(is);
   441             this.jv = jv;
   441             this.jv = jv;
   442             this.mev = new ManifestEntryVerifier(man);
   442             this.mev = new ManifestEntryVerifier(man);
   443             this.jv.beginEntry(je, mev);
   443             this.jv.beginEntry(je, mev);
   444             this.numLeft = je.getSize();
   444             this.numLeft = je.getSize();
   445             if (this.numLeft == 0)
   445             if (this.numLeft == 0)
   446                 this.jv.update(-1, this.mev);
   446                 this.jv.update(-1, this.mev);
   447         }
   447         }
   448 
   448 
   449         public int read() throws IOException
   449         public int read() throws IOException
   450         {
   450         {
       
   451             ensureOpen();
   451             if (numLeft > 0) {
   452             if (numLeft > 0) {
   452                 int b = is.read();
   453                 int b = is.read();
   453                 jv.update(b, mev);
   454                 jv.update(b, mev);
   454                 numLeft--;
   455                 numLeft--;
   455                 if (numLeft == 0)
   456                 if (numLeft == 0)
   459                 return -1;
   460                 return -1;
   460             }
   461             }
   461         }
   462         }
   462 
   463 
   463         public int read(byte b[], int off, int len) throws IOException {
   464         public int read(byte b[], int off, int len) throws IOException {
       
   465             ensureOpen();
   464             if ((numLeft > 0) && (numLeft < len)) {
   466             if ((numLeft > 0) && (numLeft < len)) {
   465                 len = (int)numLeft;
   467                 len = (int)numLeft;
   466             }
   468             }
   467 
   469 
   468             if (numLeft > 0) {
   470             if (numLeft > 0) {
   486             mev = null;
   488             mev = null;
   487             jv = null;
   489             jv = null;
   488         }
   490         }
   489 
   491 
   490         public int available() throws IOException {
   492         public int available() throws IOException {
       
   493             ensureOpen();
   491             return is.available();
   494             return is.available();
   492         }
   495         }
   493 
   496 
       
   497         private void ensureOpen() throws IOException {
       
   498             if (is == null) {
       
   499                 throw new IOException("stream closed");
       
   500             }
       
   501         }
   494     }
   502     }
   495 
   503 
   496     // Extended JavaUtilJarAccess CodeSource API Support
   504     // Extended JavaUtilJarAccess CodeSource API Support
   497 
   505 
   498     private Map<URL, Map<CodeSigner[], CodeSource>> urlToCodeSourceMap = new HashMap<>();
   506     private Map<URL, Map<CodeSigner[], CodeSource>> urlToCodeSourceMap = new HashMap<>();