1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 package java.nio; 19 20 /** IntArrayBuffer, ReadWriteIntArrayBuffer and ReadOnlyIntArrayBuffer compose the implementation of array based int buffers. 21 * <p> 22 * ReadOnlyIntArrayBuffer extends IntArrayBuffer with all the write methods throwing read only exception. 23 * </p> 24 * <p> 25 * This class is marked final for runtime performance. 26 * </p> */ 27 final class ReadOnlyIntArrayBuffer extends IntArrayBuffer { 28 29 static ReadOnlyIntArrayBuffer copy (IntArrayBuffer other, int markOfOther) { 30 ReadOnlyIntArrayBuffer buf = new ReadOnlyIntArrayBuffer(other.capacity(), other.backingArray, other.offset); 31 buf.limit = other.limit(); 32 buf.position = other.position(); 33 buf.mark = markOfOther; 34 return buf; 35 } 36 37 ReadOnlyIntArrayBuffer (int capacity, int[] backingArray, int arrayOffset) { 38 super(capacity, backingArray, arrayOffset); 39 } 40 41 public IntBuffer asReadOnlyBuffer () { 42 return duplicate(); 43 } 44 45 public IntBuffer compact () { 46 throw new ReadOnlyBufferException(); 47 } 48 49 public IntBuffer duplicate () { 50 return copy(this, mark); 51 } 52 53 public boolean isReadOnly () { 54 return true; 55 } 56 57 protected int[] protectedArray () { 58 throw new ReadOnlyBufferException(); 59 } 60 61 protected int protectedArrayOffset () { 62 throw new ReadOnlyBufferException(); 63 } 64 65 protected boolean protectedHasArray () { 66 return false; 67 } 68 69 public IntBuffer put (int c) { 70 throw new ReadOnlyBufferException(); 71 } 72 73 public IntBuffer put (int index, int c) { 74 throw new ReadOnlyBufferException(); 75 } 76 77 public IntBuffer put (IntBuffer buf) { 78 throw new ReadOnlyBufferException(); 79 } 80 81 public final IntBuffer put (int[] src, int off, int len) { 82 throw new ReadOnlyBufferException(); 83 } 84 85 public IntBuffer slice () { 86 return new ReadOnlyIntArrayBuffer(remaining(), backingArray, offset + position); 87 } 88 89 } 90