Main Page | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Related Pages

StringBinding.java

00001 /*-
00002  * See the file LICENSE for redistribution information.
00003  *
00004  * Copyright (c) 2000-2005
00005  *      Sleepycat Software.  All rights reserved.
00006  *
00007  * $Id: StringBinding.java,v 12.2 2005/08/01 20:25:14 mark Exp $
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     // javadoc is inherited
00032     public Object entryToObject(TupleInput input) {
00033 
00034         return input.readString();
00035     }
00036 
00037     // javadoc is inherited
00038     public void objectToEntry(Object object, TupleOutput output) {
00039 
00040         output.writeString((String) object);
00041     }
00042 
00043     // javadoc is inherited
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++;           // null terminator
00082         return new TupleOutput(new byte[stringLength]);
00083     }
00084 }

Generated on Sun Dec 25 12:14:30 2005 for Berkeley DB 4.4.16 by  doxygen 1.4.2