01: /*-
02: * See the file LICENSE for redistribution information.
03: *
04: * Copyright (c) 2002,2008 Oracle. All rights reserved.
05: *
06: * $Id: TestDataBinding.java,v 1.24.2.2 2008/01/07 15:14:24 cwl Exp $
07: */
08:
09: 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 entryToObject(DatabaseEntry data) {
20:
21: if (data.getSize() != 1) {
22: throw new IllegalStateException("size=" + data.getSize());
23: }
24: byte val = data.getData()[data.getOffset()];
25: return new Long(val);
26: }
27:
28: public void objectToEntry(Object object, DatabaseEntry data) {
29:
30: byte val = ((Number) object).byteValue();
31: data.setData(new byte[] { val }, 0, 1);
32: }
33: }
|