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 20fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughesimport java.nio.channels.FileChannel.MapMode; 21fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 22fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughesimport libcore.io.Memory; 2343a9f774d075e0e441d8b996e3f6c81ea483ec89Elliott Hughesimport libcore.io.SizeOf; 2443a9f774d075e0e441d8b996e3f6c81ea483ec89Elliott Hughes 25fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughesclass DirectByteBuffer extends MappedByteBuffer { 26fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes // This is the offset into {@code Buffer.block} at which this buffer logically starts. 27fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes // TODO: rewrite this so we set 'block' to an OffsetMemoryBlock? 28fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes protected final int offset; 29adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 30fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes private final boolean isReadOnly; 31adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 32fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes protected DirectByteBuffer(MemoryBlock block, int capacity, int offset, boolean isReadOnly, MapMode mapMode) { 33fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes super(block, capacity, mapMode); 34eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson 35fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes long baseSize = block.getSize(); 36fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (baseSize >= 0 && (capacity + offset) > baseSize) { 37fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new IllegalArgumentException("capacity + offset > baseSize"); 38adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 39adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 400121106d9dc1ba713b53822886355e4d9339e852Joel Dice this.effectiveDirectAddress = block.toLong() + offset; 41eaa2ff09069424b0f7a95c7cd831cef1b744fe67Jesse Wilson 42fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.offset = offset; 43fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.isReadOnly = isReadOnly; 44fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 45961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes 46fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes // Used by the JNI NewDirectByteBuffer function. 479ce6a2533b50ffcd24b8b10bae7f234042768819Joel Dice DirectByteBuffer(long address, int capacity) { 48fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this(MemoryBlock.wrapFromJni(address, capacity), capacity, 0, false, null); 49fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 50961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes 51fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes private static DirectByteBuffer copy(DirectByteBuffer other, int markOfOther, boolean isReadOnly) { 52fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes DirectByteBuffer buf = new DirectByteBuffer(other.block, other.capacity(), other.offset, isReadOnly, other.mapMode); 53fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes buf.limit = other.limit; 54fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes buf.position = other.position(); 55fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes buf.mark = markOfOther; 56fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return buf; 57fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 58961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes 59fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer asReadOnlyBuffer() { 60fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return copy(this, mark, true); 61fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 62961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes 63fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer compact() { 64fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (isReadOnly) { 65fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new ReadOnlyBufferException(); 66961da1e7487bdb8ad8ac226d4f2789d003aa87b9Elliott Hughes } 67fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes Memory.memmove(this, 0, this, position, remaining()); 68fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position = limit - position; 69fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes limit = capacity; 70fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes mark = UNSET_MARK; 71fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this; 72fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 73fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 74fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer duplicate() { 75fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return copy(this, mark, isReadOnly); 76fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 77fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 78fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer slice() { 79fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return new DirectByteBuffer(block, remaining(), offset + position, isReadOnly, mapMode); 80fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 81fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 82fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public boolean isReadOnly() { 83fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return isReadOnly; 84fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 85fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 86fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override byte[] protectedArray() { 87fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (isReadOnly) { 88fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new ReadOnlyBufferException(); 89692222b08ff88eb92b523bf4780d7ea17a23aa80Elliott Hughes } 90fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes byte[] array = this.block.array(); 91fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (array == null) { 92fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new UnsupportedOperationException(); 93adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 94fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return array; 95fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 96fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 97fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override int protectedArrayOffset() { 98fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes protectedArray(); // Throw if we don't have an array or are read-only. 99fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return offset; 100fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 101fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 102fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override boolean protectedHasArray() { 103fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return !isReadOnly && (block.array() != null); 104fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 105fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 106fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final ByteBuffer get(byte[] dst, int dstOffset, int byteCount) { 107fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes checkGetBounds(1, dst.length, dstOffset, byteCount); 108fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.peekByteArray(offset + position, dst, dstOffset, byteCount); 109fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position += byteCount; 110fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this; 111fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 112fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 113fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes final void get(char[] dst, int dstOffset, int charCount) { 114fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int byteCount = checkGetBounds(SizeOf.CHAR, dst.length, dstOffset, charCount); 115fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.peekCharArray(offset + position, dst, dstOffset, charCount, order.needsSwap); 116fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position += byteCount; 117fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 118fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 119fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes final void get(double[] dst, int dstOffset, int doubleCount) { 120fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int byteCount = checkGetBounds(SizeOf.DOUBLE, dst.length, dstOffset, doubleCount); 121fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.peekDoubleArray(offset + position, dst, dstOffset, doubleCount, order.needsSwap); 122fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position += byteCount; 123fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 124fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 125fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes final void get(float[] dst, int dstOffset, int floatCount) { 126fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int byteCount = checkGetBounds(SizeOf.FLOAT, dst.length, dstOffset, floatCount); 127fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.peekFloatArray(offset + position, dst, dstOffset, floatCount, order.needsSwap); 128fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position += byteCount; 129fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 130fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 131fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes final void get(int[] dst, int dstOffset, int intCount) { 132fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int byteCount = checkGetBounds(SizeOf.INT, dst.length, dstOffset, intCount); 133fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.peekIntArray(offset + position, dst, dstOffset, intCount, order.needsSwap); 134fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position += byteCount; 135fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 136fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 137fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes final void get(long[] dst, int dstOffset, int longCount) { 138fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int byteCount = checkGetBounds(SizeOf.LONG, dst.length, dstOffset, longCount); 139fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.peekLongArray(offset + position, dst, dstOffset, longCount, order.needsSwap); 140fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position += byteCount; 141fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 142fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 143fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes final void get(short[] dst, int dstOffset, int shortCount) { 144fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int byteCount = checkGetBounds(SizeOf.SHORT, dst.length, dstOffset, shortCount); 145fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.peekShortArray(offset + position, dst, dstOffset, shortCount, order.needsSwap); 146fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position += byteCount; 147fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 148fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 149fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final byte get() { 150fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (position == limit) { 151fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new BufferUnderflowException(); 152adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 153fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this.block.peekByte(offset + position++); 154fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 155fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 156fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final byte get(int index) { 157fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes checkIndex(index); 158fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this.block.peekByte(offset + index); 159fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 160fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 161fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final char getChar() { 162fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int newPosition = position + SizeOf.CHAR; 163fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (newPosition > limit) { 164fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new BufferUnderflowException(); 1650bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes } 166fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes char result = (char) this.block.peekShort(offset + position, order); 167fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position = newPosition; 168fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return result; 169fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 170fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 171fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final char getChar(int index) { 172fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes checkIndex(index, SizeOf.CHAR); 173fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return (char) this.block.peekShort(offset + index, order); 174fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 175fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 176fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final double getDouble() { 177fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int newPosition = position + SizeOf.DOUBLE; 178fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (newPosition > limit) { 179fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new BufferUnderflowException(); 1800bc30ae8420b5b1abc1b2eefbdf8846309b5447dElliott Hughes } 181fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes double result = Double.longBitsToDouble(this.block.peekLong(offset + position, order)); 182fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position = newPosition; 183fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return result; 184fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 185fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 186fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final double getDouble(int index) { 187fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes checkIndex(index, SizeOf.DOUBLE); 188fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return Double.longBitsToDouble(this.block.peekLong(offset + index, order)); 189fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 190fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 191fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final float getFloat() { 192fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int newPosition = position + SizeOf.FLOAT; 193fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (newPosition > limit) { 194fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new BufferUnderflowException(); 195adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 196fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes float result = Float.intBitsToFloat(this.block.peekInt(offset + position, order)); 197fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position = newPosition; 198fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return result; 199fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 200fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 201fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final float getFloat(int index) { 202fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes checkIndex(index, SizeOf.FLOAT); 203fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return Float.intBitsToFloat(this.block.peekInt(offset + index, order)); 204fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 205fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 206fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final int getInt() { 207fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int newPosition = position + SizeOf.INT; 208fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (newPosition > limit) { 209fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new BufferUnderflowException(); 210adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 211fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int result = this.block.peekInt(offset + position, order); 212fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position = newPosition; 213fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return result; 214fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 215fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 216fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final int getInt(int index) { 217fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes checkIndex(index, SizeOf.INT); 218fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this.block.peekInt(offset + index, order); 219fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 220fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 221fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final long getLong() { 222fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int newPosition = position + SizeOf.LONG; 223fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (newPosition > limit) { 224fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new BufferUnderflowException(); 225adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 226fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes long result = this.block.peekLong(offset + position, order); 227fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position = newPosition; 228fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return result; 229fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 230fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 231fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final long getLong(int index) { 232fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes checkIndex(index, SizeOf.LONG); 233fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this.block.peekLong(offset + index, order); 234fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 235fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 236fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final short getShort() { 237fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int newPosition = position + SizeOf.SHORT; 238fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (newPosition > limit) { 239fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new BufferUnderflowException(); 240adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 241fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes short result = this.block.peekShort(offset + position, order); 242fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position = newPosition; 243fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return result; 244fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 245fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 246fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final short getShort(int index) { 247fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes checkIndex(index, SizeOf.SHORT); 248fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this.block.peekShort(offset + index, order); 249fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 250fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 251fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final boolean isDirect() { 252fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return true; 253fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 254fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 255fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes public final void free() { 256fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes block.free(); 257fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 258fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 259fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final CharBuffer asCharBuffer() { 260fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return ByteBufferAsCharBuffer.asCharBuffer(this); 261fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 262fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 263fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final DoubleBuffer asDoubleBuffer() { 264fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return ByteBufferAsDoubleBuffer.asDoubleBuffer(this); 265fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 266fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 267fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final FloatBuffer asFloatBuffer() { 268fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return ByteBufferAsFloatBuffer.asFloatBuffer(this); 269fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 270fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 271fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final IntBuffer asIntBuffer() { 272fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return ByteBufferAsIntBuffer.asIntBuffer(this); 273fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 274fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 275fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final LongBuffer asLongBuffer() { 276fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return ByteBufferAsLongBuffer.asLongBuffer(this); 277fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 278fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 279fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public final ShortBuffer asShortBuffer() { 280fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return ByteBufferAsShortBuffer.asShortBuffer(this); 281fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 282fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 283fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer put(byte value) { 284fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (isReadOnly) { 285fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new ReadOnlyBufferException(); 286adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 287fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (position == limit) { 288fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new BufferOverflowException(); 289adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 290fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeByte(offset + position++, value); 291fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this; 292fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 293adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project 294fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer put(int index, byte value) { 295fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (isReadOnly) { 296fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new ReadOnlyBufferException(); 297adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 298fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes checkIndex(index); 299fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeByte(offset + index, value); 300fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this; 301fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 302fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 303fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer put(byte[] src, int srcOffset, int byteCount) { 304fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (isReadOnly) { 305fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new ReadOnlyBufferException(); 306adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 307fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes checkPutBounds(1, src.length, srcOffset, byteCount); 308fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeByteArray(offset + position, src, srcOffset, byteCount); 309fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position += byteCount; 310fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this; 311fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 312fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 313fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes final void put(char[] src, int srcOffset, int charCount) { 314fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int byteCount = checkPutBounds(SizeOf.CHAR, src.length, srcOffset, charCount); 315fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeCharArray(offset + position, src, srcOffset, charCount, order.needsSwap); 316fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position += byteCount; 317fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 318fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 319fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes final void put(double[] src, int srcOffset, int doubleCount) { 320fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int byteCount = checkPutBounds(SizeOf.DOUBLE, src.length, srcOffset, doubleCount); 321fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeDoubleArray(offset + position, src, srcOffset, doubleCount, order.needsSwap); 322fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position += byteCount; 323fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 324fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 325fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes final void put(float[] src, int srcOffset, int floatCount) { 326fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int byteCount = checkPutBounds(SizeOf.FLOAT, src.length, srcOffset, floatCount); 327fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeFloatArray(offset + position, src, srcOffset, floatCount, order.needsSwap); 328fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position += byteCount; 329fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 330fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 331fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes final void put(int[] src, int srcOffset, int intCount) { 332fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int byteCount = checkPutBounds(SizeOf.INT, src.length, srcOffset, intCount); 333fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeIntArray(offset + position, src, srcOffset, intCount, order.needsSwap); 334fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position += byteCount; 335fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 336fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 337fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes final void put(long[] src, int srcOffset, int longCount) { 338fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int byteCount = checkPutBounds(SizeOf.LONG, src.length, srcOffset, longCount); 339fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeLongArray(offset + position, src, srcOffset, longCount, order.needsSwap); 340fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position += byteCount; 341fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 342fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 343fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes final void put(short[] src, int srcOffset, int shortCount) { 344fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int byteCount = checkPutBounds(SizeOf.SHORT, src.length, srcOffset, shortCount); 345fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeShortArray(offset + position, src, srcOffset, shortCount, order.needsSwap); 346fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position += byteCount; 347fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 348fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 349fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer putChar(char value) { 350fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (isReadOnly) { 351fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new ReadOnlyBufferException(); 352adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 353fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int newPosition = position + SizeOf.CHAR; 354fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (newPosition > limit) { 355fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new BufferOverflowException(); 356adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 357fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeShort(offset + position, (short) value, order); 358fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position = newPosition; 359fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this; 360fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 361fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 362fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer putChar(int index, char value) { 363fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (isReadOnly) { 364fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new ReadOnlyBufferException(); 365adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 366fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes checkIndex(index, SizeOf.CHAR); 367fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeShort(offset + index, (short) value, order); 368fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this; 369fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 370fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 371fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer putDouble(double value) { 372fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (isReadOnly) { 373fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new ReadOnlyBufferException(); 374adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 375fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int newPosition = position + SizeOf.DOUBLE; 376fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (newPosition > limit) { 377fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new BufferOverflowException(); 378adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 379fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeLong(offset + position, Double.doubleToRawLongBits(value), order); 380fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position = newPosition; 381fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this; 382fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 383fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 384fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer putDouble(int index, double value) { 385fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (isReadOnly) { 386fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new ReadOnlyBufferException(); 387adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 388fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes checkIndex(index, SizeOf.DOUBLE); 389fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeLong(offset + index, Double.doubleToRawLongBits(value), order); 390fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this; 391fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 392fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 393fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer putFloat(float value) { 394fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (isReadOnly) { 395fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new ReadOnlyBufferException(); 396fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 397fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int newPosition = position + SizeOf.FLOAT; 398fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (newPosition > limit) { 399fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new BufferOverflowException(); 400fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 401fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeInt(offset + position, Float.floatToRawIntBits(value), order); 402fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position = newPosition; 403fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this; 404fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 405fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 406fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer putFloat(int index, float value) { 407fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (isReadOnly) { 408fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new ReadOnlyBufferException(); 409fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 410fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes checkIndex(index, SizeOf.FLOAT); 411fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeInt(offset + index, Float.floatToRawIntBits(value), order); 412fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this; 413fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 414fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 415fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer putInt(int value) { 416fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (isReadOnly) { 417fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new ReadOnlyBufferException(); 418fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 419fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int newPosition = position + SizeOf.INT; 420fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (newPosition > limit) { 421fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new BufferOverflowException(); 422fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 423fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeInt(offset + position, value, order); 424fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position = newPosition; 425fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this; 426fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 427fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 428fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer putInt(int index, int value) { 429fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (isReadOnly) { 430fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new ReadOnlyBufferException(); 431fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 432fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes checkIndex(index, SizeOf.INT); 433fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeInt(offset + index, value, order); 434fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this; 435fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 436fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 437fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer putLong(long value) { 438fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (isReadOnly) { 439fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new ReadOnlyBufferException(); 440fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 441fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int newPosition = position + SizeOf.LONG; 442fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (newPosition > limit) { 443fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new BufferOverflowException(); 444fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 445fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeLong(offset + position, value, order); 446fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position = newPosition; 447fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this; 448fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 449fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 450fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer putLong(int index, long value) { 451fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (isReadOnly) { 452fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new ReadOnlyBufferException(); 453fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 454fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes checkIndex(index, SizeOf.LONG); 455fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeLong(offset + index, value, order); 456fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this; 457fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 458fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 459fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer putShort(short value) { 460fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (isReadOnly) { 461fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new ReadOnlyBufferException(); 462fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 463fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes int newPosition = position + SizeOf.SHORT; 464fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (newPosition > limit) { 465fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new BufferOverflowException(); 466fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 467fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeShort(offset + position, value, order); 468fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes position = newPosition; 469fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this; 470fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 471fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes 472fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes @Override public ByteBuffer putShort(int index, short value) { 473fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes if (isReadOnly) { 474fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes throw new ReadOnlyBufferException(); 475adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project } 476fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes checkIndex(index, SizeOf.SHORT); 477fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes this.block.pokeShort(offset + index, value, order); 478fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes return this; 479fe5da19e0e366286cd4d95f7628fe9442b9062c8Elliott Hughes } 480adc854b798c1cfe3bfd4c27d68d5cee38ca617daThe Android Open Source Project} 481