00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 package com.sleepycat.bind.tuple;
00011
00012 import com.sleepycat.util.UtfOps;
00013 import com.sleepycat.db.DatabaseEntry;
00014
00029 public class StringBinding extends TupleBinding {
00030
00031
00032 public Object entryToObject(TupleInput input) {
00033
00034 return input.readString();
00035 }
00036
00037
00038 public void objectToEntry(Object object, TupleOutput output) {
00039
00040 output.writeString((String) object);
00041 }
00042
00043
00044 protected TupleOutput getTupleOutput(Object object) {
00045
00046 return sizedOutput((String) object);
00047 }
00048
00056 public static String entryToString(DatabaseEntry entry) {
00057
00058 return entryToInput(entry).readString();
00059 }
00060
00068 public static void stringToEntry(String val, DatabaseEntry entry) {
00069
00070 outputToEntry(sizedOutput(val).writeString(val), entry);
00071 }
00072
00077 private static TupleOutput sizedOutput(String val) {
00078
00079 int stringLength =
00080 (val == null) ? 1 : UtfOps.getByteLength(val.toCharArray());
00081 stringLength++;
00082 return new TupleOutput(new byte[stringLength]);
00083 }
00084 }