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: * DoubleArrayBuffer, ReadWriteDoubleArrayBuffer and ReadOnlyDoubleArrayBuffer
022: * compose the implementation of array based double buffers.
023: * <p>
024: * ReadOnlyDoubleArrayBuffer extends DoubleArrayBuffer with all the write
025: * methods throwing read only exception.
026: * </p>
027: * <p>
028: * This class is marked final for runtime performance.
029: * </p>
030: *
031: */
032: final class ReadOnlyDoubleArrayBuffer extends DoubleArrayBuffer {
033:
034: static ReadOnlyDoubleArrayBuffer copy(DoubleArrayBuffer other,
035: int markOfOther) {
036: ReadOnlyDoubleArrayBuffer buf = new ReadOnlyDoubleArrayBuffer(
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: ReadOnlyDoubleArrayBuffer(int capacity, double[] backingArray,
045: int arrayOffset) {
046: super (capacity, backingArray, arrayOffset);
047: }
048:
049: @Override
050: public DoubleBuffer asReadOnlyBuffer() {
051: return duplicate();
052: }
053:
054: @Override
055: public DoubleBuffer compact() {
056: throw new ReadOnlyBufferException();
057: }
058:
059: @Override
060: public DoubleBuffer duplicate() {
061: return copy(this , mark);
062: }
063:
064: @Override
065: public boolean isReadOnly() {
066: return true;
067: }
068:
069: @Override
070: protected double[] 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 DoubleBuffer put(double c) {
086: throw new ReadOnlyBufferException();
087: }
088:
089: @Override
090: public DoubleBuffer put(int index, double c) {
091: throw new ReadOnlyBufferException();
092: }
093:
094: @Override
095: public final DoubleBuffer put(double[] src, int off, int len) {
096: throw new ReadOnlyBufferException();
097: }
098:
099: @Override
100: public final DoubleBuffer put(DoubleBuffer buf) {
101: throw new ReadOnlyBufferException();
102: }
103:
104: @Override
105: public DoubleBuffer slice() {
106: return new ReadOnlyDoubleArrayBuffer(remaining(), backingArray,
107: offset + position);
108: }
109:
110: }
|