KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > cz > cuni > sofa > lib > Impl > ByteArrayOutputStream


1 /* $Id: ByteArrayOutputStream.java,v 1.1.1.1 2003/02/11 16:19:40 bures Exp $ */
2
3 package cz.cuni.sofa.lib.Impl;
4 import java.io.IOException JavaDoc;
5
6 /** Implementation of OutputStream over byte array.
7   */

8 public class ByteArrayOutputStream extends cz.cuni.sofa.lib.OutputStream {
9
10   private java.io.ObjectOutputStream JavaDoc out;
11   private java.io.ByteArrayOutputStream JavaDoc internal;
12
13   public ByteArrayOutputStream() throws IOException JavaDoc {
14     internal = new java.io.ByteArrayOutputStream JavaDoc ();
15     out = new java.io.ObjectOutputStream JavaDoc(internal);
16   }
17
18   /* from java.io.OutputStream */
19   public void write(int b) throws IOException JavaDoc {
20     out.write(b);
21   }
22
23   /** Creates a newly allocated byte array.
24     * @return the current contents of this output stream, as a byte array
25     */

26   public byte[] toByteArray() {
27     try {
28       out.close();
29     } catch (IOException JavaDoc e) {
30       System.out.println("IOException");
31     }
32     return internal.toByteArray();
33   }
34
35   /** Converts bytes to string.
36     * @return the current contents of this output stream, as a string
37     */

38   public String JavaDoc toString() {
39     try {
40       out.close();
41     } catch (IOException JavaDoc e) {
42       System.out.println("IOException");
43     }
44     return new String JavaDoc( internal.toByteArray());
45   }
46
47   public void write_boolean(boolean value) throws IOException JavaDoc {
48     out.writeBoolean(value);
49   }
50
51   public void write_char(char value) throws IOException JavaDoc {
52     out.writeChar(value);
53   }
54   
55   public void write_wchar(char value) throws IOException JavaDoc {
56     out.writeChar(value);
57   }
58   
59   public void write_octet(byte value) throws IOException JavaDoc {
60     out.writeByte(value);
61   }
62   
63   public void write_short (short value) throws IOException JavaDoc {
64     out.writeShort(value);
65   }
66   
67   public void write_ushort (short value) throws IOException JavaDoc {
68     out.writeShort(value);
69   }
70   
71   public void write_long (int value) throws IOException JavaDoc {
72     out.writeInt(value);
73   }
74   
75   public void write_ulong (int value) throws IOException JavaDoc {
76     out.writeInt(value);
77   }
78   
79   public void write_longlong (long value) throws IOException JavaDoc {
80     out.writeLong(value);
81   }
82   
83   public void write_ulonglong (long value) throws IOException JavaDoc {
84     out.writeLong(value);
85   }
86   
87   public void write_float (float value) throws IOException JavaDoc {
88     out.writeFloat(value);
89   }
90   
91   public void write_double (double value) throws IOException JavaDoc {
92     out.writeDouble(value);
93   }
94   
95   public void write_string (String JavaDoc value) throws IOException JavaDoc {
96     out.writeUTF(value);
97   }
98   
99   public void write_wstring (String JavaDoc value) throws IOException JavaDoc {
100     out.writeUTF(value);
101   }
102
103
104   public void write_boolean_array(boolean[] value, int offset, int length) throws IOException JavaDoc {
105     for (int i=0; i<length; i++) {
106       out.writeBoolean(value[i]);
107     }
108   }
109   
110   public void write_char_array(char[] value, int offset, int length) throws IOException JavaDoc {
111     for (int i=0; i<length; i++) {
112       out.writeChar(value[i]);
113     }
114   }
115   
116   public void write_wchar_array(char[] value, int offset, int length) throws IOException JavaDoc {
117     for (int i=0; i<length; i++) {
118       out.writeChar(value[i]);
119     }
120   }
121   
122   public void write_octet_array(byte[] value, int offset, int length) throws IOException JavaDoc {
123     for (int i=0; i<length; i++) {
124       out.writeByte(value[i]);
125     }
126   }
127   
128   public void write_short_array(short[] value, int offset, int length) throws IOException JavaDoc {
129     for (int i=0; i<length; i++) {
130       out.writeShort(value[i]);
131     }
132   }
133   
134   public void write_ushort_array(short[] value, int offset, int length) throws IOException JavaDoc {
135     for (int i=0; i<length; i++) {
136       out.writeShort(value[i]);
137     }
138   }
139   
140   public void write_long_array(int[] value, int offset, int length) throws IOException JavaDoc {
141     for (int i=0; i<length; i++) {
142       out.writeInt(value[i]);
143     }
144   }
145   
146   public void write_ulong_array(int[] value, int offset, int length) throws IOException JavaDoc {
147     for (int i=0; i<length; i++) {
148       out.writeInt(value[i]);
149     }
150   }
151   
152   public void write_longlong_array(long[] value, int offset, int length) throws IOException JavaDoc {
153     for (int i=0; i<length; i++) {
154       out.writeLong(value[i]);
155     }
156   }
157   
158   public void write_ulonglong_array(long[] value, int offset, int length) throws IOException JavaDoc {
159     for (int i=0; i<length; i++) {
160       out.writeLong(value[i]);
161     }
162   }
163   
164   public void write_float_array(float[] value, int offset, int length) throws IOException JavaDoc {
165     for (int i=0; i<length; i++) {
166       out.writeFloat(value[i]);
167     }
168   }
169   
170   public void write_double_array(double[] value, int offset, int length) throws IOException JavaDoc {
171     for (int i=0; i<length; i++) {
172       out.writeDouble(value[i]);
173     }
174   }
175
176
177   public void write_Object(cz.cuni.sofa.lib.Object value) throws IOException JavaDoc {
178     out.writeObject(value);
179   }
180
181     
182   
183 }
184
Popular Tags