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