• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt/router/db-4.8.30/java/src/com/sleepycat/bind/
1/*-
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2000-2009 Oracle.  All rights reserved.
5 *
6 * $Id$
7 */
8
9package com.sleepycat.bind;
10
11import com.sleepycat.db.DatabaseEntry;
12
13/**
14 * A pass-through <code>EntryBinding</code> that uses the entry's byte array as
15 * the key or data object.
16 *
17 * @author Mark Hayes
18 */
19public class ByteArrayBinding implements EntryBinding<byte[]> {
20
21    /*
22     * We can return the same byte[] for 0 length arrays.
23     */
24    private static byte[] ZERO_LENGTH_BYTE_ARRAY = new byte[0];
25
26    /**
27     * Creates a byte array binding.
28     */
29    public ByteArrayBinding() {
30    }
31
32    // javadoc is inherited
33    public byte[] entryToObject(DatabaseEntry entry) {
34
35	int len = entry.getSize();
36	if (len == 0) {
37	    return ZERO_LENGTH_BYTE_ARRAY;
38	} else {
39	    byte[] bytes = new byte[len];
40	    System.arraycopy(entry.getData(), entry.getOffset(),
41			     bytes, 0, bytes.length);
42	    return bytes;
43	}
44    }
45
46    // javadoc is inherited
47    public void objectToEntry(byte[] object, DatabaseEntry entry) {
48
49        entry.setData(object, 0, object.length);
50    }
51}
52