1 /* |
1 /* |
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
54 /** |
54 /** |
55 * Creates a new <code>JarInputStream</code> and reads the optional |
55 * Creates a new <code>JarInputStream</code> and reads the optional |
56 * manifest. If a manifest is present, also attempts to verify |
56 * manifest. If a manifest is present, also attempts to verify |
57 * the signatures if the JarInputStream is signed. |
57 * the signatures if the JarInputStream is signed. |
58 * @param in the actual input stream |
58 * @param in the actual input stream |
59 * @exception IOException if an I/O error has occurred |
59 * @throws IOException if an I/O error has occurred |
60 */ |
60 */ |
61 public JarInputStream(InputStream in) throws IOException { |
61 public JarInputStream(InputStream in) throws IOException { |
62 this(in, true); |
62 this(in, true); |
63 } |
63 } |
64 |
64 |
68 * to verify the signatures if the JarInputStream is signed. |
68 * to verify the signatures if the JarInputStream is signed. |
69 * |
69 * |
70 * @param in the actual input stream |
70 * @param in the actual input stream |
71 * @param verify whether or not to verify the JarInputStream if |
71 * @param verify whether or not to verify the JarInputStream if |
72 * it is signed. |
72 * it is signed. |
73 * @exception IOException if an I/O error has occurred |
73 * @throws IOException if an I/O error has occurred |
74 */ |
74 */ |
75 public JarInputStream(InputStream in, boolean verify) throws IOException { |
75 public JarInputStream(InputStream in, boolean verify) throws IOException { |
76 super(in); |
76 super(in); |
77 this.doVerify = verify; |
77 this.doVerify = verify; |
78 |
78 |
129 /** |
129 /** |
130 * Reads the next ZIP file entry and positions the stream at the |
130 * Reads the next ZIP file entry and positions the stream at the |
131 * beginning of the entry data. If verification has been enabled, |
131 * beginning of the entry data. If verification has been enabled, |
132 * any invalid signature detected while positioning the stream for |
132 * any invalid signature detected while positioning the stream for |
133 * the next entry will result in an exception. |
133 * the next entry will result in an exception. |
134 * @exception ZipException if a ZIP file error has occurred |
134 * @throws ZipException if a ZIP file error has occurred |
135 * @exception IOException if an I/O error has occurred |
135 * @throws IOException if an I/O error has occurred |
136 * @exception SecurityException if any of the jar file entries |
136 * @throws SecurityException if any of the jar file entries |
137 * are incorrectly signed. |
137 * are incorrectly signed. |
138 */ |
138 */ |
139 public ZipEntry getNextEntry() throws IOException { |
139 public ZipEntry getNextEntry() throws IOException { |
140 JarEntry e; |
140 JarEntry e; |
141 if (first == null) { |
141 if (first == null) { |
168 * Reads the next JAR file entry and positions the stream at the |
168 * Reads the next JAR file entry and positions the stream at the |
169 * beginning of the entry data. If verification has been enabled, |
169 * beginning of the entry data. If verification has been enabled, |
170 * any invalid signature detected while positioning the stream for |
170 * any invalid signature detected while positioning the stream for |
171 * the next entry will result in an exception. |
171 * the next entry will result in an exception. |
172 * @return the next JAR file entry, or null if there are no more entries |
172 * @return the next JAR file entry, or null if there are no more entries |
173 * @exception ZipException if a ZIP file error has occurred |
173 * @throws ZipException if a ZIP file error has occurred |
174 * @exception IOException if an I/O error has occurred |
174 * @throws IOException if an I/O error has occurred |
175 * @exception SecurityException if any of the jar file entries |
175 * @throws SecurityException if any of the jar file entries |
176 * are incorrectly signed. |
176 * are incorrectly signed. |
177 */ |
177 */ |
178 public JarEntry getNextJarEntry() throws IOException { |
178 public JarEntry getNextJarEntry() throws IOException { |
179 return (JarEntry)getNextEntry(); |
179 return (JarEntry)getNextEntry(); |
180 } |
180 } |
190 * @param b the buffer into which the data is read |
190 * @param b the buffer into which the data is read |
191 * @param off the start offset in the destination array <code>b</code> |
191 * @param off the start offset in the destination array <code>b</code> |
192 * @param len the maximum number of bytes to read |
192 * @param len the maximum number of bytes to read |
193 * @return the actual number of bytes read, or -1 if the end of the |
193 * @return the actual number of bytes read, or -1 if the end of the |
194 * entry is reached |
194 * entry is reached |
195 * @exception NullPointerException If <code>b</code> is <code>null</code>. |
195 * @throws NullPointerException If <code>b</code> is <code>null</code>. |
196 * @exception IndexOutOfBoundsException If <code>off</code> is negative, |
196 * @throws IndexOutOfBoundsException If <code>off</code> is negative, |
197 * <code>len</code> is negative, or <code>len</code> is greater than |
197 * <code>len</code> is negative, or <code>len</code> is greater than |
198 * <code>b.length - off</code> |
198 * <code>b.length - off</code> |
199 * @exception ZipException if a ZIP file error has occurred |
199 * @throws ZipException if a ZIP file error has occurred |
200 * @exception IOException if an I/O error has occurred |
200 * @throws IOException if an I/O error has occurred |
201 * @exception SecurityException if any of the jar file entries |
201 * @throws SecurityException if any of the jar file entries |
202 * are incorrectly signed. |
202 * are incorrectly signed. |
203 */ |
203 */ |
204 public int read(byte[] b, int off, int len) throws IOException { |
204 public int read(byte[] b, int off, int len) throws IOException { |
205 int n; |
205 int n; |
206 if (first == null) { |
206 if (first == null) { |