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: * ShortArrayBuffer, ReadWriteShortArrayBuffer and ReadOnlyShortArrayBuffer
022: * compose the implementation of array based short buffers.
023: * <p>
024: * ReadOnlyShortArrayBuffer extends ShortArrayBuffer 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 ReadOnlyShortArrayBuffer extends ShortArrayBuffer {
033:
034: static ReadOnlyShortArrayBuffer copy(ShortArrayBuffer other,
035: int markOfOther) {
036: ReadOnlyShortArrayBuffer buf = new ReadOnlyShortArrayBuffer(
037: other.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: ReadOnlyShortArrayBuffer(int capacity, short[] backingArray,
045: int arrayOffset) {
046: super (capacity, backingArray, arrayOffset);
047: }
048:
049: @Override
050: public ShortBuffer asReadOnlyBuffer() {
051: return duplicate();
052: }
053:
054: @Override
055: public ShortBuffer compact() {
056: throw new ReadOnlyBufferException();
057: }
058:
059: @Override
060: public ShortBuffer duplicate() {
061: return copy(this , mark);
062: }
063:
064: @Override
065: public boolean isReadOnly() {
066: return true;
067: }
068:
069: @Override
070: protected short[] 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 ShortBuffer put(ShortBuffer buf) {
086: throw new ReadOnlyBufferException();
087: }
088:
089: @Override
090: public ShortBuffer put(short c) {
091: throw new ReadOnlyBufferException();
092: }
093:
094: @Override
095: public ShortBuffer put(int index, short c) {
096: throw new ReadOnlyBufferException();
097: }
098:
099: @Override
100: public final ShortBuffer put(short[] src, int off, int len) {
101: throw new ReadOnlyBufferException();
102: }
103:
104: @Override
105: public ShortBuffer slice() {
106: return new ReadOnlyShortArrayBuffer(remaining(), backingArray,
107: offset + position);
108: }
109:
110: }
|