KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > collections > test > TestDataBinding


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2002,2006 Oracle. All rights reserved.
5  *
6  * $Id: TestDataBinding.java,v 1.24 2006/10/30 21:14:39 bostic Exp $
7  */

8
9 package com.sleepycat.collections.test;
10
11 import com.sleepycat.bind.EntryBinding;
12 import com.sleepycat.je.DatabaseEntry;
13
14 /**
15  * @author Mark Hayes
16  */

17 class TestDataBinding implements EntryBinding {
18
19     public Object JavaDoc entryToObject(DatabaseEntry data) {
20
21         if (data.getSize() != 1) {
22             throw new IllegalStateException JavaDoc("size=" + data.getSize());
23         }
24         byte val = data.getData()[data.getOffset()];
25         return new Long JavaDoc(val);
26     }
27
28     public void objectToEntry(Object JavaDoc object, DatabaseEntry data) {
29
30         byte val = ((Number JavaDoc) object).byteValue();
31         data.setData(new byte[] { val }, 0, 1);
32     }
33 }
34
Popular Tags