KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sleepycat > bind > tuple > BigIntegerBinding


1 /*-
2  * See the file LICENSE for redistribution information.
3  *
4  * Copyright (c) 2000-2006
5  * Oracle Corporation. All rights reserved.
6  *
7  * $Id: BigIntegerBinding.java,v 1.1 2006/11/14 23:30:48 mark Exp $
8  */

9
10 package com.sleepycat.bind.tuple;
11
12 import java.math.BigInteger JavaDoc;
13
14 import com.sleepycat.je.DatabaseEntry;
15
16 /**
17  * A concrete <code>TupleBinding</code> for a <code>BigInteger</code> value.
18  */

19 public class BigIntegerBinding extends TupleBinding {
20
21     // javadoc is inherited
22
public Object JavaDoc entryToObject(TupleInput input) {
23
24         return input.readBigInteger();
25     }
26
27     // javadoc is inherited
28
public void objectToEntry(Object JavaDoc object, TupleOutput output) {
29
30         output.writeBigInteger((BigInteger JavaDoc) object);
31     }
32
33     // javadoc is inherited
34
protected TupleOutput getTupleOutput(Object JavaDoc object) {
35
36         return sizedOutput((BigInteger JavaDoc) object);
37     }
38
39     /**
40      * Converts an entry buffer into a <code>BigInteger</code> value.
41      *
42      * @param entry is the source entry buffer.
43      *
44      * @return the resulting value.
45      */

46     public static BigInteger JavaDoc entryToBigInteger(DatabaseEntry entry) {
47
48         return entryToInput(entry).readBigInteger();
49     }
50
51     /**
52      * Converts a <code>BigInteger</code> value into an entry buffer.
53      *
54      * @param val is the source value.
55      *
56      * @param entry is the destination entry buffer.
57      */

58     public static void bigIntegerToEntry(BigInteger JavaDoc val, DatabaseEntry entry) {
59
60         outputToEntry(sizedOutput(val).writeBigInteger(val), entry);
61     }
62
63     /**
64      * Returns a tuple output object of the exact size needed, to avoid
65      * wasting space when a single primitive is output.
66      */

67     private static TupleOutput sizedOutput(BigInteger JavaDoc val) {
68
69         int len = TupleOutput.getBigIntegerByteLength(val);
70         return new TupleOutput(new byte[len]);
71     }
72 }
73
Popular Tags