1 8 9 package com.sleepycat.bind.tuple; 10 11 import com.sleepycat.util.UtfOps; 12 import com.sleepycat.je.DatabaseEntry; 13 14 28 public class StringBinding extends TupleBinding { 29 30 public Object entryToObject(TupleInput input) { 32 33 return input.readString(); 34 } 35 36 public void objectToEntry(Object object, TupleOutput output) { 38 39 output.writeString((String ) object); 40 } 41 42 protected TupleOutput getTupleOutput(Object object) { 44 45 return sizedOutput((String ) object); 46 } 47 48 55 public static String entryToString(DatabaseEntry entry) { 56 57 return entryToInput(entry).readString(); 58 } 59 60 67 public static void stringToEntry(String val, DatabaseEntry entry) { 68 69 outputToEntry(sizedOutput(val).writeString(val), entry); 70 } 71 72 76 private static TupleOutput sizedOutput(String val) { 77 78 int stringLength = 79 (val == null) ? 1 : UtfOps.getByteLength(val.toCharArray()); 80 stringLength++; return new TupleOutput(new byte[stringLength]); 82 } 83 } 84 | Popular Tags |