1 24 25 package org.objectweb.cjdbc.common.stream; 26 27 import java.io.BufferedInputStream ; 28 import java.io.DataInputStream ; 29 import java.io.IOException ; 30 import java.io.InputStream ; 31 import java.io.StreamCorruptedException ; 32 import java.net.Socket ; 33 34 41 public class CJDBCInputStream 42 { 43 private DataInputStream input; 44 private Socket socket; 45 private long dateCreated; 46 47 52 public CJDBCInputStream(InputStream in) 53 { 54 input = new DataInputStream (new BufferedInputStream (in)); 55 } 56 57 64 public CJDBCInputStream(Socket socket) throws IOException , 65 StreamCorruptedException 66 { 67 this(socket.getInputStream()); 68 this.socket = socket; 69 dateCreated = System.currentTimeMillis(); 70 } 71 72 76 public void close() throws IOException 77 { 78 input.close(); 79 } 80 81 86 public boolean readBoolean() throws IOException 87 { 88 return input.readBoolean(); 89 } 90 91 96 public int readInt() throws IOException 97 { 98 return input.readInt(); 99 } 100 101 106 public long readLong() throws IOException 107 { 108 return input.readLong(); 109 } 110 111 116 public double readFloat() throws IOException 117 { 118 return input.readFloat(); 119 } 120 121 126 public double readDouble() throws IOException 127 { 128 return input.readDouble(); 129 } 130 131 136 public void readFully(byte[] b) throws IOException 137 { 138 input.readFully(b); 139 } 140 141 147 public String readUTF() throws IOException 148 { 149 if (!input.readBoolean()) 150 return null; 151 152 final int maxSize = CJDBCStream.STRING_CHUNK_SIZE; 153 154 int strlen = input.readInt(); 155 StringBuffer sbuf = new StringBuffer (strlen); 156 157 for (int idx = 0; idx < strlen; idx += maxSize) 160 sbuf.append(input.readUTF()); 161 162 return new String (sbuf); 163 } 164 165 170 public int available() throws IOException 171 { 172 return input.available(); 173 } 174 175 178 public Socket getSocket() 179 { 180 return socket; 181 } 182 183 186 public long getDateCreated() 187 { 188 return dateCreated; 189 } 190 191 } | Popular Tags |