1 2 12 package com.versant.core.jdbc.sql.conv; 13 14 import com.versant.core.jdbc.JdbcConverter; 15 16 22 public class DoubleArrayConverter extends TypeAsBytesConverterBase { 23 24 public static class Factory extends TypeAsBytesConverterBase.Factory { 25 26 protected JdbcConverter createConverter(JdbcConverter nested) { 27 return new DoubleArrayConverter(nested); 28 } 29 30 } 31 32 public DoubleArrayConverter(JdbcConverter nested) { 33 super(nested); 34 } 35 36 39 protected Object fromByteArray(byte[] buf) { 40 int n = buf.length / 8; 41 double[] a = new double[n]; 42 int i = 0, j = 0; 43 for (; i < n; ) { 44 a[i++] = Double.longBitsToDouble( 45 ((long)(buf[j++] & 0xFF) << 56) 46 + ((long)(buf[j++] & 0xFF) << 48) 47 + ((long)(buf[j++] & 0xFF) << 40) 48 + ((long)(buf[j++] & 0xFF) << 32) 49 + ((long)(buf[j++] & 0xFF) << 24) 50 + ((buf[j++] & 0xFF) << 16) 51 + ((buf[j++] & 0xFF) << 8) 52 + (buf[j++] & 0xFF)); 53 } 54 return a; 55 } 56 57 60 protected byte[] toByteArray(Object value) { 61 if (value == null) return null; 62 double[] a = (double[])value; 63 int n = a.length; 64 byte[] buf = new byte[n * 8]; 65 int i = 0, j = 0; 66 for (; i < n; ) { 67 68 long x = Double.doubleToRawLongBits(a[i++]); 69 70 71 buf[j++] = (byte)((x >>> 56) & 0xFF); 72 buf[j++] = (byte)((x >>> 48) & 0xFF); 73 buf[j++] = (byte)((x >>> 40) & 0xFF); 74 buf[j++] = (byte)((x >>> 32) & 0xFF); 75 buf[j++] = (byte)((x >>> 24) & 0xFF); 76 buf[j++] = (byte)((x >>> 16) & 0xFF); 77 buf[j++] = (byte)((x >>> 8) & 0xFF); 78 buf[j++] = (byte)(x & 0xFF); 79 } 80 return buf; 81 } 82 83 87 public Class getValueType() { 88 return double[].class; 89 } 90 91 } 92 93 | Popular Tags |