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