|
|||||||||||||||||||
Source file | Conditionals | Statements | Methods | TOTAL | |||||||||||||||
InlineHeaderBuilder.java | - | 100% | 50% | 88.9% |
|
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | * | |
17 | * $Id: InlineHeaderBuilder.java 541508 2007-05-25 01:54:12Z vgritsenko $ | |
18 | */ | |
19 | ||
20 | package org.apache.xindice.core.meta.inline; | |
21 | ||
22 | import org.apache.xindice.core.data.Value; | |
23 | ||
24 | /** | |
25 | * Construct a Value object containing the inline metadata header | |
26 | * and value data. | |
27 | * | |
28 | * The first header byte holds the number of total bytes (counting itself) | |
29 | * preceding the data. The second header byte contains the version number | |
30 | * of the metadata. Remaining header bytes are the version-specific metadata. | |
31 | * | |
32 | * <pre> | |
33 | * Version 0: Null | |
34 | * no version-specific metdata, two byte total length | |
35 | * byte 1: 2 | |
36 | * byte 2: 0 | |
37 | * | |
38 | * Version 1: ResoureType | |
39 | * resource type, three byte total length | |
40 | * byte 1: 2 | |
41 | * byte 2: 1 | |
42 | * byte 3: content type (1 => xml, 2 => binary) | |
43 | * </pre> | |
44 | * | |
45 | * @version $Revision: 541508 $, $Date: 2007-05-24 18:54:12 -0700 (Thu, 24 May 2007) $ | |
46 | */ | |
47 | public class InlineHeaderBuilder { | |
48 | ||
49 | /** | |
50 | * There's no reason to ever create an instance of this class. | |
51 | */ | |
52 | 0 | private InlineHeaderBuilder() { |
53 | } | |
54 | ||
55 | /** | |
56 | * Create a Value object containing the inline metadata header and | |
57 | * value data. | |
58 | * | |
59 | * NOTE: For maximum performance, we would hand all the pieces to the Value | |
60 | * object, which would talk to the BTree by stream, and none of these | |
61 | * allocations and copies would be necessary. | |
62 | */ | |
63 | 1984 | public static Value createValue(int version, byte[] metadata, byte[] data, int pos, int len) { |
64 | ||
65 | 1984 | int headerLength = 2 + metadata.length; |
66 | 1984 | byte[] valueData = new byte[headerLength + len]; |
67 | ||
68 | 1984 | valueData[0] = (byte) headerLength; |
69 | 1984 | valueData[1] = (byte) version; |
70 | 1984 | System.arraycopy(metadata, 0, valueData, 2, metadata.length); |
71 | 1984 | System.arraycopy(data, pos, valueData, 2 + metadata.length, len); |
72 | 1984 | return new Value(valueData); |
73 | } | |
74 | } |
|