1 package com.quadcap.sql.io; 2 3 40 41 import java.io.IOException ; 42 import java.io.ObjectInput ; 43 import java.io.ObjectOutput ; 44 45 import java.math.BigDecimal ; 46 import java.math.BigInteger ; 47 48 import com.quadcap.util.Debug; 49 50 55 public class ExternProxyBigDecimal implements ExternalizeProxy { 56 public Object readObject(ObjectInput in) throws IOException { 57 if (in.read() == 0) return null; 58 int cnt = in.read(); 59 byte[] buf = new byte[cnt]; 60 in.read(buf); 61 int scale = in.readInt(); 62 BigInteger bi = new BigInteger (buf); 63 BigDecimal big = new BigDecimal (bi, scale); 64 return big; 65 } 66 67 public void writeObject(ObjectOutput out, Object object) 68 throws IOException 69 { 70 if (object == null) { 71 out.write(0); 72 } else { 73 out.write(1); 74 BigDecimal big = (BigDecimal )object; 75 BigInteger bi = big.unscaledValue(); 79 byte[] buf = bi.toByteArray(); 81 out.write(buf.length); 82 out.write(buf); 83 out.writeInt(big.scale()); 84 } 85 } 86 } 87 88 89 | Popular Tags |