Merge from mainline.
[official-gcc.git] / libjava / classpath / test / java.io / BufferedByteOutputStreamTest.java
blobe2785e6b396f1aa64a44ffc222e466752b29955b
1 /*************************************************************************
2 /* BufferedByteOutputStreamTest.java -- Test {Buffered,ByteArray}OutputStream
3 /*
4 /* Copyright (c) 1998 Free Software Foundation, Inc.
5 /* Written by Aaron M. Renn (arenn@urbanophile.com)
6 /*
7 /* This program is free software; you can redistribute it and/or modify
8 /* it under the terms of the GNU General Public License as published
9 /* by the Free Software Foundation, either version 2 of the License, or
10 /* (at your option) any later version.
12 /* This program is distributed in the hope that it will be useful, but
13 /* WITHOUT ANY WARRANTY; without even the implied warranty of
14 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 /* GNU General Public License for more details.
17 /* You should have received a copy of the GNU General Public License
18 /* along with this program; if not, write to the Free Software Foundation
19 /* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 /*************************************************************************/
22 import java.io.*;
24 /**
25 * Class to test BufferedOutputStream and ByteOutputStream
27 * @version 0.0
29 * @author Aaron M. Renn (arenn@urbanophile.com)
31 public class BufferedByteOutputStreamTest
34 public static void
35 main(String argv[])
37 System.out.println("Started test of BufferedOutputStream and ByteArrayOutputStream");
39 try
41 System.out.println("Test 1: Write Tests");
43 ByteArrayOutputStream baos = new ByteArrayOutputStream(24);
44 BufferedOutputStream bos = new BufferedOutputStream(baos, 12);
46 String str = "The Kroger on College Mall Rd. in Bloomington " +
47 "used to sell Kroger brand froze pizzas for 68 cents. " +
48 "I ate a lot of those in college. It was kind of embarrassing " +
49 "walking out of the grocery with nothing but 15 frozen pizzas.\n";
51 boolean passed = true;
53 byte[] buf = str.getBytes();
54 bos.write(buf, 0, 5);
55 if (baos.toByteArray().length != 0)
57 passed = false;
58 System.out.println("ByteArrayOutputStream has too many bytes #1");
60 bos.write(buf, 5, 8);
61 bos.write(buf, 13, 12);
62 bos.write(buf[25]);
63 bos.write(buf, 26, buf.length - 26);
64 bos.close();
66 String str2 = new String(baos.toByteArray());
67 if (!str.equals(str2))
69 passed = false;
70 System.out.println("Unexpected string: " + str2);
73 if (passed)
74 System.out.println("PASSED: Write Tests");
75 else
76 System.out.println("FAILED: Write Tests");
78 catch(IOException e)
80 System.out.println("FAILED: Write Tests: " + e);
83 System.out.println("Finished test of BufferedOutputStream and ByteArrayOutputStream");
86 } // class BufferedByteOutputStreamTest