DirectByteBuffer.java revision 0bc30ae8420b5b1abc1b2eefbdf8846309b5447d
1adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project/*
2adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  Licensed to the Apache Software Foundation (ASF) under one or more
3adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  contributor license agreements.  See the NOTICE file distributed with
4adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  this work for additional information regarding copyright ownership.
5adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  The ASF licenses this file to You under the Apache License, Version 2.0
6adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  (the "License"); you may not use this file except in compliance with
7adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  the License.  You may obtain a copy of the License at
8adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *
9adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *     http://www.apache.org/licenses/LICENSE-2.0
10adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *
11adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  Unless required by applicable law or agreed to in writing, software
12adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  distributed under the License is distributed on an "AS IS" BASIS,
13adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  See the License for the specific language governing permissions and
15adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project *  limitations under the License.
16adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project */
17adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
18adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Projectpackage java.nio;
19adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
200440837fd0013373ba3476283151299e7be9e5a3Elliott Hughesabstract class DirectByteBuffer extends BaseByteBuffer {
210440837fd0013373ba3476283151299e7be9e5a3Elliott Hughes    // This is the offset into {@code Buffer.block} at which this buffer logically starts.
220440837fd0013373ba3476283151299e7be9e5a3Elliott Hughes    // TODO: rewrite this so we set 'block' to an OffsetMemoryBlock?
23adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    protected final int offset;
24adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
25eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes    protected DirectByteBuffer(MemoryBlock block, int capacity, int offset) {
260440837fd0013373ba3476283151299e7be9e5a3Elliott Hughes        super(capacity, block);
27adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
28eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes        long baseSize = block.getSize();
29c3c38fbbccaf428200acdd819b1f7799edac54d2Elliott Hughes        if (baseSize >= 0 && (capacity + offset) > baseSize) {
30c3c38fbbccaf428200acdd819b1f7799edac54d2Elliott Hughes            throw new IllegalArgumentException("capacity + offset > baseSize");
31adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
32eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson
33adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        this.offset = offset;
34eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes        this.effectiveDirectAddress = block.toInt() + offset;
35adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
36adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
37961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    private int checkBounds(int bytesPerElement, int length, int offset, int count) {
38961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        int byteCount = bytesPerElement * count;
39961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        if (offset < 0 || count < 0 || (long) offset + (long) count > length) {
40adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            throw new IndexOutOfBoundsException();
41adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
420e1b748ecabf720065a632f28330f5d4d037d5aeElliott Hughes        if (byteCount > remaining()) {
43adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            throw new BufferUnderflowException();
44adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
45961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        return byteCount;
46961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    }
47961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes
48961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    @Override
49961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    public final ByteBuffer get(byte[] dst, int dstOffset, int byteCount) {
50961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        checkBounds(1, dst.length, dstOffset, byteCount);
510e1b748ecabf720065a632f28330f5d4d037d5aeElliott Hughes        this.block.peekByteArray(offset + position, dst, dstOffset, byteCount);
520e1b748ecabf720065a632f28330f5d4d037d5aeElliott Hughes        position += byteCount;
53adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        return this;
54adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
55eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson
56961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    final void get(char[] dst, int dstOffset, int charCount) {
57961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        int byteCount = checkBounds(SIZEOF_CHAR, dst.length, dstOffset, charCount);
58961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        this.block.peekCharArray(offset + position, dst, dstOffset, charCount, order.needsSwap);
59961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        position += byteCount;
60961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    }
61961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes
62961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    final void get(double[] dst, int dstOffset, int doubleCount) {
63961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        int byteCount = checkBounds(SIZEOF_DOUBLE, dst.length, dstOffset, doubleCount);
64961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        this.block.peekDoubleArray(offset + position, dst, dstOffset, doubleCount, order.needsSwap);
65961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        position += byteCount;
66961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    }
67961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes
68961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    final void get(float[] dst, int dstOffset, int floatCount) {
69961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        int byteCount = checkBounds(SIZEOF_FLOAT, dst.length, dstOffset, floatCount);
70961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        this.block.peekFloatArray(offset + position, dst, dstOffset, floatCount, order.needsSwap);
71961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        position += byteCount;
72961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    }
73961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes
74961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    final void get(int[] dst, int dstOffset, int intCount) {
75961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        int byteCount = checkBounds(SIZEOF_INT, dst.length, dstOffset, intCount);
760e1b748ecabf720065a632f28330f5d4d037d5aeElliott Hughes        this.block.peekIntArray(offset + position, dst, dstOffset, intCount, order.needsSwap);
77692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes        position += byteCount;
78961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    }
79961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes
80961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    final void get(long[] dst, int dstOffset, int longCount) {
81961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        int byteCount = checkBounds(SIZEOF_LONG, dst.length, dstOffset, longCount);
82961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        this.block.peekLongArray(offset + position, dst, dstOffset, longCount, order.needsSwap);
83961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        position += byteCount;
84961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    }
85961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes
86961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes    final void get(short[] dst, int dstOffset, int shortCount) {
87961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        int byteCount = checkBounds(SIZEOF_SHORT, dst.length, dstOffset, shortCount);
88961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        this.block.peekShortArray(offset + position, dst, dstOffset, shortCount, order.needsSwap);
89961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes        position += byteCount;
90692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes    }
91692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes
92eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson    @Override
93adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public final byte get() {
94adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        if (position == limit) {
95adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            throw new BufferUnderflowException();
96adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
97eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes        return this.block.peekByte(offset + position++);
98adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
99adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
100eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson    @Override
101adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public final byte get(int index) {
102adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        if (index < 0 || index >= limit) {
103adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            throw new IndexOutOfBoundsException();
104adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
105eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes        return this.block.peekByte(offset + index);
106adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
107adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
108eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson    @Override
1090bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes    public final char getChar() {
1100bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes        int newPosition = position + SIZEOF_CHAR;
1110bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes        if (newPosition > limit) {
1120bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes            throw new BufferUnderflowException();
1130bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes        }
1140bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes        char result = (char) this.block.peekShort(offset + position, order);
1150bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes        position = newPosition;
1160bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes        return result;
1170bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes    }
1180bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes
1190bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes    @Override
1200bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes    public final char getChar(int index) {
1210bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes        if (index < 0 || (long) index + SIZEOF_CHAR > limit) {
1220bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes            throw new IndexOutOfBoundsException();
1230bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes        }
1240bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes        return (char) this.block.peekShort(offset + index, order);
1250bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes    }
1260bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes
1270bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes    @Override
128adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public final double getDouble() {
12929dbfe19b113a13b712be2bc762ef1c81cd06c47Elliott Hughes        int newPosition = position + SIZEOF_DOUBLE;
130adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        if (newPosition > limit) {
131adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            throw new BufferUnderflowException();
132adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
1330bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes        double result = Double.longBitsToDouble(this.block.peekLong(offset + position, order));
134adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        position = newPosition;
135adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        return result;
136adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
137adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
138eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson    @Override
139adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public final double getDouble(int index) {
14029dbfe19b113a13b712be2bc762ef1c81cd06c47Elliott Hughes        if (index < 0 || (long) index + SIZEOF_DOUBLE > limit) {
141adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            throw new IndexOutOfBoundsException();
142adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
1430bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes        return Double.longBitsToDouble(this.block.peekLong(offset + index, order));
144adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
145adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
146eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson    @Override
147adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public final float getFloat() {
14829dbfe19b113a13b712be2bc762ef1c81cd06c47Elliott Hughes        int newPosition = position + SIZEOF_FLOAT;
149adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        if (newPosition > limit) {
150adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            throw new BufferUnderflowException();
151adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
1520bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes        float result = Float.intBitsToFloat(this.block.peekInt(offset + position, order));
153adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        position = newPosition;
154adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        return result;
155adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
156adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
157eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson    @Override
158adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public final float getFloat(int index) {
15929dbfe19b113a13b712be2bc762ef1c81cd06c47Elliott Hughes        if (index < 0 || (long) index + SIZEOF_FLOAT > limit) {
160adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            throw new IndexOutOfBoundsException();
161adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
1620bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes        return Float.intBitsToFloat(this.block.peekInt(offset + index, order));
163adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
164adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
165eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson    @Override
166adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public final int getInt() {
16729dbfe19b113a13b712be2bc762ef1c81cd06c47Elliott Hughes        int newPosition = position + SIZEOF_INT;
168adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        if (newPosition > limit) {
169adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            throw new BufferUnderflowException();
170adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
171eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes        int result = this.block.peekInt(offset + position, order);
172adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        position = newPosition;
173adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        return result;
174adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
175adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
176eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson    @Override
177adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public final int getInt(int index) {
17829dbfe19b113a13b712be2bc762ef1c81cd06c47Elliott Hughes        if (index < 0 || (long) index + SIZEOF_INT > limit) {
179adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            throw new IndexOutOfBoundsException();
180adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
181eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes        return this.block.peekInt(offset + index, order);
182adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
183adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
184eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson    @Override
185adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public final long getLong() {
18629dbfe19b113a13b712be2bc762ef1c81cd06c47Elliott Hughes        int newPosition = position + SIZEOF_LONG;
187adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        if (newPosition > limit) {
188adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            throw new BufferUnderflowException();
189adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
190eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes        long result = this.block.peekLong(offset + position, order);
191adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        position = newPosition;
192adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        return result;
193adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
194adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
195eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson    @Override
196adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public final long getLong(int index) {
19729dbfe19b113a13b712be2bc762ef1c81cd06c47Elliott Hughes        if (index < 0 || (long) index + SIZEOF_LONG > limit) {
198adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            throw new IndexOutOfBoundsException();
199adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
200eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes        return this.block.peekLong(offset + index, order);
201adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
202adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
203eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson    @Override
204adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public final short getShort() {
20529dbfe19b113a13b712be2bc762ef1c81cd06c47Elliott Hughes        int newPosition = position + SIZEOF_SHORT;
206adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        if (newPosition > limit) {
207adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            throw new BufferUnderflowException();
208adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
209eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes        short result = this.block.peekShort(offset + position, order);
210adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        position = newPosition;
211adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        return result;
212adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
213adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
214eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson    @Override
215adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public final short getShort(int index) {
21629dbfe19b113a13b712be2bc762ef1c81cd06c47Elliott Hughes        if (index < 0 || (long) index + SIZEOF_SHORT > limit) {
217adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project            throw new IndexOutOfBoundsException();
218adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        }
219eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes        return this.block.peekShort(offset + index, order);
220adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
221adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
222eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson    @Override
223adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public final boolean isDirect() {
224adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        return true;
225adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
226adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
227adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    public final void free() {
228eb29579498a8860f81fd38275f8657c21bb67abbElliott Hughes        block.free();
229adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
230eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson
231eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson    @Override
232adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    final protected byte[] protectedArray() {
233adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        throw new UnsupportedOperationException();
234adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
235adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
236eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson    @Override
237adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    final protected int protectedArrayOffset() {
238adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        throw new UnsupportedOperationException();
239adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
240adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project
241eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson    @Override
242adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    final protected boolean protectedHasArray() {
243adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project        return false;
244adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project    }
245adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project}
246