1 24 25 package org.objectweb.cjdbc.common.stream; 26 27 import java.io.BufferedOutputStream ; 28 import java.io.DataOutputStream ; 29 import java.io.IOException ; 30 import java.io.OutputStream ; 31 import java.net.Socket ; 32 33 41 public class CJDBCOutputStream 42 { 43 private DataOutputStream output; 44 private Socket socket; 45 private long dateCreated; 46 47 54 public CJDBCOutputStream(Socket socket) throws IOException 55 { 56 this(socket.getOutputStream()); 57 this.socket = socket; 58 } 59 60 65 public CJDBCOutputStream(OutputStream out) 66 { 67 output = new DataOutputStream (new BufferedOutputStream (out)); 68 dateCreated = System.currentTimeMillis(); 69 } 70 71 75 public void flush() throws IOException 76 { 77 output.flush(); 78 } 79 80 84 public void close() throws IOException 85 { 86 output.close(); 87 } 88 89 123 public void writeUTF(String string) throws IOException 124 { 125 if (null == string) 126 { 127 output.writeBoolean(false); 128 return; 129 } 130 131 output.writeBoolean(true); 132 int idx; 133 final int maxSize = CJDBCStream.STRING_CHUNK_SIZE; 134 135 this.writeInt(string.length()); 136 137 for (idx = 0; idx + maxSize <= string.length(); idx += maxSize) 139 output.writeUTF(string.substring(idx, idx + maxSize)); 141 142 148 if (string.length() > idx) 149 output.writeUTF(string.substring(idx)); 150 } 151 152 157 public void writeInt(int value) throws IOException 158 { 159 output.writeInt(value); 160 } 161 162 167 public void writeLong(long value) throws IOException 168 { 169 output.writeLong(value); 170 } 171 172 177 public void writeFloat(float value) throws IOException 178 { 179 output.writeFloat(value); 180 } 181 182 187 public void writeDouble(double value) throws IOException 188 { 189 output.writeDouble(value); 190 } 191 192 197 public void write(byte[] b) throws IOException 198 { 199 this.write(b, 0, b.length); 200 } 201 202 205 public void write(byte[] b, int offset, int length) throws IOException 206 { 207 output.write(b, offset, length); 208 } 209 210 215 public void writeBoolean(boolean value) throws IOException 216 { 217 output.writeBoolean(value); 218 } 219 220 223 public Socket getSocket() 224 { 225 return socket; 226 } 227 228 231 public long getDateCreated() 232 { 233 return dateCreated; 234 } 235 236 } 237 | Popular Tags |