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 18package java.nio; 19 20/** 21 * LongArrayBuffer, ReadWriteLongArrayBuffer and ReadOnlyLongArrayBuffer compose 22 * the implementation of array based long buffers. 23 * <p> 24 * ReadOnlyLongArrayBuffer extends LongArrayBuffer with all the write methods 25 * throwing read only exception. 26 * </p> 27 * <p> 28 * This class is marked final for runtime performance. 29 * </p> 30 * 31 */ 32final class ReadOnlyLongArrayBuffer extends LongArrayBuffer { 33 34 static ReadOnlyLongArrayBuffer copy(LongArrayBuffer other, int markOfOther) { 35 ReadOnlyLongArrayBuffer buf = new ReadOnlyLongArrayBuffer(other 36 .capacity(), other.backingArray, other.offset); 37 buf.limit = other.limit(); 38 buf.position = other.position(); 39 buf.mark = markOfOther; 40 return buf; 41 } 42 43 ReadOnlyLongArrayBuffer(int capacity, long[] backingArray, int arrayOffset) { 44 super(capacity, backingArray, arrayOffset); 45 } 46 47 @Override 48 public LongBuffer asReadOnlyBuffer() { 49 return duplicate(); 50 } 51 52 @Override 53 public LongBuffer compact() { 54 throw new ReadOnlyBufferException(); 55 } 56 57 @Override 58 public LongBuffer duplicate() { 59 return copy(this, mark); 60 } 61 62 @Override 63 public boolean isReadOnly() { 64 return true; 65 } 66 67 @Override 68 protected long[] protectedArray() { 69 throw new ReadOnlyBufferException(); 70 } 71 72 @Override 73 protected int protectedArrayOffset() { 74 throw new ReadOnlyBufferException(); 75 } 76 77 @Override 78 protected boolean protectedHasArray() { 79 return false; 80 } 81 82 @Override 83 public LongBuffer put(long c) { 84 throw new ReadOnlyBufferException(); 85 } 86 87 @Override 88 public LongBuffer put(int index, long c) { 89 throw new ReadOnlyBufferException(); 90 } 91 92 @Override 93 public LongBuffer put(LongBuffer buf) { 94 throw new ReadOnlyBufferException(); 95 } 96 97 @Override 98 public final LongBuffer put(long[] src, int off, int len) { 99 throw new ReadOnlyBufferException(); 100 } 101 102 @Override 103 public LongBuffer slice() { 104 return new ReadOnlyLongArrayBuffer(remaining(), backingArray, offset 105 + position); 106 } 107 108} 109