1 30 31 32 package org.hsqldb.rowio; 33 34 import java.io.IOException ; 35 import java.math.BigDecimal ; 36 import java.math.BigInteger ; 37 import java.sql.Date ; 38 import java.sql.Time ; 39 import java.sql.Timestamp ; 40 41 import org.hsqldb.HsqlDateTime; 42 import org.hsqldb.HsqlException; 43 import org.hsqldb.lib.StringConverter; 44 import org.hsqldb.store.ValuePool; 45 import org.hsqldb.types.Binary; 46 import org.hsqldb.types.JavaObject; 47 48 58 public class RowInputBinary extends RowInputBase 59 implements org.hsqldb.rowio.RowInputInterface { 60 61 private RowOutputBinary out; 62 63 public RowInputBinary() { 64 super(); 65 } 66 67 public RowInputBinary(byte[] buf) { 68 super(buf); 69 } 70 71 75 public RowInputBinary(RowOutputBinary out) { 76 77 super(out.getBuffer()); 78 79 this.out = out; 80 } 81 82 protected byte[] readByteArray() throws IOException { 83 84 byte[] b = new byte[readInt()]; 85 86 readFully(b); 87 88 return b; 89 } 90 91 public int readType() throws IOException { 92 return readShort(); 93 } 94 95 public short readShortData() throws IOException { 96 return readShort(); 97 } 98 99 public int readIntData() throws IOException { 100 return readInt(); 101 } 102 103 public long readLongData() throws IOException { 104 return readLong(); 105 } 106 107 public String readString() throws IOException { 108 109 int length = readInt(); 110 String s = StringConverter.readUTF(buf, pos, length); 111 112 s = ValuePool.getString(s); 113 pos += length; 114 115 return s; 116 } 117 118 protected boolean checkNull() throws IOException { 119 120 int b = readByte(); 121 122 return b == 0 ? true 123 : false; 124 } 125 126 protected String readChar(int type) throws IOException { 127 return readString(); 128 } 129 130 protected Integer readSmallint() throws IOException , HsqlException { 131 return ValuePool.getInt(readShort()); 132 } 133 134 protected Integer readInteger() throws IOException , HsqlException { 135 return ValuePool.getInt(readInt()); 136 } 137 138 protected Long readBigint() throws IOException , HsqlException { 139 return ValuePool.getLong(readLong()); 140 } 141 142 protected Double readReal(int type) throws IOException , HsqlException { 143 return ValuePool.getDouble(readLong()); 144 } 145 146 protected BigDecimal readDecimal() throws IOException , HsqlException { 147 148 byte[] bytes = readByteArray(); 149 int scale = readInt(); 150 BigInteger bigint = new BigInteger (bytes); 151 152 return ValuePool.getBigDecimal(new BigDecimal (bigint, scale)); 153 } 154 155 protected Boolean readBit() throws IOException , HsqlException { 156 return readBoolean() ? Boolean.TRUE 157 : Boolean.FALSE; 158 } 159 160 protected Time readTime() throws IOException , HsqlException { 161 return new Time (HsqlDateTime.getNormalisedTime(readLong())); 162 } 163 164 protected Date readDate() throws IOException , HsqlException { 165 166 long date = HsqlDateTime.getNormalisedDate(readLong()); 167 168 return ValuePool.getDate(date); 169 } 170 171 protected Timestamp readTimestamp() throws IOException , HsqlException { 172 return HsqlDateTime.timestampValue(readLong(), readInt()); 173 } 174 175 protected Object readOther() throws IOException , HsqlException { 176 return new JavaObject(readByteArray()); 177 } 178 179 protected Binary readBinary(int type) throws IOException , HsqlException { 180 return new Binary(readByteArray(), false); 181 } 182 183 188 public void resetRow(int rowsize) { 189 190 if (out != null) { 191 out.reset(rowsize); 192 193 buf = out.getBuffer(); 194 } 195 196 super.reset(); 197 } 198 199 204 public void resetRow(int filepos, int rowsize) throws IOException { 205 206 if (out != null) { 207 out.reset(rowsize); 208 209 buf = out.getBuffer(); 210 } 211 212 super.resetRow(filepos, rowsize); 213 } 214 } 215 | Popular Tags |