1 // Tags: JDK1.1 |
|
2 |
|
3 // Copyright (C) 2002 Free Software Foundation, Inc. |
|
4 // Written by Daryl Lee (dolee@sources.redhat.com) |
|
5 // Modified from FileOutputStream/write.java, |
|
6 // written by Mark Wielaard (mark@klomp.org) |
|
7 |
|
8 // This file is part of Mauve. |
|
9 |
|
10 // Mauve is free software; you can redistribute it and/or modify |
|
11 // it under the terms of the GNU General Public License as published by |
|
12 // the Free Software Foundation; either version 2, or (at your option) |
|
13 // any later version. |
|
14 |
|
15 // Mauve is distributed in the hope that it will be useful, |
|
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18 // GNU General Public License for more details. |
|
19 |
|
20 // You should have received a copy of the GNU General Public License |
|
21 // along with Mauve; see the file COPYING. If not, write to |
|
22 // the Free Software Foundation, 59 Temple Place - Suite 330, |
|
23 // Boston, MA 02111-1307, USA. */ |
|
24 |
|
25 package gnu.testlet.java.io.FilterOutputStream; |
|
26 |
|
27 import java.io.ByteArrayOutputStream; |
|
28 import java.io.FilterOutputStream; |
|
29 import java.io.IOException; |
|
30 |
|
31 import gnu.testlet.Testlet; |
|
32 import gnu.testlet.TestHarness; |
|
33 |
|
34 public class write implements Testlet |
|
35 { |
|
36 class TestOutputStream extends FilterOutputStream |
|
37 { |
|
38 TestOutputStream (ByteArrayOutputStream baos) |
|
39 { |
|
40 super(baos); |
|
41 } |
|
42 } |
|
43 public void test (TestHarness harness) |
|
44 { |
|
45 ByteArrayOutputStream baos = new ByteArrayOutputStream(); |
|
46 FilterOutputStream fos = new FilterOutputStream(baos);; |
|
47 byte[] ba = {(byte)'B', (byte)'C', (byte)'D'}; |
|
48 try { |
|
49 String tststr = "ABCD"; |
|
50 fos.write('A'); |
|
51 harness.check(true, "write(int)"); |
|
52 fos.write(ba); |
|
53 harness.check(true, "write(buf)"); |
|
54 fos.write(ba,0,3); |
|
55 harness.check(true, "write(buf,off,len)"); |
|
56 byte[] finalba = baos.toByteArray(); |
|
57 String finalstr2 = new String(finalba); |
|
58 harness.check(finalstr2.equals("ABCDBCD"), "wrote all characters okay"); |
|
59 baos.flush(); |
|
60 harness.check(true, "flush()"); |
|
61 baos.close(); |
|
62 harness.check(true, "close()"); |
|
63 } |
|
64 catch (IOException e) { |
|
65 harness.fail("IOException unexpected"); |
|
66 } |
|
67 } |
|
68 } |
|