mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-04-05 06:48:45 +00:00
90 lines
2.3 KiB
Java
90 lines
2.3 KiB
Java
|
/*
|
||
|
* Licensed to Elastic Search and Shay Banon under one
|
||
|
* or more contributor license agreements. See the NOTICE file
|
||
|
* distributed with this work for additional information
|
||
|
* regarding copyright ownership. Elastic Search 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.
|
||
|
*/
|
||
|
|
||
|
package org.elasticsearch.common.bytes;
|
||
|
|
||
|
import org.elasticsearch.common.io.stream.StreamInput;
|
||
|
import org.elasticsearch.common.io.stream.StreamOutput;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import java.io.OutputStream;
|
||
|
|
||
|
/**
|
||
|
* A reference to bytes.
|
||
|
*/
|
||
|
public interface BytesReference {
|
||
|
|
||
|
/**
|
||
|
* Returns the byte at the specified index. Need to be between 0 and length.
|
||
|
*/
|
||
|
byte get(int index);
|
||
|
|
||
|
/**
|
||
|
* The length.
|
||
|
*/
|
||
|
int length();
|
||
|
|
||
|
/**
|
||
|
* Slice the bytes from the <tt>from</tt> index up to <tt>length</tt>.
|
||
|
*/
|
||
|
BytesReference slice(int from, int length);
|
||
|
|
||
|
/**
|
||
|
* A stream input of the bytes.
|
||
|
*/
|
||
|
StreamInput streamInput();
|
||
|
|
||
|
/**
|
||
|
* Writes the bytes into the output, with an optional length header (variable encoded).
|
||
|
*/
|
||
|
void writeTo(StreamOutput out, boolean withLength) throws IOException;
|
||
|
|
||
|
void writeTo(OutputStream os) throws IOException;
|
||
|
|
||
|
/**
|
||
|
* Returns the bytes as a single byte array.
|
||
|
*/
|
||
|
byte[] toBytes();
|
||
|
|
||
|
/**
|
||
|
* Returns the bytes as a byte array, possibly sharing the underlying byte buffer.
|
||
|
*/
|
||
|
BytesArray toBytesArray();
|
||
|
|
||
|
/**
|
||
|
* Returns the bytes copied over as a byte array.
|
||
|
*/
|
||
|
BytesArray copyBytesArray();
|
||
|
|
||
|
/**
|
||
|
* Is there an underlying byte array for this bytes reference.
|
||
|
*/
|
||
|
boolean hasArray();
|
||
|
|
||
|
/**
|
||
|
* The underlying byte array (if exists).
|
||
|
*/
|
||
|
byte[] array();
|
||
|
|
||
|
/**
|
||
|
* The offset into the underlying byte array.
|
||
|
*/
|
||
|
int arrayOffset();
|
||
|
}
|