1 2 3 package cz.cuni.sofa.lib.Impl; 4 import java.io.IOException ; 5 6 8 public class ByteArrayOutputStream extends cz.cuni.sofa.lib.OutputStream { 9 10 private java.io.ObjectOutputStream out; 11 private java.io.ByteArrayOutputStream internal; 12 13 public ByteArrayOutputStream() throws IOException { 14 internal = new java.io.ByteArrayOutputStream (); 15 out = new java.io.ObjectOutputStream (internal); 16 } 17 18 19 public void write(int b) throws IOException { 20 out.write(b); 21 } 22 23 26 public byte[] toByteArray() { 27 try { 28 out.close(); 29 } catch (IOException e) { 30 System.out.println("IOException"); 31 } 32 return internal.toByteArray(); 33 } 34 35 38 public String toString() { 39 try { 40 out.close(); 41 } catch (IOException e) { 42 System.out.println("IOException"); 43 } 44 return new String ( internal.toByteArray()); 45 } 46 47 public void write_boolean(boolean value) throws IOException { 48 out.writeBoolean(value); 49 } 50 51 public void write_char(char value) throws IOException { 52 out.writeChar(value); 53 } 54 55 public void write_wchar(char value) throws IOException { 56 out.writeChar(value); 57 } 58 59 public void write_octet(byte value) throws IOException { 60 out.writeByte(value); 61 } 62 63 public void write_short (short value) throws IOException { 64 out.writeShort(value); 65 } 66 67 public void write_ushort (short value) throws IOException { 68 out.writeShort(value); 69 } 70 71 public void write_long (int value) throws IOException { 72 out.writeInt(value); 73 } 74 75 public void write_ulong (int value) throws IOException { 76 out.writeInt(value); 77 } 78 79 public void write_longlong (long value) throws IOException { 80 out.writeLong(value); 81 } 82 83 public void write_ulonglong (long value) throws IOException { 84 out.writeLong(value); 85 } 86 87 public void write_float (float value) throws IOException { 88 out.writeFloat(value); 89 } 90 91 public void write_double (double value) throws IOException { 92 out.writeDouble(value); 93 } 94 95 public void write_string (String value) throws IOException { 96 out.writeUTF(value); 97 } 98 99 public void write_wstring (String value) throws IOException { 100 out.writeUTF(value); 101 } 102 103 104 public void write_boolean_array(boolean[] value, int offset, int length) throws IOException { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 178 out.writeObject(value); 179 } 180 181 182 183 } 184 | Popular Tags |