74 */
75 public JarInputStream(InputStream in, boolean verify) throws IOException {
76 super(in);
77 this.doVerify = verify;
78
79 // This implementation assumes the META-INF/MANIFEST.MF entry
80 // should be either the first or the second entry (when preceded
81 // by the dir META-INF/). It skips the META-INF/ and then
82 // "consumes" the MANIFEST.MF to initialize the Manifest object.
83 JarEntry e = (JarEntry)super.getNextEntry();
84 if (e != null && e.getName().equalsIgnoreCase("META-INF/"))
85 e = (JarEntry)super.getNextEntry();
86 first = checkManifest(e);
87 }
88
89 private JarEntry checkManifest(JarEntry e)
90 throws IOException
91 {
92 if (e != null && JarFile.MANIFEST_NAME.equalsIgnoreCase(e.getName())) {
93 man = new Manifest();
94 byte bytes[] = getBytes(new BufferedInputStream(this));
95 man.read(new ByteArrayInputStream(bytes));
96 closeEntry();
97 if (doVerify) {
98 jv = new JarVerifier(bytes);
99 mev = new ManifestEntryVerifier(man);
100 }
101 return (JarEntry)super.getNextEntry();
102 }
103 return e;
104 }
105
106 private byte[] getBytes(InputStream is)
107 throws IOException
108 {
109 byte[] buffer = new byte[8192];
110 ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
111 int n;
112 while ((n = is.read(buffer, 0, buffer.length)) != -1) {
113 baos.write(buffer, 0, n);
114 }
|
74 */
75 public JarInputStream(InputStream in, boolean verify) throws IOException {
76 super(in);
77 this.doVerify = verify;
78
79 // This implementation assumes the META-INF/MANIFEST.MF entry
80 // should be either the first or the second entry (when preceded
81 // by the dir META-INF/). It skips the META-INF/ and then
82 // "consumes" the MANIFEST.MF to initialize the Manifest object.
83 JarEntry e = (JarEntry)super.getNextEntry();
84 if (e != null && e.getName().equalsIgnoreCase("META-INF/"))
85 e = (JarEntry)super.getNextEntry();
86 first = checkManifest(e);
87 }
88
89 private JarEntry checkManifest(JarEntry e)
90 throws IOException
91 {
92 if (e != null && JarFile.MANIFEST_NAME.equalsIgnoreCase(e.getName())) {
93 man = new Manifest();
94 byte[] bytes = getBytes(new BufferedInputStream(this));
95 man.read(new ByteArrayInputStream(bytes));
96 closeEntry();
97 if (doVerify) {
98 jv = new JarVerifier(bytes);
99 mev = new ManifestEntryVerifier(man);
100 }
101 return (JarEntry)super.getNextEntry();
102 }
103 return e;
104 }
105
106 private byte[] getBytes(InputStream is)
107 throws IOException
108 {
109 byte[] buffer = new byte[8192];
110 ByteArrayOutputStream baos = new ByteArrayOutputStream(2048);
111 int n;
112 while ((n = is.read(buffer, 0, buffer.length)) != -1) {
113 baos.write(buffer, 0, n);
114 }
|