KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > h2 > value > ValueBytes


1 /*
2  * Copyright 2004-2006 H2 Group. Licensed under the H2 License, Version 1.0 (http://h2database.com/html/license.html).
3  * Initial Developer: H2 Group
4  */

5 package org.h2.value;
6
7 import org.h2.engine.Constants;
8 import org.h2.util.ByteUtils;
9
10 /**
11  * @author Thomas
12  */

13 public class ValueBytes extends ValueBytesBase {
14
15     private static final ValueBytes EMPTY = new ValueBytes(new byte[0]);
16     
17     protected ValueBytes(byte[] v) {
18         super(v);
19     }
20     
21     public static ValueBytes get(byte[] b) {
22         b = ByteUtils.cloneByteArray(b);
23         return getNoCopy(b);
24     }
25     
26     public static ValueBytes getNoCopy(byte[] b) {
27         if (b.length == 0) {
28             return EMPTY;
29         }
30         ValueBytes obj = new ValueBytes(b);
31         if (b.length > Constants.OBJECT_CACHE_MAX_PER_ELEMENT_SIZE) {
32             return obj;
33         }
34         return (ValueBytes) Value.cache(obj);
35     }
36
37     public int getType() {
38         return Value.BYTES;
39     }
40
41 }
42
Popular Tags