blob: 0ec1e599a9b0412adc60d08bb18e9e0ffd67da3a [file] [log] [blame]
duke6e45e102007-12-01 00:00:00 +00001/*
2 * Copyright 1997 Sun Microsystems, Inc. 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 */
23
24/* @test
25 @bug 4017158
26 @summary Check for correct implementation of ByteArrayInputStream.write
27 */
28
29import java.io.*;
30
31
32public 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}