1 2 12 package com.versant.core.jdbc.sql.conv; 13 14 import com.versant.core.jdbc.JdbcConverter; 15 16 22 public class CharArrayConverter extends TypeAsBytesConverterBase { 23 24 public static class Factory extends TypeAsBytesConverterBase.Factory { 25 26 protected JdbcConverter createConverter(JdbcConverter nested) { 27 return new CharArrayConverter(nested); 28 } 29 30 } 31 32 public CharArrayConverter(JdbcConverter nested) { 33 super(nested); 34 } 35 36 39 protected Object fromByteArray(byte[] buf) { 40 int n = buf.length / 2; 41 char[] a = new char[n]; 42 int i = 0, j = 0; 43 for (; i < n; ) { 44 a[i++] = (char)(((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 char[] a = (char[])value; 55 int n = a.length; 56 byte[] buf = new byte[n * 2]; 57 int i = 0, j = 0; 58 for (; i < n; ) { 59 char 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 char[].class; 72 } 73 74 } 75 76 | Popular Tags |