1 8 9 package com.sleepycat.bind; 10 11 import com.sleepycat.je.DatabaseEntry; 12 13 19 public class ByteArrayBinding implements EntryBinding { 20 21 24 private static byte[] ZERO_LENGTH_BYTE_ARRAY = new byte[0]; 25 26 29 public ByteArrayBinding() { 30 } 31 32 public Object entryToObject(DatabaseEntry entry) { 34 35 int len = entry.getSize(); 36 if (len == 0) { 37 return ZERO_LENGTH_BYTE_ARRAY; 38 } else { 39 byte[] bytes = new byte[len]; 40 System.arraycopy(entry.getData(), entry.getOffset(), 41 bytes, 0, bytes.length); 42 return bytes; 43 } 44 } 45 46 public void objectToEntry(Object object, DatabaseEntry entry) { 48 49 byte[] bytes = (byte[]) object; 50 entry.setData(bytes, 0, bytes.length); 51 } 52 } 53 | Popular Tags |