| 11 | package java.nio; |
| 12 | |
| 13 | class ArrayByteBuffer extends ByteBuffer { |
| 14 | private final byte[] array; |
| 15 | private final int arrayOffset; |
| 16 | |
| 17 | ArrayByteBuffer(byte[] array, int offset, int length, boolean readOnly) { |
| 18 | super(readOnly); |
| 19 | |
| 20 | this.array = array; |
| 21 | this.arrayOffset = offset; |
| 22 | this.capacity = length; |
| 23 | this.limit = length; |
| 24 | this.position = 0; |
| 25 | } |
| 26 | |
| 27 | public ByteBuffer asReadOnlyBuffer() { |
| 28 | ByteBuffer b = new ArrayByteBuffer(array, arrayOffset, capacity, true); |
| 29 | b.position(position()); |
| 30 | b.limit(limit()); |
| 31 | return b; |
| 32 | } |
| 33 | |
| 34 | public boolean hasArray() { |
| 35 | return true; |
| 36 | } |
| 37 | |
| 38 | public byte[] array() { |
| 39 | return array; |
| 40 | } |
| 41 | |
| 42 | public ByteBuffer slice() { |
| 43 | return new ArrayByteBuffer |
| 44 | (array, arrayOffset + position, remaining(), true); |
| 45 | } |
| 46 | |
| 47 | public int arrayOffset() { |
| 48 | return arrayOffset; |
| 49 | } |
| 50 | |
| 51 | protected void doPut(int position, byte val) { |
| 52 | array[arrayOffset + position] = val; |
| 53 | } |
| 54 | |
| 55 | public ByteBuffer put(ByteBuffer src) { |
| 56 | int length = src.remaining(); |
| 57 | checkPut(position, length, false); |
| 58 | src.get(array, arrayOffset + position, length); |
| 59 | position += length; |
| 60 | return this; |
| 61 | } |
| 62 | |
| 63 | public ByteBuffer put(byte[] src, int offset, int length) { |
| 64 | checkPut(position, length, false); |
| 65 | |
| 66 | System.arraycopy(src, offset, array, arrayOffset + position, length); |
| 67 | position += length; |
| 68 | |
| 69 | return this; |
| 70 | } |
nothing calls this directly
no outgoing calls
no test coverage detected