1 /*
2 * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 4008296 4008293 4190090 4193729
27 * @summary Check for correct handling of parameters to
28 * XXXXInputStream.read(b, off, len).
29 *
30 */
31
32 import java.io.*;
33 import java.util.zip.ZipInputStream;
34 import java.util.zip.InflaterInputStream;
35 import java.util.zip.DeflaterOutputStream;
36
37 public class ReadParams {
38
39 /* check for correct handling of different values of off and len */
40 public static void doTest(InputStream in) throws Exception {
41
42 int off[] = {-1, -1, 0, 0, 33, 33, 0, 32, 32, 4, 1, 0, -1,
43 Integer.MAX_VALUE, 1, Integer.MIN_VALUE,
44 Integer.MIN_VALUE, 1};
45 int len[] = {-1, 0, -1, 33, 0, 4, 32, 0, 4, 16, 31, 0,
46 Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE,
180 doTest(sis);
181 doTest1(sis);
182 sis.close();
183
184 ZipInputStream zis = new ZipInputStream(new FileInputStream(fn));
185 doTest(zis);
186 doTest1(zis);
187 zis.close();
188
189 byte[] data = new byte[256];
190 ByteArrayOutputStream bos = new ByteArrayOutputStream();
191 DeflaterOutputStream dos = new DeflaterOutputStream(bos);
192 dos.write(data, 0, data.length);
193 dos.close();
194 InflaterInputStream ifs = new InflaterInputStream
195 (new ByteArrayInputStream(bos.toByteArray()));
196 doTest(ifs);
197 doTest1(ifs);
198 ifs.close();
199
200 /* cleanup */
201 fn.delete();
202 }
203 }
204
205 /* An InputStream class used in the above tests */
206 class MyInputStream extends InputStream {
207
208 private int readctr = 0;
209 private long endoffile;
210
211 public MyInputStream(long endoffile) {
212 this.endoffile = endoffile;
213 }
214
215 public int read() {
216 if (readctr == endoffile) {
217 return -1;
218 }
219 else {
|
1 /*
2 * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 4008296 4008293 4190090 4193729 4358774
27 * @summary Check for correct handling of parameters to
28 * XXXXInputStream.read(b, off, len).
29 *
30 */
31
32 import java.io.*;
33 import java.util.zip.ZipInputStream;
34 import java.util.zip.InflaterInputStream;
35 import java.util.zip.DeflaterOutputStream;
36
37 public class ReadParams {
38
39 /* check for correct handling of different values of off and len */
40 public static void doTest(InputStream in) throws Exception {
41
42 int off[] = {-1, -1, 0, 0, 33, 33, 0, 32, 32, 4, 1, 0, -1,
43 Integer.MAX_VALUE, 1, Integer.MIN_VALUE,
44 Integer.MIN_VALUE, 1};
45 int len[] = {-1, 0, -1, 33, 0, 4, 32, 0, 4, 16, 31, 0,
46 Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE,
180 doTest(sis);
181 doTest1(sis);
182 sis.close();
183
184 ZipInputStream zis = new ZipInputStream(new FileInputStream(fn));
185 doTest(zis);
186 doTest1(zis);
187 zis.close();
188
189 byte[] data = new byte[256];
190 ByteArrayOutputStream bos = new ByteArrayOutputStream();
191 DeflaterOutputStream dos = new DeflaterOutputStream(bos);
192 dos.write(data, 0, data.length);
193 dos.close();
194 InflaterInputStream ifs = new InflaterInputStream
195 (new ByteArrayInputStream(bos.toByteArray()));
196 doTest(ifs);
197 doTest1(ifs);
198 ifs.close();
199
200 InputStream nis = InputStream.nullStream();
201 doTest(nis);
202 doTest1(nis);
203 nis.close();
204
205 /* cleanup */
206 fn.delete();
207 }
208 }
209
210 /* An InputStream class used in the above tests */
211 class MyInputStream extends InputStream {
212
213 private int readctr = 0;
214 private long endoffile;
215
216 public MyInputStream(long endoffile) {
217 this.endoffile = endoffile;
218 }
219
220 public int read() {
221 if (readctr == endoffile) {
222 return -1;
223 }
224 else {
|