src/org/objectweb/cjdbc/common/stream/CJDBCOutputStream.java

説明を見る。
00001 00025 package org.objectweb.cjdbc.common.stream; 00026 00027 import java.io.BufferedOutputStream; 00028 import java.io.IOException; 00029 import java.io.ObjectOutputStream; 00030 import java.io.OutputStream; 00031 import java.io.StreamCorruptedException; 00032 import java.net.Socket; 00033 00040 public class CJDBCOutputStream 00041 { 00042 00043 private ObjectOutputStream output; 00044 private long bytesWritten; 00045 private Socket socket; 00046 private boolean useCompression = false; 00047 private long speed = -1; 00048 private long dateCreated; 00049 private int unshared = 0; 00050 00059 public CJDBCOutputStream(Socket socket) throws IOException, 00060 StreamCorruptedException 00061 { 00062 this(socket.getOutputStream()); 00063 this.socket = socket; 00064 } 00065 00074 public CJDBCOutputStream(OutputStream out) throws IOException, 00075 StreamCorruptedException 00076 { 00077 output = new ObjectOutputStream(new BufferedOutputStream(out)); 00078 dateCreated = System.currentTimeMillis(); 00079 bytesWritten = 0; 00080 } 00081 00086 public void flush() throws IOException 00087 { 00088 output.flush(); 00089 } 00090 00095 public void close() throws IOException 00096 { 00097 output.close(); 00098 } 00099 00105 public void writeObject(Object obj) throws IOException 00106 { 00107 if (useCompression) 00108 { 00109 byte[] bytes = CJDBCStream.compressObject(obj); 00110 bytesWritten += bytes.length + 4; 00111 // we are sending an integer on the pipe. 00112 00113 output.writeInt(bytes.length); 00114 output.write(bytes); 00115 } 00116 else 00117 { 00118 // Use the unshared version to prevent the stream to keep references on 00119 // objects. This prevents objects sent through the channel from being 00120 // garbage collected and results in memory leaks. 00121 output.writeUnshared(obj); 00122 if (CJDBCStream.CLEAN_INTERVAL != -1 00123 && (unshared++ > CJDBCStream.CLEAN_INTERVAL)) 00124 { 00125 unshared = 0; 00126 output.flush(); 00127 output.reset(); 00128 } 00129 } 00130 00131 } 00132 00138 public void writeUTF(String string) throws IOException 00139 { 00140 // use writeUnshared of writeObject of this class 00141 this.writeObject(string); 00142 if (string != null) 00143 bytesWritten += string.length(); 00144 } 00145 00151 public void writeInt(int value) throws IOException 00152 { 00153 bytesWritten += 4; 00154 output.writeInt(value); 00155 } 00156 00162 public void writeLong(long value) throws IOException 00163 { 00164 bytesWritten += 8; 00165 output.writeLong(value); 00166 } 00167 00173 public void writeBoolean(boolean value) throws IOException 00174 { 00175 bytesWritten += 1; 00176 output.writeBoolean(value); 00177 } 00178 00182 public long getBytesWritten() 00183 { 00184 return bytesWritten; 00185 } 00186 00190 public Socket getSocket() 00191 { 00192 return socket; 00193 } 00194 00198 public long getDateCreated() 00199 { 00200 return dateCreated; 00201 } 00202 00206 public boolean getUseCompression() 00207 { 00208 return useCompression; 00209 } 00210 00214 public long getSpeed() 00215 { 00216 return speed; 00217 } 00218 }

CJDBCversion1.0.4に対してTue Oct 12 15:15:58 2004に生成されました。 doxygen 1.3.8