Package org.apache.xindice.core.meta.inline

Source Code of org.apache.xindice.core.meta.inline.InlineHeaderBuilder

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $Id: InlineHeaderBuilder.java 511426 2007-02-25 03:25:02Z vgritsenko $
*/

package org.apache.xindice.core.meta.inline;

import org.apache.xindice.core.data.Value;

/**
* Construct a Value object containing the inline metadata header
* and value data.
*
* The first header byte holds the number of total bytes (counting itself)
* preceding the data.  The second header byte contains the version number
* of the metadata.  Remaining header bytes are the version-specific metadata.
*
* <pre>
* Version 0: Null
*     no version-specific metdata, two byte total length
*     byte 1: 2
*     byte 2: 0
*
* Version 1: ResoureType
*     resource type, three byte total length
*     byte 1: 2
*     byte 2: 1
*     byte 3: content type (1 => xml, 2 => binary)
* </pre>
*
* @version $Revision: 511426 $, $Date: 2007-02-24 22:25:02 -0500 (Sat, 24 Feb 2007) $
*/
public class InlineHeaderBuilder {

    /**
     * There's no reason to ever create an instance of this class.
     */
    private InlineHeaderBuilder() {
    }

    /**
     * Create a Value object containing the inline metadata header and
     * value data.
     *
     * NOTE: For maximum performance, we would hand all the pieces to the Value
     * object,  which would talk to the BTree by stream,  and none of these
     * allocations and copies would be necessary.
     */
    public static Value createValue(int version, byte[] metadata, byte[] data, int pos, int len) {

        int headerLength = 2 + metadata.length;
        byte[] valueData = new byte[headerLength + len];

        valueData[0] = (byte) headerLength;
        valueData[1] = (byte) version;
        System.arraycopy(metadata, 0, valueData, 2, metadata.length);
        System.arraycopy(data, pos, valueData, 2 + metadata.length, len);
        return new Value(valueData);
    }
}
TOP

Related Classes of org.apache.xindice.core.meta.inline.InlineHeaderBuilder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.