1 /* |
|
2 * Copyright (c) 1997, 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 /* @test |
|
25 @bug 4017158 |
|
26 @summary Check for correct implementation of ByteArrayInputStream.write |
|
27 */ |
|
28 |
|
29 import java.io.*; |
|
30 |
|
31 |
|
32 public class WriteBounds{ |
|
33 |
|
34 private static void dotest(byte[] b, int off, int len, |
|
35 ByteArrayOutputStream baos) |
|
36 throws Exception |
|
37 { |
|
38 |
|
39 if (b != null) { |
|
40 System.err.println("ByteArrayOutStream.write -- b.length = " + |
|
41 b.length + " off = " + off + " len = " + len); |
|
42 } |
|
43 else{ |
|
44 System.err.println("ByteArrayOutStream.write - b is null off = " + |
|
45 off + " len = " + len); |
|
46 } |
|
47 |
|
48 try { |
|
49 baos.write(b, off, len); |
|
50 } catch (IndexOutOfBoundsException e) { |
|
51 System.err.println("IndexOutOfBoundsException is thrown -- OKAY"); |
|
52 } catch (NullPointerException e) { |
|
53 System.err.println("NullPointerException is thrown -- OKAY"); |
|
54 } catch (Throwable e){ |
|
55 throw new RuntimeException("Unexpected Exception is thrown"); |
|
56 } |
|
57 |
|
58 } |
|
59 |
|
60 public static void main( String argv[] ) throws Exception { |
|
61 |
|
62 ByteArrayOutputStream y1; |
|
63 byte array1[]={1 , 2 , 3 , 4 , 5}; // Simple array |
|
64 |
|
65 //Create new ByteArrayOutputStream object |
|
66 y1 = new ByteArrayOutputStream(5); |
|
67 |
|
68 dotest(array1, 0, Integer.MAX_VALUE , y1); |
|
69 dotest(array1, 0, array1.length+100, y1); |
|
70 dotest(array1, -1, 2, y1); |
|
71 dotest(array1, 0, -1, y1); |
|
72 dotest(null, 0, 2, y1); |
|
73 |
|
74 } |
|
75 |
|
76 } |
|