001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package java.nio;
019:
020: /**
021: * IntArrayBuffer, ReadWriteIntArrayBuffer and ReadOnlyIntArrayBuffer compose
022: * the implementation of array based int buffers.
023: * <p>
024: * ReadOnlyIntArrayBuffer extends IntArrayBuffer with all the write methods
025: * throwing read only exception.
026: * </p>
027: * <p>
028: * This class is marked final for runtime performance.
029: * </p>
030: *
031: */
032: final class ReadOnlyIntArrayBuffer extends IntArrayBuffer {
033:
034: static ReadOnlyIntArrayBuffer copy(IntArrayBuffer other,
035: int markOfOther) {
036: ReadOnlyIntArrayBuffer buf = new ReadOnlyIntArrayBuffer(other
037: .capacity(), other.backingArray, other.offset);
038: buf.limit = other.limit();
039: buf.position = other.position();
040: buf.mark = markOfOther;
041: return buf;
042: }
043:
044: ReadOnlyIntArrayBuffer(int capacity, int[] backingArray,
045: int arrayOffset) {
046: super (capacity, backingArray, arrayOffset);
047: }
048:
049: @Override
050: public IntBuffer asReadOnlyBuffer() {
051: return duplicate();
052: }
053:
054: @Override
055: public IntBuffer compact() {
056: throw new ReadOnlyBufferException();
057: }
058:
059: @Override
060: public IntBuffer duplicate() {
061: return copy(this , mark);
062: }
063:
064: @Override
065: public boolean isReadOnly() {
066: return true;
067: }
068:
069: @Override
070: protected int[] protectedArray() {
071: throw new ReadOnlyBufferException();
072: }
073:
074: @Override
075: protected int protectedArrayOffset() {
076: throw new ReadOnlyBufferException();
077: }
078:
079: @Override
080: protected boolean protectedHasArray() {
081: return false;
082: }
083:
084: @Override
085: public IntBuffer put(int c) {
086: throw new ReadOnlyBufferException();
087: }
088:
089: @Override
090: public IntBuffer put(int index, int c) {
091: throw new ReadOnlyBufferException();
092: }
093:
094: @Override
095: public IntBuffer put(IntBuffer buf) {
096: throw new ReadOnlyBufferException();
097: }
098:
099: @Override
100: public final IntBuffer put(int[] src, int off, int len) {
101: throw new ReadOnlyBufferException();
102: }
103:
104: @Override
105: public IntBuffer slice() {
106: return new ReadOnlyIntArrayBuffer(remaining(), backingArray,
107: offset + position);
108: }
109:
110: }
|