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 * CharArrayBuffer, ReadWriteCharArrayBuffer and ReadOnlyCharArrayBuffer compose 22 * the implementation of array based char buffers. 23 * <p> 24 * ReadOnlyCharArrayBuffer extends CharArrayBuffer 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 ReadOnlyCharArrayBuffer extends CharArrayBuffer { 33 34 static ReadOnlyCharArrayBuffer copy(CharArrayBuffer other, int markOfOther) { 35 ReadOnlyCharArrayBuffer buf = 36 new ReadOnlyCharArrayBuffer(other.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 ReadOnlyCharArrayBuffer(int capacity, char[] backingArray, int arrayOffset) { 44 super(capacity, backingArray, arrayOffset); 45 } 46 47 @Override 48 public CharBuffer asReadOnlyBuffer() { 49 return duplicate(); 50 } 51 52 @Override 53 public CharBuffer compact() { 54 throw new ReadOnlyBufferException(); 55 } 56 57 @Override 58 public CharBuffer duplicate() { 59 return copy(this, mark); 60 } 61 62 @Override 63 public boolean isReadOnly() { 64 return true; 65 } 66 67 @Override char[] protectedArray() { 68 throw new ReadOnlyBufferException(); 69 } 70 71 @Override int protectedArrayOffset() { 72 throw new ReadOnlyBufferException(); 73 } 74 75 @Override boolean protectedHasArray() { 76 return false; 77 } 78 79 @Override 80 public CharBuffer put(char c) { 81 throw new ReadOnlyBufferException(); 82 } 83 84 @Override 85 public CharBuffer put(int index, char c) { 86 throw new ReadOnlyBufferException(); 87 } 88 89 @Override 90 public final CharBuffer put(char[] src, int srcOffset, int charCount) { 91 throw new ReadOnlyBufferException(); 92 } 93 94 @Override 95 public final CharBuffer put(CharBuffer src) { 96 throw new ReadOnlyBufferException(); 97 } 98 99 @Override 100 public CharBuffer put(String src, int start, int end) { 101 throw new ReadOnlyBufferException(); 102 } 103 104 @Override 105 public CharBuffer slice() { 106 return new ReadOnlyCharArrayBuffer(remaining(), backingArray, offset + position); 107 } 108} 109