1
package org.apache.lucene.store;
4
* Licensed to the Apache Software Foundation (ASF) under one or more
5
* contributor license agreements. See the NOTICE file distributed with
6
* this work for additional information regarding copyright ownership.
7
* The ASF licenses this file to You under the Apache License, Version 2.0
8
* (the "License"); you may not use this file except in compliance with
9
* the License. You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
20
import org.apache.lucene.util.BytesRef;
22
/** @lucene.experimental */
23
public final class ByteArrayDataInput extends DataInput {
30
public ByteArrayDataInput(byte[] bytes) {
34
public ByteArrayDataInput(byte[] bytes, int offset, int len) {
35
reset(bytes, offset, len);
38
public ByteArrayDataInput() {
39
reset(BytesRef.EMPTY_BYTES);
42
public void reset(byte[] bytes) {
43
reset(bytes, 0, bytes.length);
46
public int getPosition() {
50
public void reset(byte[] bytes, int offset, int len) {
56
public boolean eof() {
60
public void skipBytes(int count) {
66
public short readShort() {
67
return (short) (((bytes[pos++] & 0xFF) << 8) | (bytes[pos++] & 0xFF));
71
public int readInt() {
72
assert pos+4 <= limit;
73
return ((bytes[pos++] & 0xFF) << 24) | ((bytes[pos++] & 0xFF) << 16)
74
| ((bytes[pos++] & 0xFF) << 8) | (bytes[pos++] & 0xFF);
78
public long readLong() {
79
assert pos+8 <= limit;
80
final int i1 = ((bytes[pos++] & 0xff) << 24) | ((bytes[pos++] & 0xff) << 16) |
81
((bytes[pos++] & 0xff) << 8) | (bytes[pos++] & 0xff);
82
final int i2 = ((bytes[pos++] & 0xff) << 24) | ((bytes[pos++] & 0xff) << 16) |
83
((bytes[pos++] & 0xff) << 8) | (bytes[pos++] & 0xff);
84
return (((long)i1) << 32) | (i2 & 0xFFFFFFFFL);
88
public int readVInt() {
90
byte b = bytes[pos++];
92
for (int shift = 7; (b & 0x80) != 0; shift += 7) {
95
i |= (b & 0x7F) << shift;
101
public long readVLong() {
103
byte b = bytes[pos++];
105
for (int shift = 7; (b & 0x80) != 0; shift += 7) {
108
i |= (b & 0x7FL) << shift;
113
// NOTE: AIOOBE not EOF if you read too much
115
public byte readByte() {
120
// NOTE: AIOOBE not EOF if you read too much
122
public void readBytes(byte[] b, int offset, int len) {
123
assert pos + len <= limit;
124
System.arraycopy(bytes, pos, b, offset, len);
128
private boolean checkBounds() {