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