KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > indexing > BinarySmallObject


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.indexing;
12
13 class BinarySmallObject extends IndexedStoreObject {
14     public static final int TYPE = 5;
15     public static final int VALUE_OFFSET = 2;
16     protected byte[] value;
17
18     /**
19      * Constructs a new object that will be inserted into a store.
20      */

21     public BinarySmallObject(byte[] value) {
22         super();
23         this.value = new Buffer(value).get();
24     }
25
26     /**
27      * Constructs an object from bytes that came from the store.
28      */

29     public BinarySmallObject(Field f, ObjectStore store, ObjectAddress address) throws ObjectStoreException {
30         super(f, store, address);
31     }
32
33     /**
34      * Places the contents of the fields into the buffer.
35      * Subclasses should implement and call super.
36      * The value field is maintained in the contents directly and does not need
37      * to be copied there by this method.
38      */

39     protected void insertValues(Field f) {
40         super.insertValues(f);
41         f.subfield(VALUE_OFFSET).put(value);
42     }
43
44     /**
45      * Extracts the values from a field into the members of this object;
46      */

47     protected void extractValues(Field f) throws ObjectStoreException {
48         super.extractValues(f);
49         value = f.subfield(VALUE_OFFSET).get();
50     }
51
52     /**
53      * Returns the maximum size of this object's instance -- including its type field.
54      * Subclasses should override.
55      */

56     protected int getMaximumSize() {
57         return 6000 + VALUE_OFFSET;
58     }
59
60     protected int length() {
61         return value.length + VALUE_OFFSET;
62     }
63
64     /**
65      * Returns the minimum size of this object's instance -- including its type field.
66      * Subclasses should override.
67      */

68     protected int getMinimumSize() {
69         return VALUE_OFFSET;
70     }
71
72     /**
73      * Returns the required type of this class of object.
74      * Subclasses must override.
75      */

76     protected int getRequiredType() {
77         return TYPE;
78     }
79
80     /**
81      * Returns the value of the object.
82      */

83     public byte[] getValue() {
84         return new Field(value).get();
85     }
86
87     /**
88      * Provides a printable representation of this object.
89      */

90     public String JavaDoc toString() {
91         int n = 10;
92         StringBuffer JavaDoc b = new StringBuffer JavaDoc();
93         b.append("BSOB("); //$NON-NLS-1$
94
b.append(value.length);
95         b.append(" ["); //$NON-NLS-1$
96
for (int i = 0; i < value.length; i++) {
97             if (i > 0)
98                 b.append(" "); //$NON-NLS-1$
99
if (i == n)
100                 break;
101             b.append(value[i]);
102         }
103         if (value.length > n)
104             b.append(" ..."); //$NON-NLS-1$
105
b.append("])"); //$NON-NLS-1$
106
return b.toString();
107     }
108
109 }
110
Popular Tags