You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2005/12/01 07:04:00 UTC
svn commit: r350181 [124/198] - in
/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/
depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/
depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/
depends/oss/win....
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/FileChannelImpl.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/FileChannelImpl.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/FileChannelImpl.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/FileChannelImpl.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,369 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.MappedByteBuffer;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+import java.nio.channels.NonReadableChannelException;
+import java.nio.channels.NonWritableChannelException;
+import java.nio.channels.ReadableByteChannel;
+import java.nio.channels.WritableByteChannel;
+
+import com.ibm.misc.util.NotYetImplementedException;
+import com.ibm.platform.IFileSystem;
+import com.ibm.platform.Platform;
+import com.ibm.platform.struct.PlatformAddress;
+
+/*
+ * The file channel impl class is the bridge between the logical channels
+ * described by the NIO channel framework, and the file system implementation
+ * provided by the port layer.
+ *
+ * This class is non-API, but implements the API of the FileChannel interface.
+ *
+ */
+public class FileChannelImpl extends FileChannel {
+
+ // Reference to the portable file system code.
+ private static final IFileSystem fileSystem = Platform.getFileSystem();
+
+ // Handle to the open file
+ private final long handle;
+
+ /*
+ * The mode in which we are allowed to manipulate the underlying file.
+ * defined in the interface IFileSystem.
+ */
+ private final int openMode;
+
+ // The object that will track all outstanding locks on this channel.
+ private final LockManager lockManager = new LockManager();
+
+ private final Object repositioningLock = new Object();
+
+ // Latch that shows when the underlying file has definitely been closed.
+ private boolean isClosed = false;
+
+ /*
+ * Create a new file channel implementation class that wraps the given file
+ * handle and operates in the specififed mode.
+ *
+ */
+ public FileChannelImpl(long handle, int openMode) {
+ super();
+ this.handle = handle;
+ this.openMode = openMode;
+ }
+
+ private final boolean isReadOnly() {
+ return openMode == IFileSystem.O_RDONLY;
+ }
+
+ private final boolean isWriteOnly() {
+ return openMode == IFileSystem.O_WRONLY;
+ }
+
+ private final boolean isReadWrite() {
+ return openMode == IFileSystem.O_RDWR;
+ }
+
+ private final boolean isReadable() {
+ return isReadOnly() || isReadWrite();
+ }
+
+ private final boolean isWritable() {
+ return isWriteOnly() || isReadWrite();
+ }
+
+ /*
+ * Helper method to throw an exception if the channel is already closed.
+ * Note that we don't bother to synchronize on this test since the file may
+ * be closed by operations beyond our control anyways.
+ */
+ protected final void openCheck() throws ClosedChannelException {
+ if (isClosed) {
+ throw new ClosedChannelException();
+ }
+ }
+
+ protected final void writeCheck() throws ClosedChannelException,
+ NonWritableChannelException {
+ openCheck();
+ if (!isWritable()) {
+ throw new NonWritableChannelException();
+ }
+ }
+
+ protected final void readCheck() throws ClosedChannelException,
+ NonReadableChannelException {
+ openCheck();
+ if (!isReadable()) {
+ throw new NonReadableChannelException();
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.channels.spi.AbstractInterruptibleChannel#implCloseChannel()
+ */
+ public void closeChannel() throws IOException {
+ fileSystem.close(handle);
+ }
+
+ protected FileLock basicLock(long position, long size, boolean shared,
+ boolean wait) throws IOException {
+ if ((position < 0) || (size < 0)) {
+ throw new IllegalArgumentException(
+ "Lock position and size must be non-negative."); //$NON-NLS-1$
+ }
+ int lockType;
+ if (shared) {
+ readCheck();
+ lockType = IFileSystem.SHARED_LOCK_TYPE;
+ } else {
+ writeCheck();
+ lockType = IFileSystem.EXCLUSIVE_LOCK_TYPE;
+ }
+
+ FileLock pendingLock = new FileLockImpl(this, position, size, shared);
+ lockManager.addLock(pendingLock);
+
+ if (fileSystem.lock(handle, position, size, lockType, wait)) {
+ return pendingLock;
+ }
+
+ // Lock acquisition failed
+ lockManager.removeLock(pendingLock);
+ return null;
+ }
+
+ /*
+ * Acquire a lock on the receiver, blocks if the lock cannot be obtained
+ * immediately.
+ *
+ * @see java.nio.channels.FileChannel#lock(long, long, boolean)
+ */
+ public FileLock lock(long position, long size, boolean shared)
+ throws IOException {
+ return basicLock(position, size, shared, true);
+ }
+
+ /*
+ * Attempts to acquire the given lock, but does not block. If the lock
+ * cannot be acquired the method returns null.
+ *
+ * @see java.nio.channels.FileChannel#tryLock(long, long, boolean)
+ */
+ public FileLock tryLock(long position, long size, boolean shared)
+ throws IOException {
+ return basicLock(position, size, shared, false);
+ }
+
+ /*
+ * Non-API method to release a given lock on a file channel. Assumes that
+ * the lock will mark itself invalid after successful unlocking.
+ */
+ void release(FileLock lock) throws IOException {
+ openCheck();
+ fileSystem.unlock(handle, lock.position(), lock.size());
+ lockManager.removeLock(lock);
+ }
+
+ /*
+ * Flush the contents of the file to disk, and the metadata if asked.
+ */
+ public void force(boolean metadata) throws IOException {
+ openCheck();
+ // Forcing data-only on a read-only file is a no-op.
+ if (!metadata & isReadOnly()) {
+ return;
+ }
+ fileSystem.fflush(handle, metadata);
+ }
+
+ public MappedByteBuffer map(MapMode mode, long position, long size)
+ throws IOException {
+ openCheck();
+
+ if (mode == null) {
+ throw new NullPointerException();
+ }
+ int mapMode;
+ if (mode == MapMode.READ_ONLY) {
+ mapMode = IFileSystem.MMAP_READ_ONLY;
+ } else {
+ if (mode == MapMode.READ_WRITE) {
+ mapMode = IFileSystem.MMAP_READ_WRITE;
+ } else {
+ mapMode = IFileSystem.MMAP_WRITE_COPY;
+ }
+ }
+ PlatformAddress address = fileSystem.mmap(handle, position, size,
+ mapMode);
+
+ throw new NotYetImplementedException();
+ }
+
+ /*
+ * Answers the current file position.
+ */
+ public long position() throws IOException {
+ openCheck();
+ return fileSystem.seek(handle, 0L, IFileSystem.SEEK_CUR);
+ }
+
+ /*
+ * Sets the file pointer.
+ */
+ public FileChannel position(long newPosition) throws IOException {
+ if (newPosition < 0) {
+ throw new IllegalArgumentException(
+ "New position must be non-negative."); //$NON-NLS-1$
+ }
+ openCheck();
+
+ synchronized (repositioningLock) {
+ fileSystem.seek(handle, newPosition, IFileSystem.SEEK_SET);
+ }
+ return this;
+ }
+
+ public int read(ByteBuffer buffer, long position) throws IOException {
+ synchronized (repositioningLock) {
+ int bytesRead = 0;
+ long preReadPosition = position();
+ position(position);
+ try {
+ bytesRead = read(buffer);
+ } finally {
+ position(preReadPosition);
+ }
+ return bytesRead;
+ }
+ }
+
+ public int read(ByteBuffer buffer) throws IOException {
+ readCheck();
+ int bytesRead;
+ synchronized (repositioningLock) {
+ if (buffer.isDirect()) {
+ DirectByteBuffer directBuffer = (DirectByteBuffer) buffer;
+ long address = directBuffer.getEffectiveAddress().toLong();
+ bytesRead = (int) fileSystem.readDirect(handle, address, buffer
+ .remaining());
+ } else {
+ HeapByteBuffer heapBuffer = (HeapByteBuffer) buffer;
+ bytesRead = (int) fileSystem.read(handle, heapBuffer.array(),
+ heapBuffer.arrayOffset(), buffer.remaining());
+ }
+ if (bytesRead > 0) {
+ buffer.position(buffer.position() + bytesRead);
+ }
+ }
+ return bytesRead;
+ }
+
+ public long read(ByteBuffer[] buffers, int offset, int length)
+ throws IOException {
+ readCheck();
+ throw new NotYetImplementedException();
+ }
+
+ /*
+ * Answers the current file size, as an integer number of bytes.
+ */
+ public long size() throws IOException {
+ readCheck();
+ synchronized (repositioningLock) {
+ long currentPosition = fileSystem.seek(handle, 0L,
+ IFileSystem.SEEK_CUR);
+ long endOfFilePosition = fileSystem.seek(handle, 0L,
+ IFileSystem.SEEK_END);
+ fileSystem.seek(handle, currentPosition, IFileSystem.SEEK_SET);
+ return endOfFilePosition;
+ }
+ }
+
+ public long transferFrom(ReadableByteChannel src, long position, long count)
+ throws IOException {
+ writeCheck();
+ throw new NotYetImplementedException();
+ }
+
+ public long transferTo(long position, long count, WritableByteChannel target)
+ throws IOException {
+ readCheck();
+ throw new NotYetImplementedException();
+ }
+
+ public FileChannel truncate(long size) throws IOException {
+ writeCheck();
+ throw new NotYetImplementedException();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.channels.WritableByteChannel#write(java.nio.ByteBuffer)
+ */
+
+ public int write(ByteBuffer buffer, long position) throws IOException {
+ synchronized (repositioningLock) {
+ int bytesWritten = 0;
+ long preWritePosition = position();
+ position(position);
+ try {
+ bytesWritten = write(buffer);
+ } finally {
+ position(preWritePosition);
+ }
+ return bytesWritten;
+ }
+ }
+
+ public int write(ByteBuffer buffer) throws IOException {
+ writeCheck();
+ int bytesWritten;
+ synchronized (repositioningLock) {
+ if (buffer.isDirect()) {
+ DirectByteBuffer directBuffer = (DirectByteBuffer) buffer;
+ long address = directBuffer.getEffectiveAddress().toLong();
+ bytesWritten = (int) fileSystem.writeDirect(handle, address,
+ buffer.remaining());
+ } else {
+ HeapByteBuffer heapBuffer = (HeapByteBuffer) buffer;
+ bytesWritten = (int) fileSystem.write(handle, heapBuffer
+ .array(), heapBuffer.arrayOffset(), buffer.remaining());
+ }
+ if (bytesWritten > 0) {
+ buffer.position(buffer.position() + bytesWritten);
+ }
+ }
+ return bytesWritten;
+ }
+
+ public long write(ByteBuffer[] buffers, int offset, int length)
+ throws IOException {
+ writeCheck();
+ throw new NotYetImplementedException();
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/FileLockImpl.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/FileLockImpl.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/FileLockImpl.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/FileLockImpl.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,67 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.io.IOException;
+import java.nio.channels.FileChannel;
+import java.nio.channels.FileLock;
+
+/*
+ * The concrete implementation of an NIO file lock object.
+ *
+ */
+final class FileLockImpl extends FileLock {
+
+ // Remembers if this lock has been released via the API.
+ private boolean isReleased = false;
+
+ /*
+ * Answers a new file lock object with the given parameters.
+ *
+ * @param channel the file channel hosting the lock. @param position the
+ * start position of the lock, in bytes @param size the length of the lock,
+ * in bytes @param shared whether this lock is shared (true) or exclusive
+ * (false)
+ */
+ public FileLockImpl(FileChannel channel, long position, long size,
+ boolean shared) {
+ super(channel, position, size, shared);
+ }
+
+ /*
+ * Tests to see if the lock is valid. A lock can be invalidated if the
+ * channel it is acquired on is closed or if it is released. (non-Javadoc)
+ *
+ * @see java.nio.channels.FileLock#isValid()
+ */
+ public boolean isValid() {
+ return !isReleased && channel().isOpen();
+ }
+
+ /*
+ * Releases the file lock on the channel that acquired it. Releasing an
+ * invalid lock has no effect.
+ *
+ * @see java.nio.channels.FileLock#release()
+ */
+ public void release() throws IOException {
+ if (isValid()) {
+ ((FileChannelImpl) channel()).release(this);
+ isReleased = true;
+ }
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/FloatArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/FloatArrayBuffer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/FloatArrayBuffer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/FloatArrayBuffer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,77 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.BufferUnderflowException;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+
+/**
+ * FloatArrayBuffer, ReadWriteFloatArrayBuffer and ReadOnlyFloatArrayBuffer
+ * compose the implementation of array based float buffers.
+ * <p>
+ * FloatArrayBuffer implements all the shared readonly methods and is extended
+ * by the other two classes.
+ * </p>
+ * <p>
+ * All methods are marked final for runtime performance.
+ * </p>
+ *
+ */
+abstract class FloatArrayBuffer extends FloatBuffer {
+
+ protected final float[] backingArray;
+
+ protected final int offset;
+
+ FloatArrayBuffer(float[] array) {
+ this(array.length, array, 0);
+ }
+
+ FloatArrayBuffer(int capacity) {
+ this(capacity, new float[capacity], 0);
+ }
+
+ FloatArrayBuffer(int capacity, float[] backingArray, int offset) {
+ super(capacity);
+ this.backingArray = backingArray;
+ this.offset = offset;
+ }
+
+ public final float get() {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return backingArray[offset + position++];
+ }
+
+ public final float get(int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return backingArray[offset + index];
+ }
+
+ public final boolean isDirect() {
+ return false;
+ }
+
+ public final ByteOrder order() {
+ return ByteOrder.nativeOrder();
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/FloatToByteBufferAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/FloatToByteBufferAdapter.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/FloatToByteBufferAdapter.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/FloatToByteBufferAdapter.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,147 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.BufferOverflowException;
+import java.nio.BufferUnderflowException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.FloatBuffer;
+import java.nio.ReadOnlyBufferException;
+
+/**
+ * This class wraps a byte buffer to be a float buffer.
+ * <p>
+ * Implementation notice:
+ * <ul>
+ * <li>After a byte buffer instance is wrapped, it becomes privately owned by
+ * the adapter. It must NOT be accessed outside the adapter any more.</li>
+ * <li>The byte buffer's position and limit are NOT linked with the adapter.
+ * The adapter extends Buffer, thus has its own position and limit.</li>
+ * </ul>
+ * </p>
+ *
+ */
+final class FloatToByteBufferAdapter extends FloatBuffer {
+
+ static FloatBuffer wrap(ByteBuffer byteBuffer) {
+ return new FloatToByteBufferAdapter(byteBuffer.slice());
+ }
+
+ private final ByteBuffer byteBuffer;
+
+ FloatToByteBufferAdapter(ByteBuffer byteBuffer) {
+ super((byteBuffer.capacity() >> 2));
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ }
+
+ public FloatBuffer asReadOnlyBuffer() {
+ FloatToByteBufferAdapter buf = new FloatToByteBufferAdapter(byteBuffer
+ .asReadOnlyBuffer());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ public FloatBuffer compact() {
+ if (byteBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ byteBuffer.limit(limit << 2);
+ byteBuffer.position(position << 2);
+ byteBuffer.compact();
+ byteBuffer.clear();
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ public FloatBuffer duplicate() {
+ FloatToByteBufferAdapter buf = new FloatToByteBufferAdapter(byteBuffer
+ .duplicate());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ public float get() {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return byteBuffer.getFloat(position++ << 2);
+ }
+
+ public float get(int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return byteBuffer.getFloat(index << 2);
+ }
+
+ public boolean isDirect() {
+ return byteBuffer.isDirect();
+ }
+
+ public boolean isReadOnly() {
+ return byteBuffer.isReadOnly();
+ }
+
+ public ByteOrder order() {
+ return byteBuffer.order();
+ }
+
+ protected float[] protectedArray() {
+ throw new UnsupportedOperationException();
+ }
+
+ protected int protectedArrayOffset() {
+ throw new UnsupportedOperationException();
+ }
+
+ protected boolean protectedHasArray() {
+ return false;
+ }
+
+ public FloatBuffer put(float c) {
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ byteBuffer.putFloat(position++ << 2, c);
+ return this;
+ }
+
+ public FloatBuffer put(int index, float c) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ byteBuffer.putFloat(index << 2, c);
+ return this;
+ }
+
+ public FloatBuffer slice() {
+ byteBuffer.limit(limit << 2);
+ byteBuffer.position(position << 2);
+ FloatBuffer result = new FloatToByteBufferAdapter(byteBuffer.slice());
+ byteBuffer.clear();
+ return result;
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/HeapByteBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/HeapByteBuffer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/HeapByteBuffer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/HeapByteBuffer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,217 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.BufferUnderflowException;
+
+import com.ibm.platform.Endianness;
+
+/**
+ * HeapByteBuffer, ReadWriteHeapByteBuffer and ReadOnlyHeapByteBuffer compose
+ * the implementation of array based byte buffers.
+ * <p>
+ * HeapByteBuffer implements all the shared readonly methods and is extended by
+ * the other two classes.
+ * </p>
+ * <p>
+ * All methods are marked final for runtime performance.
+ * </p>
+ *
+ */
+abstract class HeapByteBuffer extends BaseByteBuffer {
+
+ protected final byte[] backingArray;
+
+ protected final int offset;
+
+ HeapByteBuffer(byte[] backingArray) {
+ this(backingArray, backingArray.length, 0);
+ }
+
+ HeapByteBuffer(int capacity) {
+ this(new byte[capacity], capacity, 0);
+ }
+
+ HeapByteBuffer(byte[] backingArray, int capacity, int offset) {
+ super(capacity);
+ this.backingArray = backingArray;
+ this.offset = offset;
+
+ if (offset + capacity > backingArray.length) {
+ throw new IndexOutOfBoundsException();
+ }
+ }
+
+ public final byte get() {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return backingArray[offset + position++];
+ }
+
+ public final byte get(int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return backingArray[offset + index];
+ }
+
+ public final double getDouble() {
+ return Double.longBitsToDouble(getLong());
+ }
+
+ public final double getDouble(int index) {
+ return Double.longBitsToDouble(getLong(index));
+ }
+
+ public final float getFloat() {
+ return Float.intBitsToFloat(getInt());
+ }
+
+ public final float getFloat(int index) {
+ return Float.intBitsToFloat(getInt(index));
+ }
+
+ public final int getInt() {
+ int newPosition = position + 4;
+ if (newPosition > limit) {
+ throw new BufferUnderflowException();
+ }
+ int result = loadInt(position);
+ position = newPosition;
+ return result;
+ }
+
+ public final int getInt(int index) {
+ if (index < 0 || index + 4 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return loadInt(index);
+ }
+
+ public final long getLong() {
+ int newPosition = position + 8;
+ if (newPosition > limit) {
+ throw new BufferUnderflowException();
+ }
+ long result = loadLong(position);
+ position = newPosition;
+ return result;
+ }
+
+ public final long getLong(int index) {
+ if (index < 0 || index + 8 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return loadLong(index);
+ }
+
+ public final short getShort() {
+ int newPosition = position + 2;
+ if (newPosition > limit) {
+ throw new BufferUnderflowException();
+ }
+ short result = loadShort(position);
+ position = newPosition;
+ return result;
+ }
+
+ public final short getShort(int index) {
+ if (index < 0 || index + 2 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return loadShort(index);
+ }
+
+ public final boolean isDirect() {
+ return false;
+ }
+
+ protected final int loadInt(int index) {
+ int baseOffset = offset + index;
+ int bytes = 0;
+ for (int i = 0; i < 4; i++) {
+ bytes = bytes << 8;
+ bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
+ }
+ return (order == Endianness.BIG_ENDIAN) ? bytes : swap(bytes);
+ }
+
+ protected final long loadLong(int index) {
+ int baseOffset = offset + index;
+ long bytes = 0;
+ for (int i = 0; i < 8; i++) {
+ bytes = bytes << 8;
+ bytes = bytes | (backingArray[baseOffset + i] & 0xFF);
+ }
+ return (order == Endianness.BIG_ENDIAN) ? bytes : swap(bytes);
+ }
+
+ protected final short loadShort(int index) {
+ int baseOffset = offset + index;
+ short bytes = (short) (backingArray[baseOffset] << 8);
+ bytes |= (backingArray[baseOffset + 1] & 0xFF);
+ return (order == Endianness.BIG_ENDIAN) ? bytes : swap(bytes);
+ }
+
+ protected final void store(int index, int value) {
+ int baseOffset = offset + index;
+ int bytes = (order == Endianness.BIG_ENDIAN) ? value : swap(value);
+ for (int i = 3; i >= 0; i--) {
+ backingArray[baseOffset + i] = (byte) (bytes & 0xFF);
+ bytes = bytes >> 8;
+ }
+ }
+
+ protected final void store(int index, long value) {
+ int baseOffset = offset + index;
+ long bytes = (order == Endianness.BIG_ENDIAN) ? value : swap(value);
+ for (int i = 7; i >= 0; i--) {
+ backingArray[baseOffset + i] = (byte) (bytes & 0xFF);
+ bytes = bytes >> 8;
+ }
+ }
+
+ protected final void store(int index, short value) {
+ int baseOffset = offset + index;
+ short bytes = (order == Endianness.BIG_ENDIAN) ? value : swap(value);
+ backingArray[baseOffset] = (byte) ((bytes >> 8) & 0xFF);
+ backingArray[baseOffset + 1] = (byte) (bytes & 0xFF);
+ }
+
+ private int swap(int value) {
+ short left = (short) (value >> 16);
+ short right = (short) value;
+ int topEnd = swap(right) << 16;
+ int btmEnd = swap(left) & 0xFFFF;
+ return topEnd | btmEnd;
+ }
+
+ private long swap(long value) {
+ int left = (int) (value >> 32);
+ int right = (int) value;
+ long topEnd = ((long) swap(right)) << 32;
+ long btmEnd = swap(left) & 0xFFFFFFFFL;
+ return topEnd | btmEnd;
+ }
+
+ private short swap(short value) {
+ int topEnd = value << 8;
+ int btmEnd = (value >> 8) & 0xFF;
+ return (short) (topEnd | btmEnd);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/IntArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/IntArrayBuffer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/IntArrayBuffer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/IntArrayBuffer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,77 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.BufferUnderflowException;
+import java.nio.ByteOrder;
+import java.nio.IntBuffer;
+
+/**
+ * IntArrayBuffer, ReadWriteIntArrayBuffer and ReadOnlyIntArrayBuffer compose
+ * the implementation of array based int buffers.
+ * <p>
+ * IntArrayBuffer implements all the shared readonly methods and is extended by
+ * the other two classes.
+ * </p>
+ * <p>
+ * All methods are marked final for runtime performance.
+ * </p>
+ *
+ */
+abstract class IntArrayBuffer extends IntBuffer {
+
+ protected final int[] backingArray;
+
+ protected final int offset;
+
+ IntArrayBuffer(int[] array) {
+ this(array.length, array, 0);
+ }
+
+ IntArrayBuffer(int capacity) {
+ this(capacity, new int[capacity], 0);
+ }
+
+ IntArrayBuffer(int capacity, int[] backingArray, int offset) {
+ super(capacity);
+ this.backingArray = backingArray;
+ this.offset = offset;
+ }
+
+ public final int get() {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return backingArray[offset + position++];
+ }
+
+ public final int get(int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return backingArray[offset + index];
+ }
+
+ public final boolean isDirect() {
+ return false;
+ }
+
+ public final ByteOrder order() {
+ return ByteOrder.nativeOrder();
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/IntToByteBufferAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/IntToByteBufferAdapter.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/IntToByteBufferAdapter.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/IntToByteBufferAdapter.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,147 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.BufferOverflowException;
+import java.nio.BufferUnderflowException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.IntBuffer;
+import java.nio.ReadOnlyBufferException;
+
+/**
+ * This class wraps a byte buffer to be a int buffer.
+ * <p>
+ * Implementation notice:
+ * <ul>
+ * <li>After a byte buffer instance is wrapped, it becomes privately owned by
+ * the adapter. It must NOT be accessed outside the adapter any more.</li>
+ * <li>The byte buffer's position and limit are NOT linked with the adapter.
+ * The adapter extends Buffer, thus has its own position and limit.</li>
+ * </ul>
+ * </p>
+ *
+ */
+final class IntToByteBufferAdapter extends IntBuffer {
+
+ static IntBuffer wrap(ByteBuffer byteBuffer) {
+ return new IntToByteBufferAdapter(byteBuffer.slice());
+ }
+
+ private final ByteBuffer byteBuffer;
+
+ IntToByteBufferAdapter(ByteBuffer byteBuffer) {
+ super((byteBuffer.capacity() >> 2));
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ }
+
+ public IntBuffer asReadOnlyBuffer() {
+ IntToByteBufferAdapter buf = new IntToByteBufferAdapter(byteBuffer
+ .asReadOnlyBuffer());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ public IntBuffer compact() {
+ if (byteBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ byteBuffer.limit(limit << 2);
+ byteBuffer.position(position << 2);
+ byteBuffer.compact();
+ byteBuffer.clear();
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ public IntBuffer duplicate() {
+ IntToByteBufferAdapter buf = new IntToByteBufferAdapter(byteBuffer
+ .duplicate());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ public int get() {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return byteBuffer.getInt(position++ << 2);
+ }
+
+ public int get(int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return byteBuffer.getInt(index << 2);
+ }
+
+ public boolean isDirect() {
+ return byteBuffer.isDirect();
+ }
+
+ public boolean isReadOnly() {
+ return byteBuffer.isReadOnly();
+ }
+
+ public ByteOrder order() {
+ return byteBuffer.order();
+ }
+
+ protected int[] protectedArray() {
+ throw new UnsupportedOperationException();
+ }
+
+ protected int protectedArrayOffset() {
+ throw new UnsupportedOperationException();
+ }
+
+ protected boolean protectedHasArray() {
+ return false;
+ }
+
+ public IntBuffer put(int c) {
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ byteBuffer.putInt(position++ << 2, c);
+ return this;
+ }
+
+ public IntBuffer put(int index, int c) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ byteBuffer.putInt(index << 2, c);
+ return this;
+ }
+
+ public IntBuffer slice() {
+ byteBuffer.limit(limit << 2);
+ byteBuffer.position(position << 2);
+ IntBuffer result = new IntToByteBufferAdapter(byteBuffer.slice());
+ byteBuffer.clear();
+ return result;
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/LockManager.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/LockManager.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/LockManager.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/LockManager.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,79 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.channels.FileLock;
+import java.nio.channels.OverlappingFileLockException;
+import java.util.Comparator;
+import java.util.Iterator;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+/**
+ * The lock manager is responsible for tracking acquired and pending locks on
+ * the underlying file channel.
+ *
+ */
+final class LockManager {
+ // The set of acquired and pending locks.
+ private final Comparator lockComparator = new Comparator() {
+ public int compare(Object lock1, Object lock2) {
+ long position1 = ((FileLock) lock1).position();
+ long position2 = ((FileLock) lock2).position();
+ return position1 > position2 ? 1 : (position1 < position2 ? -1 : 0);
+ }
+ };
+
+ private final SortedSet locks = new TreeSet(lockComparator);
+
+ /*
+ * Default Constructor.
+ */
+ protected LockManager() {
+ super();
+ }
+
+ /*
+ * Add a new pending lock to the manager. Thows an exception if the lock
+ * would overlap an existing lock. Once the lock is acquired it remains in
+ * this set as an acquired lock.
+ */
+ synchronized void addLock(FileLock lock)
+ throws OverlappingFileLockException {
+ long lockEnd = lock.position() + lock.size();
+ for (Iterator keyItr = locks.iterator(); keyItr.hasNext();) {
+ FileLock existingLock = (FileLock) keyItr.next();
+ if (existingLock.position() > lockEnd) {
+ // This, and all remaining locks, start beyond our end (so
+ // cannot overlap).
+ break;
+ }
+ if (existingLock.overlaps(lock.position(), lock.size())) {
+ throw new OverlappingFileLockException();
+ }
+ }
+ locks.add(lock);
+ }
+
+ /*
+ * Removes an acquired lock from the lock manager. If the lock did not exist
+ * in the lock manager the operation is a no-op.
+ */
+ synchronized void removeLock(FileLock lock) {
+ locks.remove(lock);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/LongArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/LongArrayBuffer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/LongArrayBuffer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/LongArrayBuffer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,77 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.BufferUnderflowException;
+import java.nio.ByteOrder;
+import java.nio.LongBuffer;
+
+/**
+ * LongArrayBuffer, ReadWriteLongArrayBuffer and ReadOnlyLongArrayBuffer compose
+ * the implementation of array based long buffers.
+ * <p>
+ * LongArrayBuffer implements all the shared readonly methods and is extended by
+ * the other two classes.
+ * </p>
+ * <p>
+ * All methods are marked final for runtime performance.
+ * </p>
+ *
+ */
+abstract class LongArrayBuffer extends LongBuffer {
+
+ protected final long[] backingArray;
+
+ protected final int offset;
+
+ LongArrayBuffer(long[] array) {
+ this(array.length, array, 0);
+ }
+
+ LongArrayBuffer(int capacity) {
+ this(capacity, new long[capacity], 0);
+ }
+
+ LongArrayBuffer(int capacity, long[] backingArray, int offset) {
+ super(capacity);
+ this.backingArray = backingArray;
+ this.offset = offset;
+ }
+
+ public final long get() {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return backingArray[offset + position++];
+ }
+
+ public final long get(int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return backingArray[offset + index];
+ }
+
+ public final boolean isDirect() {
+ return false;
+ }
+
+ public final ByteOrder order() {
+ return ByteOrder.nativeOrder();
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/LongToByteBufferAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/LongToByteBufferAdapter.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/LongToByteBufferAdapter.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/LongToByteBufferAdapter.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,147 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.BufferOverflowException;
+import java.nio.BufferUnderflowException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.LongBuffer;
+import java.nio.ReadOnlyBufferException;
+
+/**
+ * This class wraps a byte buffer to be a long buffer.
+ * <p>
+ * Implementation notice:
+ * <ul>
+ * <li>After a byte buffer instance is wrapped, it becomes privately owned by
+ * the adapter. It must NOT be accessed outside the adapter any more.</li>
+ * <li>The byte buffer's position and limit are NOT linked with the adapter.
+ * The adapter extends Buffer, thus has its own position and limit.</li>
+ * </ul>
+ * </p>
+ *
+ */
+final class LongToByteBufferAdapter extends LongBuffer {
+
+ static LongBuffer wrap(ByteBuffer byteBuffer) {
+ return new LongToByteBufferAdapter(byteBuffer.slice());
+ }
+
+ private final ByteBuffer byteBuffer;
+
+ LongToByteBufferAdapter(ByteBuffer byteBuffer) {
+ super((byteBuffer.capacity() >> 3));
+ this.byteBuffer = byteBuffer;
+ this.byteBuffer.clear();
+ }
+
+ public LongBuffer asReadOnlyBuffer() {
+ LongToByteBufferAdapter buf = new LongToByteBufferAdapter(byteBuffer
+ .asReadOnlyBuffer());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ public LongBuffer compact() {
+ if (byteBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ byteBuffer.limit(limit << 3);
+ byteBuffer.position(position << 3);
+ byteBuffer.compact();
+ byteBuffer.clear();
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ public LongBuffer duplicate() {
+ LongToByteBufferAdapter buf = new LongToByteBufferAdapter(byteBuffer
+ .duplicate());
+ buf.limit = limit;
+ buf.position = position;
+ buf.mark = mark;
+ return buf;
+ }
+
+ public long get() {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return byteBuffer.getLong(position++ << 3);
+ }
+
+ public long get(int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return byteBuffer.getLong(index << 3);
+ }
+
+ public boolean isDirect() {
+ return byteBuffer.isDirect();
+ }
+
+ public boolean isReadOnly() {
+ return byteBuffer.isReadOnly();
+ }
+
+ public ByteOrder order() {
+ return byteBuffer.order();
+ }
+
+ protected long[] protectedArray() {
+ throw new UnsupportedOperationException();
+ }
+
+ protected int protectedArrayOffset() {
+ throw new UnsupportedOperationException();
+ }
+
+ protected boolean protectedHasArray() {
+ return false;
+ }
+
+ public LongBuffer put(long c) {
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ byteBuffer.putLong(position++ << 3, c);
+ return this;
+ }
+
+ public LongBuffer put(int index, long c) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ byteBuffer.putLong(index << 3, c);
+ return this;
+ }
+
+ public LongBuffer slice() {
+ byteBuffer.limit(limit << 3);
+ byteBuffer.position(position << 3);
+ LongBuffer result = new LongToByteBufferAdapter(byteBuffer.slice());
+ byteBuffer.clear();
+ return result;
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/MappedToByteBufferAdapter.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/MappedToByteBufferAdapter.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/MappedToByteBufferAdapter.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/MappedToByteBufferAdapter.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,582 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.io.File;
+import java.nio.BufferOverflowException;
+import java.nio.BufferUnderflowException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.nio.CharBuffer;
+import java.nio.DoubleBuffer;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+import java.nio.LongBuffer;
+import java.nio.MappedByteBuffer;
+import java.nio.ReadOnlyBufferException;
+import java.nio.ShortBuffer;
+import java.nio.channels.FileChannel.MapMode;
+
+/**
+ * Implements MappedByteBuffer by wrapping a ByteBuffer.
+ * <p>
+ * Implementation notice:
+ * <ul>
+ * <li>After a byte buffer instance is wrapped, it becomes privately owned by
+ * the adapter. It must NOT be accessed outside the adapter any more.</li>
+ * <li>The byte buffer's position and limit are NOT linked with the adapter.
+ * The adapter extends Buffer, thus has its own position and limit.</li>
+ * <li>The byte buffer's byte order is linked with the adapter.</li>
+ * </ul>
+ * </p>
+ *
+ */
+final class MappedToByteBufferAdapter extends MappedByteBuffer {
+
+ MappedToByteBufferAdapter(File mappedFile, long offset, int size,
+ MapMode mapMode) {
+ super(mappedFile, offset, size, mapMode);
+ }
+
+ MappedToByteBufferAdapter(File mappedFile, long offset, int size,
+ MapMode mapMode, ByteBuffer wrappedBuffer) {
+ super(mappedFile, offset, size, mapMode, wrappedBuffer);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#asCharBuffer()
+ */
+ public CharBuffer asCharBuffer() {
+ return CharToByteBufferAdapter.wrap(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#asDoubleBuffer()
+ */
+ public DoubleBuffer asDoubleBuffer() {
+ return DoubleToByteBufferAdapter.wrap(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#asFloatBuffer()
+ */
+ public FloatBuffer asFloatBuffer() {
+ return FloatToByteBufferAdapter.wrap(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#asIntBuffer()
+ */
+ public IntBuffer asIntBuffer() {
+ return IntToByteBufferAdapter.wrap(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#asLongBuffer()
+ */
+ public LongBuffer asLongBuffer() {
+ return LongToByteBufferAdapter.wrap(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#asReadOnlyBuffer()
+ */
+ public ByteBuffer asReadOnlyBuffer() {
+ MappedToByteBufferAdapter buf = new MappedToByteBufferAdapter(
+ mappedFile, offset, capacity, mapMode, wrappedBuffer
+ .asReadOnlyBuffer());
+ buf.position = position;
+ buf.limit = limit;
+ buf.mark = mark;
+ buf.order = order;
+ return buf;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#asShortBuffer()
+ */
+ public ShortBuffer asShortBuffer() {
+ return ShortToByteBufferAdapter.wrap(this);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#compact()
+ */
+ public ByteBuffer compact() {
+ if (mapMode == MapMode.READ_ONLY || wrappedBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ wrappedBuffer.limit(limit);
+ wrappedBuffer.position(position);
+ wrappedBuffer.compact();
+ wrappedBuffer.clear();
+ position = limit - position;
+ limit = capacity;
+ mark = UNSET_MARK;
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#duplicate()
+ */
+ public ByteBuffer duplicate() {
+ MappedToByteBufferAdapter buf = new MappedToByteBufferAdapter(
+ mappedFile, offset, capacity, mapMode, wrappedBuffer
+ .duplicate());
+ buf.position = position;
+ buf.limit = limit;
+ buf.mark = mark;
+ buf.order = order;
+ return buf;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#get()
+ */
+ public byte get() {
+ if (position == limit) {
+ throw new BufferUnderflowException();
+ }
+ return wrappedBuffer.get(position++);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#get(int)
+ */
+ public byte get(int index) {
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return wrappedBuffer.get(index);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#getChar()
+ */
+ public char getChar() {
+ return (char) getShort();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#getChar(int)
+ */
+ public char getChar(int index) {
+ return (char) getShort(index);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#getDouble()
+ */
+ public double getDouble() {
+ return Double.longBitsToDouble(getLong());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#getDouble(int)
+ */
+ public double getDouble(int index) {
+ return Double.longBitsToDouble(getLong(index));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#getFloat()
+ */
+ public float getFloat() {
+ return Float.intBitsToFloat(getInt());
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#getFloat(int)
+ */
+ public float getFloat(int index) {
+ return Float.intBitsToFloat(getInt(index));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#getInt()
+ */
+ public int getInt() {
+ int newPosition = position + 4;
+ if (newPosition > limit) {
+ throw new BufferUnderflowException();
+ }
+ int result = wrappedBuffer.getInt(position);
+ position = newPosition;
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#getInt(int)
+ */
+ public int getInt(int index) {
+ if (index < 0 || index + 4 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return wrappedBuffer.getInt(index);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#getLong()
+ */
+ public long getLong() {
+ int newPosition = position + 8;
+ if (newPosition > limit) {
+ throw new BufferUnderflowException();
+ }
+ long result = wrappedBuffer.getLong(position);
+ position = newPosition;
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#getLong(int)
+ */
+ public long getLong(int index) {
+ if (index < 0 || index + 8 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return wrappedBuffer.getLong(index);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#getShort()
+ */
+ public short getShort() {
+ int newPosition = position + 2;
+ if (newPosition > limit) {
+ throw new BufferUnderflowException();
+ }
+ short result = wrappedBuffer.getShort(position);
+ position = newPosition;
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#getShort(int)
+ */
+ public short getShort(int index) {
+ if (index < 0 || index + 2 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ return wrappedBuffer.getShort(index);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#isDirect()
+ */
+ public boolean isDirect() {
+ return true;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.Buffer#isReadOnly()
+ */
+ public boolean isReadOnly() {
+ return mapMode == MapMode.READ_ONLY || wrappedBuffer.isReadOnly();
+ }
+
+ /*
+ * Override to keep this.order linked with wrappedBuffer.order
+ */
+ public ByteBuffer order(ByteOrder byteOrder) {
+ super.order(byteOrder);
+ wrappedBuffer.order(byteOrder);
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#protectedArray()
+ */
+ protected byte[] protectedArray() {
+ throw new UnsupportedOperationException();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#protectedArrayOffset()
+ */
+ protected int protectedArrayOffset() {
+ throw new UnsupportedOperationException();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#protectedHasArray()
+ */
+ protected boolean protectedHasArray() {
+ return false;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#put(byte)
+ */
+ public ByteBuffer put(byte b) {
+ if (mapMode == MapMode.READ_ONLY || wrappedBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ if (position == limit) {
+ throw new BufferOverflowException();
+ }
+ wrappedBuffer.put(position++, b);
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#put(int, byte)
+ */
+ public ByteBuffer put(int index, byte b) {
+ if (mapMode == MapMode.READ_ONLY || wrappedBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ if (index < 0 || index >= limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ wrappedBuffer.put(index, b);
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#putChar(char)
+ */
+ public ByteBuffer putChar(char value) {
+ return putShort((short) value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#putChar(int, char)
+ */
+ public ByteBuffer putChar(int index, char value) {
+ return putShort(index, (short) value);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#putDouble(double)
+ */
+ public ByteBuffer putDouble(double value) {
+ return putLong(Double.doubleToRawLongBits(value));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#putDouble(int, double)
+ */
+ public ByteBuffer putDouble(int index, double value) {
+ return putLong(index, Double.doubleToRawLongBits(value));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#putFloat(float)
+ */
+ public ByteBuffer putFloat(float value) {
+ return putInt(Float.floatToIntBits(value));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#putFloat(int, float)
+ */
+ public ByteBuffer putFloat(int index, float value) {
+ return putInt(index, Float.floatToIntBits(value));
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#putInt(int)
+ */
+ public ByteBuffer putInt(int value) {
+ if (mapMode == MapMode.READ_ONLY || wrappedBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ int newPosition = position + 4;
+ if (newPosition > limit) {
+ throw new BufferOverflowException();
+ }
+ wrappedBuffer.putInt(position, value);
+ position = newPosition;
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#putInt(int, int)
+ */
+ public ByteBuffer putInt(int index, int value) {
+ if (mapMode == MapMode.READ_ONLY || wrappedBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ if (index < 0 || index + 4 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ wrappedBuffer.putInt(index, value);
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#putLong(int, long)
+ */
+ public ByteBuffer putLong(int index, long value) {
+ if (mapMode == MapMode.READ_ONLY || wrappedBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ if (index < 0 || index + 8 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ wrappedBuffer.putLong(index, value);
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#putLong(long)
+ */
+ public ByteBuffer putLong(long value) {
+ if (mapMode == MapMode.READ_ONLY || wrappedBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ int newPosition = position + 8;
+ if (newPosition > limit) {
+ throw new BufferOverflowException();
+ }
+ wrappedBuffer.putLong(position, value);
+ position = newPosition;
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#putShort(int, short)
+ */
+ public ByteBuffer putShort(int index, short value) {
+ if (mapMode == MapMode.READ_ONLY || wrappedBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ if (index < 0 || index + 2 > limit) {
+ throw new IndexOutOfBoundsException();
+ }
+ wrappedBuffer.putShort(index, value);
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#putShort(short)
+ */
+ public ByteBuffer putShort(short value) {
+ if (mapMode == MapMode.READ_ONLY || wrappedBuffer.isReadOnly()) {
+ throw new ReadOnlyBufferException();
+ }
+ int newPosition = position + 2;
+ if (newPosition > limit) {
+ throw new BufferOverflowException();
+ }
+ wrappedBuffer.putShort(position, value);
+ position = newPosition;
+ return this;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see java.nio.ByteBuffer#slice()
+ */
+ public ByteBuffer slice() {
+ wrappedBuffer.limit(limit);
+ wrappedBuffer.position(position);
+ MappedToByteBufferAdapter result = new MappedToByteBufferAdapter(
+ mappedFile, offset + position, remaining(), mapMode,
+ wrappedBuffer.slice());
+ wrappedBuffer.clear();
+ result.order = order;
+ return result;
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyCharArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyCharArrayBuffer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyCharArrayBuffer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyCharArrayBuffer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,90 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.CharBuffer;
+import java.nio.ReadOnlyBufferException;
+
+/**
+ * CharArrayBuffer, ReadWriteCharArrayBuffer and ReadOnlyCharArrayBuffer compose
+ * the implementation of array based char buffers.
+ * <p>
+ * ReadOnlyCharArrayBuffer extends CharArrayBuffer with all the write methods
+ * throwing read only exception.
+ * </p>
+ * <p>
+ * This class is marked final for runtime performance.
+ * </p>
+ *
+ */
+final class ReadOnlyCharArrayBuffer extends CharArrayBuffer {
+
+ static ReadOnlyCharArrayBuffer copy(CharArrayBuffer other, int markOfOther) {
+ ReadOnlyCharArrayBuffer buf = new ReadOnlyCharArrayBuffer(other
+ .capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadOnlyCharArrayBuffer(int capacity, char[] backingArray, int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public CharBuffer asReadOnlyBuffer() {
+ return duplicate();
+ }
+
+ public CharBuffer compact() {
+ throw new ReadOnlyBufferException();
+ }
+
+ public CharBuffer duplicate() {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ protected char[] protectedArray() {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected int protectedArrayOffset() {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected boolean protectedHasArray() {
+ return false;
+ }
+
+ public CharBuffer put(char c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public CharBuffer put(int index, char c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public CharBuffer slice() {
+ return new ReadOnlyCharArrayBuffer(remaining(), backingArray, offset
+ + position);
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyDirectByteBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyDirectByteBuffer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyDirectByteBuffer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyDirectByteBuffer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,134 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.ByteBuffer;
+import java.nio.ReadOnlyBufferException;
+
+/**
+ * DirectByteBuffer, ReadWriteDirectByteBuffer and ReadOnlyDirectByteBuffer
+ * compose the implementation of platform memory based byte buffers.
+ * <p>
+ * ReadOnlyDirectByteBuffer extends DirectByteBuffer with all the write methods
+ * throwing read only exception.
+ * </p>
+ * <p>
+ * This class is marked final for runtime performance.
+ * </p>
+ *
+ */
+final class ReadOnlyDirectByteBuffer extends DirectByteBuffer {
+
+ static ReadOnlyDirectByteBuffer copy(DirectByteBuffer other, int markOfOther) {
+ ReadOnlyDirectByteBuffer buf = new ReadOnlyDirectByteBuffer(
+ other.safeAddress, other.capacity(), other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ buf.order(other.order());
+ return buf;
+ }
+
+ protected ReadOnlyDirectByteBuffer(SafeAddress address, int capacity,
+ int offset) {
+ super(address, capacity, offset);
+ }
+
+ public ByteBuffer asReadOnlyBuffer() {
+ return copy(this, mark);
+ }
+
+ public ByteBuffer compact() {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer duplicate() {
+ return copy(this, mark);
+ }
+
+ protected byte[] protectedArray() {
+ throw new UnsupportedOperationException();
+ }
+
+ protected int protectedArrayOffset() {
+ throw new UnsupportedOperationException();
+ }
+
+ protected boolean protectedHasArray() {
+ return false;
+ }
+
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ public ByteBuffer put(byte value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer put(int index, byte value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putDouble(double value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putDouble(int index, double value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putFloat(float value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putFloat(int index, float value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putInt(int value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putInt(int index, int value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putLong(int index, long value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putLong(long value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putShort(int index, short value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putShort(short value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer slice() {
+ ReadOnlyDirectByteBuffer buf = new ReadOnlyDirectByteBuffer(
+ safeAddress, remaining(), offset + position);
+ buf.order = order;
+ return buf;
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyDoubleArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyDoubleArrayBuffer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyDoubleArrayBuffer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyDoubleArrayBuffer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,92 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.DoubleBuffer;
+import java.nio.ReadOnlyBufferException;
+
+/**
+ * DoubleArrayBuffer, ReadWriteDoubleArrayBuffer and ReadOnlyDoubleArrayBuffer
+ * compose the implementation of array based double buffers.
+ * <p>
+ * ReadOnlyDoubleArrayBuffer extends DoubleArrayBuffer with all the write
+ * methods throwing read only exception.
+ * </p>
+ * <p>
+ * This class is marked final for runtime performance.
+ * </p>
+ *
+ */
+final class ReadOnlyDoubleArrayBuffer extends DoubleArrayBuffer {
+
+ static ReadOnlyDoubleArrayBuffer copy(DoubleArrayBuffer other,
+ int markOfOther) {
+ ReadOnlyDoubleArrayBuffer buf = new ReadOnlyDoubleArrayBuffer(other
+ .capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadOnlyDoubleArrayBuffer(int capacity, double[] backingArray,
+ int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public DoubleBuffer asReadOnlyBuffer() {
+ return duplicate();
+ }
+
+ public DoubleBuffer compact() {
+ throw new ReadOnlyBufferException();
+ }
+
+ public DoubleBuffer duplicate() {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ protected double[] protectedArray() {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected int protectedArrayOffset() {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected boolean protectedHasArray() {
+ return false;
+ }
+
+ public DoubleBuffer put(double c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public DoubleBuffer put(int index, double c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public DoubleBuffer slice() {
+ return new ReadOnlyDoubleArrayBuffer(remaining(), backingArray, offset
+ + position);
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyFloatArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyFloatArrayBuffer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyFloatArrayBuffer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyFloatArrayBuffer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,90 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.FloatBuffer;
+import java.nio.ReadOnlyBufferException;
+
+/**
+ * FloatArrayBuffer, ReadWriteFloatArrayBuffer and ReadOnlyFloatArrayBuffer
+ * compose the implementation of array based float buffers.
+ * <p>
+ * ReadOnlyFloatArrayBuffer extends FloatArrayBuffer with all the write methods
+ * throwing read only exception.
+ * </p>
+ * <p>
+ * This class is marked final for runtime performance.
+ * </p>
+ *
+ */
+final class ReadOnlyFloatArrayBuffer extends FloatArrayBuffer {
+
+ static ReadOnlyFloatArrayBuffer copy(FloatArrayBuffer other, int markOfOther) {
+ ReadOnlyFloatArrayBuffer buf = new ReadOnlyFloatArrayBuffer(other
+ .capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadOnlyFloatArrayBuffer(int capacity, float[] backingArray, int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public FloatBuffer asReadOnlyBuffer() {
+ return duplicate();
+ }
+
+ public FloatBuffer compact() {
+ throw new ReadOnlyBufferException();
+ }
+
+ public FloatBuffer duplicate() {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ protected float[] protectedArray() {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected int protectedArrayOffset() {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected boolean protectedHasArray() {
+ return false;
+ }
+
+ public FloatBuffer put(float c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public FloatBuffer put(int index, float c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public FloatBuffer slice() {
+ return new ReadOnlyFloatArrayBuffer(remaining(), backingArray, offset
+ + position);
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyHeapByteBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyHeapByteBuffer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyHeapByteBuffer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyHeapByteBuffer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,132 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.ByteBuffer;
+import java.nio.ReadOnlyBufferException;
+
+/**
+ * HeapByteBuffer, ReadWriteHeapByteBuffer and ReadOnlyHeapByteBuffer compose
+ * the implementation of array based byte buffers.
+ * <p>
+ * ReadOnlyHeapByteBuffer extends HeapByteBuffer with all the write methods
+ * throwing read only exception.
+ * </p>
+ * <p>
+ * This class is marked final for runtime performance.
+ * </p>
+ *
+ */
+final class ReadOnlyHeapByteBuffer extends HeapByteBuffer {
+
+ static ReadOnlyHeapByteBuffer copy(HeapByteBuffer other, int markOfOther) {
+ ReadOnlyHeapByteBuffer buf = new ReadOnlyHeapByteBuffer(
+ other.backingArray, other.capacity(), other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ buf.order(other.order());
+ return buf;
+ }
+
+ ReadOnlyHeapByteBuffer(byte[] backingArray, int capacity, int arrayOffset) {
+ super(backingArray, capacity, arrayOffset);
+ }
+
+ public ByteBuffer asReadOnlyBuffer() {
+ return copy(this, mark);
+ }
+
+ public ByteBuffer compact() {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer duplicate() {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ protected byte[] protectedArray() {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected int protectedArrayOffset() {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected boolean protectedHasArray() {
+ return false;
+ }
+
+ public ByteBuffer put(byte b) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer put(int index, byte b) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putDouble(double value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putDouble(int index, double value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putFloat(float value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putFloat(int index, float value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putInt(int value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putInt(int index, int value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putLong(int index, long value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putLong(long value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putShort(int index, short value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer putShort(short value) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ByteBuffer slice() {
+ ReadOnlyHeapByteBuffer slice = new ReadOnlyHeapByteBuffer(backingArray,
+ remaining(), offset + position);
+ slice.order = order;
+ return slice;
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyIntArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyIntArrayBuffer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyIntArrayBuffer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyIntArrayBuffer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,90 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.IntBuffer;
+import java.nio.ReadOnlyBufferException;
+
+/**
+ * IntArrayBuffer, ReadWriteIntArrayBuffer and ReadOnlyIntArrayBuffer compose
+ * the implementation of array based int buffers.
+ * <p>
+ * ReadOnlyIntArrayBuffer extends IntArrayBuffer with all the write methods
+ * throwing read only exception.
+ * </p>
+ * <p>
+ * This class is marked final for runtime performance.
+ * </p>
+ *
+ */
+final class ReadOnlyIntArrayBuffer extends IntArrayBuffer {
+
+ static ReadOnlyIntArrayBuffer copy(IntArrayBuffer other, int markOfOther) {
+ ReadOnlyIntArrayBuffer buf = new ReadOnlyIntArrayBuffer(other
+ .capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadOnlyIntArrayBuffer(int capacity, int[] backingArray, int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public IntBuffer asReadOnlyBuffer() {
+ return duplicate();
+ }
+
+ public IntBuffer compact() {
+ throw new ReadOnlyBufferException();
+ }
+
+ public IntBuffer duplicate() {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ protected int[] protectedArray() {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected int protectedArrayOffset() {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected boolean protectedHasArray() {
+ return false;
+ }
+
+ public IntBuffer put(int c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public IntBuffer put(int index, int c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public IntBuffer slice() {
+ return new ReadOnlyIntArrayBuffer(remaining(), backingArray, offset
+ + position);
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyLongArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyLongArrayBuffer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyLongArrayBuffer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyLongArrayBuffer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,90 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.LongBuffer;
+import java.nio.ReadOnlyBufferException;
+
+/**
+ * LongArrayBuffer, ReadWriteLongArrayBuffer and ReadOnlyLongArrayBuffer compose
+ * the implementation of array based long buffers.
+ * <p>
+ * ReadOnlyLongArrayBuffer extends LongArrayBuffer with all the write methods
+ * throwing read only exception.
+ * </p>
+ * <p>
+ * This class is marked final for runtime performance.
+ * </p>
+ *
+ */
+final class ReadOnlyLongArrayBuffer extends LongArrayBuffer {
+
+ static ReadOnlyLongArrayBuffer copy(LongArrayBuffer other, int markOfOther) {
+ ReadOnlyLongArrayBuffer buf = new ReadOnlyLongArrayBuffer(other
+ .capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadOnlyLongArrayBuffer(int capacity, long[] backingArray, int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public LongBuffer asReadOnlyBuffer() {
+ return duplicate();
+ }
+
+ public LongBuffer compact() {
+ throw new ReadOnlyBufferException();
+ }
+
+ public LongBuffer duplicate() {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ protected long[] protectedArray() {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected int protectedArrayOffset() {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected boolean protectedHasArray() {
+ return false;
+ }
+
+ public LongBuffer put(long c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public LongBuffer put(int index, long c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public LongBuffer slice() {
+ return new ReadOnlyLongArrayBuffer(remaining(), backingArray, offset
+ + position);
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyShortArrayBuffer.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyShortArrayBuffer.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyShortArrayBuffer.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/com/ibm/io/nio/ReadOnlyShortArrayBuffer.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,90 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.ibm.io.nio;
+
+
+import java.nio.ReadOnlyBufferException;
+import java.nio.ShortBuffer;
+
+/**
+ * ShortArrayBuffer, ReadWriteShortArrayBuffer and ReadOnlyShortArrayBuffer
+ * compose the implementation of array based short buffers.
+ * <p>
+ * ReadOnlyShortArrayBuffer extends ShortArrayBuffer with all the write methods
+ * throwing read only exception.
+ * </p>
+ * <p>
+ * This class is marked final for runtime performance.
+ * </p>
+ *
+ */
+final class ReadOnlyShortArrayBuffer extends ShortArrayBuffer {
+
+ static ReadOnlyShortArrayBuffer copy(ShortArrayBuffer other, int markOfOther) {
+ ReadOnlyShortArrayBuffer buf = new ReadOnlyShortArrayBuffer(other
+ .capacity(), other.backingArray, other.offset);
+ buf.limit = other.limit();
+ buf.position = other.position();
+ buf.mark = markOfOther;
+ return buf;
+ }
+
+ ReadOnlyShortArrayBuffer(int capacity, short[] backingArray, int arrayOffset) {
+ super(capacity, backingArray, arrayOffset);
+ }
+
+ public ShortBuffer asReadOnlyBuffer() {
+ return duplicate();
+ }
+
+ public ShortBuffer compact() {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ShortBuffer duplicate() {
+ return copy(this, mark);
+ }
+
+ public boolean isReadOnly() {
+ return true;
+ }
+
+ protected short[] protectedArray() {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected int protectedArrayOffset() {
+ throw new ReadOnlyBufferException();
+ }
+
+ protected boolean protectedHasArray() {
+ return false;
+ }
+
+ public ShortBuffer put(short c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ShortBuffer put(int index, short c) {
+ throw new ReadOnlyBufferException();
+ }
+
+ public ShortBuffer slice() {
+ return new ReadOnlyShortArrayBuffer(remaining(), backingArray, offset
+ + position);
+ }
+
+}