This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: New NIO code needs refactoring
Could you try this patch?
--
--Per Bothner
per@bothner.com http://per.bothner.com/
2004-03-17 Per Bothner <per@bothner.com>
* java/nio/CharViewBufferImpl.java: Moved to gnu.java.nio.
* java/nio/DoubleViewBufferImpl.java: Likewise.
* java/nio/FloatViewBufferImpl.java: Likewise.
* java/nio/IntViewBufferImpl.java: Likewise.
* java/nio/LongViewBufferImpl.java: Likewise.
* java/nio/MappedByteBufferImpl.java: Likewise.
* java/nio/ShortViewBufferImpl.java: Likewise.
* java/nio/DirectByteBufferImpl.java: Likewise.
* java/nio/natDirectByteBufferImpl.cc: Likewise.
* gnu/java/nio/ByteBufferHelper.java: Renamed class. Made public.
* gnu/java/nio/CharViewBufferImpl.java: Likewise.
* gnu/java/nio/DirectByteBufferImpl.java: Likewise.
* gnu/java/nio/DoubleViewBufferImpl.java: Likewise.
* gnu/java/nio/FloatViewBufferImpl.java: Likewise.
* gnu/java/nio/IntViewBufferImpl.java: Likewise.
* gnu/java/nio/LongViewBufferImpl.java: Likewise.
* gnu/java/nio/MappedByteBufferImpl.java: Likewise.
* gnu/java/nio/ShortViewBufferImpl.java: Likewise.
* gnu/java/nio/natDirectByteBufferImpl.cc: Likewise.
* Makefile.am: Update accordingly.
* jni.cc: Update for renamed classes.
* gnu/java/nio/channels/natFileChannelEcos.cc: Likewise.
* gnu/java/nio/channels/natFileChannelPosix.cc: Likewise.
* gnu/java/nio/channels/natFileChannelWin32.cc: Likewise.
* java/nio/ByteBuffer.java: Likewise, by importing gnu.java.nio.*.
* java/nio/ByteBufferImpl.java: Likewise.
* gnu/java/nio/channels/natFileChannelEcos.cc (diag_write): Restored.
(write): Call diag_write, as in old natFileDescriptorEcos.cc.
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.365
diff -u -p -r1.365 Makefile.am
--- Makefile.am 9 Mar 2004 19:14:22 -0000 1.365
+++ Makefile.am 18 Mar 2004 00:10:20 -0000
@@ -2350,8 +2352,10 @@ gnu/java/net/protocol/jar/Connection.jav
gnu/java/net/protocol/jar/Handler.java \
gnu/java/net/protocol/gcjlib/Connection.java \
gnu/java/net/protocol/gcjlib/Handler.java \
+gnu/java/nio/ByteBufferHelper.java \
gnu/java/nio/DatagramChannelImpl.java \
gnu/java/nio/DatagramChannelSelectionKey.java \
+gnu/java/nio/DirectByteBufferImpl.java \
gnu/java/nio/FileLockImpl.java \
gnu/java/nio/NIOConstants.java \
gnu/java/nio/NIODatagramSocket.java \
@@ -2359,7 +2363,13 @@ gnu/java/nio/NIOServerSocket.java \
gnu/java/nio/NIOSocket.java \
gnu/java/nio/ChannelInputStream.java \
gnu/java/nio/ChannelOutputStream.java \
+gnu/java/nio/CharViewBufferImpl.java \
+gnu/java/nio/DoubleViewBufferImpl.java \
+gnu/java/nio/FloatViewBufferImpl.java \
gnu/java/nio/InputStreamChannel.java \
+gnu/java/nio/IntViewBufferImpl.java \
+gnu/java/nio/LongViewBufferImpl.java \
+gnu/java/nio/MappedByteBufferImpl.java \
gnu/java/nio/OutputStreamChannel.java \
gnu/java/nio/PipeImpl.java \
gnu/java/nio/SelectionKeyImpl.java \
@@ -2367,6 +2377,7 @@ gnu/java/nio/SelectorImpl.java \
gnu/java/nio/SelectorProviderImpl.java \
gnu/java/nio/ServerSocketChannelImpl.java \
gnu/java/nio/ServerSocketChannelSelectionKey.java \
+gnu/java/nio/ShortViewBufferImpl.java \
gnu/java/nio/SocketChannelImpl.java \
gnu/java/nio/SocketChannelSelectionKey.java \
gnu/java/nio/channels/FileChannelImpl.java \
@@ -2379,33 +2390,6 @@ gnu/java/nio/charset/UTF_16Decoder.java
gnu/java/nio/charset/UTF_16Encoder.java \
gnu/java/nio/charset/UTF_16LE.java \
gnu/java/nio/charset/UTF_8.java \
-gnu/regexp/CharIndexed.java \
-gnu/regexp/CharIndexedCharArray.java \
-gnu/regexp/CharIndexedInputStream.java \
-gnu/regexp/CharIndexedReader.java \
-gnu/regexp/CharIndexedString.java \
-gnu/regexp/CharIndexedStringBuffer.java \
-gnu/regexp/RE.java \
-gnu/regexp/REException.java \
-gnu/regexp/REFilterInputStream.java \
-gnu/regexp/REFilterReader.java \
-gnu/regexp/REMatch.java \
-gnu/regexp/REMatchEnumeration.java \
-gnu/regexp/RESyntax.java \
-gnu/regexp/REToken.java \
-gnu/regexp/RETokenAny.java \
-gnu/regexp/RETokenBackRef.java \
-gnu/regexp/RETokenChar.java \
-gnu/regexp/RETokenEnd.java \
-gnu/regexp/RETokenEndSub.java \
-gnu/regexp/RETokenLookAhead.java \
-gnu/regexp/RETokenOneOf.java \
-gnu/regexp/RETokenPOSIX.java \
-gnu/regexp/RETokenRange.java \
-gnu/regexp/RETokenRepeated.java \
-gnu/regexp/RETokenStart.java \
-gnu/regexp/RETokenWordBoundary.java \
-gnu/regexp/UncheckedRE.java \
gnu/java/security/Engine.java \
gnu/java/security/OID.java \
gnu/java/security/der/BitString.java \
@@ -2444,6 +2428,33 @@ gnu/java/util/prefs/NodeReader.java \
gnu/java/util/prefs/MemoryBasedPreferences.java \
gnu/java/util/prefs/FileBasedFactory.java \
gnu/java/util/prefs/NodeWriter.java \
+gnu/regexp/CharIndexed.java \
+gnu/regexp/CharIndexedCharArray.java \
+gnu/regexp/CharIndexedInputStream.java \
+gnu/regexp/CharIndexedReader.java \
+gnu/regexp/CharIndexedString.java \
+gnu/regexp/CharIndexedStringBuffer.java \
+gnu/regexp/RE.java \
+gnu/regexp/REException.java \
+gnu/regexp/REFilterInputStream.java \
+gnu/regexp/REFilterReader.java \
+gnu/regexp/REMatch.java \
+gnu/regexp/REMatchEnumeration.java \
+gnu/regexp/RESyntax.java \
+gnu/regexp/REToken.java \
+gnu/regexp/RETokenAny.java \
+gnu/regexp/RETokenBackRef.java \
+gnu/regexp/RETokenChar.java \
+gnu/regexp/RETokenEnd.java \
+gnu/regexp/RETokenEndSub.java \
+gnu/regexp/RETokenLookAhead.java \
+gnu/regexp/RETokenOneOf.java \
+gnu/regexp/RETokenPOSIX.java \
+gnu/regexp/RETokenRange.java \
+gnu/regexp/RETokenRepeated.java \
+gnu/regexp/RETokenStart.java \
+gnu/regexp/RETokenWordBoundary.java \
+gnu/regexp/UncheckedRE.java \
java/lang/ref/PhantomReference.java \
java/lang/ref/Reference.java \
java/lang/ref/ReferenceQueue.java \
@@ -2511,32 +2522,23 @@ java/nio/Buffer.java \
java/nio/BufferOverflowException.java \
java/nio/BufferUnderflowException.java \
java/nio/ByteBuffer.java \
-java/nio/ByteBufferHelper.java \
java/nio/ByteBufferImpl.java \
java/nio/ByteOrder.java \
java/nio/CharBuffer.java \
java/nio/CharBufferImpl.java \
-java/nio/CharViewBufferImpl.java \
-java/nio/DirectByteBufferImpl.java \
java/nio/DoubleBuffer.java \
java/nio/DoubleBufferImpl.java \
-java/nio/DoubleViewBufferImpl.java \
java/nio/FloatBuffer.java \
java/nio/FloatBufferImpl.java \
-java/nio/FloatViewBufferImpl.java \
java/nio/IntBuffer.java \
java/nio/IntBufferImpl.java \
-java/nio/IntViewBufferImpl.java \
java/nio/InvalidMarkException.java \
java/nio/LongBuffer.java \
java/nio/LongBufferImpl.java \
-java/nio/LongViewBufferImpl.java \
java/nio/MappedByteBuffer.java \
-java/nio/MappedByteBufferImpl.java \
java/nio/ReadOnlyBufferException.java \
java/nio/ShortBuffer.java \
java/nio/ShortBufferImpl.java \
-java/nio/ShortViewBufferImpl.java \
java/nio/channels/AlreadyConnectedException.java \
java/nio/channels/AsynchronousCloseException.java \
java/nio/channels/ByteChannel.java \
@@ -2860,6 +2862,7 @@ gnu/java/awt/natEmbeddedWindow.cc \
gnu/java/net/natPlainDatagramSocketImpl.cc \
gnu/java/net/natPlainSocketImpl.cc \
gnu/java/net/protocol/core/natCoreInputStream.cc \
+gnu/java/nio/natDirectByteBufferImpl.cc \
gnu/java/nio/natPipeImpl.cc \
gnu/java/nio/natSelectorImpl.cc \
gnu/java/nio/natNIOServerSocket.cc \
@@ -2891,7 +2894,6 @@ java/lang/reflect/natProxy.cc \
java/net/natNetworkInterface.cc \
java/net/natInetAddress.cc \
java/nio/channels/natChannels.cc \
-java/nio/natDirectByteBufferImpl.cc \
java/text/natCollator.cc \
java/util/natResourceBundle.cc \
java/util/natTimeZone.cc \
Index: jni.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/jni.cc,v
retrieving revision 1.81
diff -u -p -r1.81 jni.cc
--- jni.cc 1 Feb 2004 20:05:02 -0000 1.81
+++ jni.cc 18 Mar 2004 00:10:22 -0000
@@ -39,7 +39,7 @@ details. */
#include <java/lang/ThreadGroup.h>
#include <java/lang/Thread.h>
#include <java/lang/IllegalAccessError.h>
-#include <java/nio/DirectByteBufferImpl.h>
+#include <gnu/java/nio/DirectByteBufferImpl.h>
#include <java/util/IdentityHashMap.h>
#include <gnu/gcj/RawData.h>
@@ -1717,7 +1717,7 @@ static jobject
(JNICALL _Jv_JNI_NewDirectByteBuffer) (JNIEnv *, void *address, jlong length)
{
using namespace gnu::gcj;
- using namespace java::nio;
+ using namespace gnu::java::nio;
return new DirectByteBufferImpl (reinterpret_cast<RawData *> (address),
length);
}
@@ -1725,7 +1725,7 @@ static jobject
static void *
(JNICALL _Jv_JNI_GetDirectBufferAddress) (JNIEnv *, jobject buffer)
{
- using namespace java::nio;
+ using namespace gnu::java::nio;
DirectByteBufferImpl* bb = static_cast<DirectByteBufferImpl *> (buffer);
return reinterpret_cast<void *> (bb->address);
}
@@ -1733,7 +1733,7 @@ static void *
static jlong
(JNICALL _Jv_JNI_GetDirectBufferCapacity) (JNIEnv *, jobject buffer)
{
- using namespace java::nio;
+ using namespace gnu::java::nio;
DirectByteBufferImpl* bb = static_cast<DirectByteBufferImpl *> (buffer);
return bb->capacity();
}
Index: gnu/java/nio/ByteBufferHelper.java
===================================================================
RCS file: gnu/java/nio/ByteBufferHelper.java
diff -N gnu/java/nio/ByteBufferHelper.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/java/nio/ByteBufferHelper.java 18 Mar 2004 00:10:22 -0000
@@ -0,0 +1,382 @@
+/* ByteBufferImpl.java --
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.nio;
+import java.nio.*;
+
+/**
+ * @author Michael Koch <konqueror@gmx.de>
+ */
+public final class ByteBufferHelper
+{
+ private static void checkRemainingForRead (ByteBuffer buffer, int bytes)
+ {
+ if (buffer.remaining() < bytes)
+ throw new BufferUnderflowException();
+ }
+
+ private static void checkRemainingForWrite (ByteBuffer buffer, int bytes)
+ {
+ if (buffer.remaining() < bytes)
+ throw new BufferOverflowException();
+ }
+
+ private static void checkAvailableForRead (ByteBuffer buffer,
+ int index, int bytes)
+ {
+ if (buffer.limit() < (index + bytes))
+ throw new BufferUnderflowException();
+ }
+
+ private static void checkAvailableForWrite (ByteBuffer buffer,
+ int index, int bytes)
+ {
+ if (buffer.limit() < (index + bytes))
+ throw new BufferOverflowException();
+ }
+
+ public static char getChar (ByteBuffer buffer, ByteOrder order)
+ {
+ return (char) getShort (buffer, order);
+ }
+
+ public static void putChar (ByteBuffer buffer, char value, ByteOrder order)
+ {
+ putShort (buffer, (short) value, order);
+ }
+
+ public static char getChar (ByteBuffer buffer, int index, ByteOrder order)
+ {
+ return (char) getShort (buffer, index, order);
+ }
+
+ public static void putChar (ByteBuffer buffer, int index,
+ char value, ByteOrder order)
+ {
+ putShort (buffer, index, (short) value, order);
+ }
+
+ public static short getShort (ByteBuffer buffer, ByteOrder order)
+ {
+ checkRemainingForRead (buffer, 2);
+
+ if (order == ByteOrder.LITTLE_ENDIAN)
+ {
+ return (short) ((buffer.get() & 0xff)
+ + (buffer.get() << 8));
+ }
+
+ return (short) ((buffer.get() << 8)
+ + (buffer.get() & 0xff));
+ }
+
+ public static void putShort (ByteBuffer buffer, short value, ByteOrder order)
+ {
+ checkRemainingForWrite (buffer, 2);
+
+ if (order == ByteOrder.LITTLE_ENDIAN)
+ {
+ buffer.put ((byte) value);
+ buffer.put ((byte) (value >> 8));
+ }
+ else
+ {
+ buffer.put ((byte) (value >> 8));
+ buffer.put ((byte) value);
+ }
+ }
+
+ public static short getShort (ByteBuffer buffer,
+ int index, ByteOrder order)
+ {
+ checkAvailableForRead (buffer, index, 2);
+
+ if (order == ByteOrder.LITTLE_ENDIAN)
+ {
+ return (short) ((buffer.get (index) & 0xff)
+ + (buffer.get (++index) << 8));
+ }
+
+ return (short) ((buffer.get (index) << 8)
+ + (buffer.get (++index) & 0xff));
+ }
+
+ public static void putShort (ByteBuffer buffer, int index,
+ short value, ByteOrder order)
+ {
+ checkAvailableForWrite (buffer, index, 2);
+
+ if (order == ByteOrder.LITTLE_ENDIAN)
+ {
+ buffer.put (index, (byte) value);
+ buffer.put (++index, (byte) (value >> 8));
+ }
+ else
+ {
+ buffer.put (index, (byte) (value >> 8));
+ buffer.put (++index, (byte) value);
+ }
+ }
+
+ public static int getInt (ByteBuffer buffer, ByteOrder order)
+ {
+ checkRemainingForRead (buffer, 4);
+
+ if (order == ByteOrder.LITTLE_ENDIAN)
+ {
+ return ((buffer.get() & 0xff)
+ + ((buffer.get() & 0xff) << 8)
+ + ((buffer.get() & 0xff) << 16)
+ + (buffer.get() << 24));
+ }
+
+ return (int) ((buffer.get() << 24)
+ + ((buffer.get() & 0xff) << 16)
+ + ((buffer.get() & 0xff) << 8)
+ + (buffer.get() & 0xff));
+ }
+
+ public static void putInt (ByteBuffer buffer, int value, ByteOrder order)
+ {
+ checkRemainingForWrite (buffer, 4);
+
+ if (order == ByteOrder.LITTLE_ENDIAN)
+ {
+ buffer.put ((byte) value);
+ buffer.put ((byte) (value >> 8));
+ buffer.put ((byte) (value >> 16));
+ buffer.put ((byte) (value >> 24));
+ }
+ else
+ {
+ buffer.put ((byte) (value >> 24));
+ buffer.put ((byte) (value >> 16));
+ buffer.put ((byte) (value >> 8));
+ buffer.put ((byte) value);
+ }
+ }
+
+ public static int getInt (ByteBuffer buffer, int index, ByteOrder order)
+ {
+ checkAvailableForRead (buffer, index, 4);
+
+ if (order == ByteOrder.LITTLE_ENDIAN)
+ {
+ return ((buffer.get (index) & 0xff)
+ + ((buffer.get (++index) & 0xff) << 8)
+ + ((buffer.get (++index) & 0xff) << 16)
+ + (buffer.get (++index) << 24));
+ }
+
+ return ((buffer.get (index) << 24)
+ + ((buffer.get (++index) & 0xff) << 16)
+ + ((buffer.get (++index) & 0xff) << 8)
+ + (buffer.get (++index) & 0xff));
+ }
+
+ public static void putInt (ByteBuffer buffer, int index,
+ int value, ByteOrder order)
+ {
+ checkAvailableForWrite (buffer, index, 4);
+
+ if (order == ByteOrder.LITTLE_ENDIAN)
+ {
+ buffer.put (index, (byte) value);
+ buffer.put (++index, (byte) (value >> 8));
+ buffer.put (++index, (byte) (value >> 16));
+ buffer.put (++index, (byte) (value >> 24));
+ }
+ else
+ {
+ buffer.put (index, (byte) (value >> 24));
+ buffer.put (++index, (byte) (value >> 16));
+ buffer.put (++index, (byte) (value >> 8));
+ buffer.put (++index, (byte) value);
+ }
+ }
+
+ public static long getLong (ByteBuffer buffer, ByteOrder order)
+ {
+ checkRemainingForRead (buffer, 8);
+
+ if (order == ByteOrder.LITTLE_ENDIAN)
+ {
+ return ((buffer.get() & 0xff)
+ + (((buffer.get() & 0xff)) << 8)
+ + (((buffer.get() & 0xff)) << 16)
+ + (((buffer.get() & 0xffL)) << 24)
+ + (((buffer.get() & 0xffL)) << 32)
+ + (((buffer.get() & 0xffL)) << 40)
+ + (((buffer.get() & 0xffL)) << 48)
+ + (((long) buffer.get()) << 56));
+ }
+
+ return ((((long) buffer.get()) << 56)
+ + ((buffer.get() & 0xffL) << 48)
+ + ((buffer.get() & 0xffL) << 40)
+ + ((buffer.get() & 0xffL) << 32)
+ + ((buffer.get() & 0xffL) << 24)
+ + ((buffer.get() & 0xff) << 16)
+ + ((buffer.get() & 0xff) << 8)
+ + (buffer.get() & 0xff));
+ }
+
+ public static void putLong (ByteBuffer buffer, long value, ByteOrder order)
+ {
+ checkRemainingForWrite (buffer, 8);
+
+ if (order == ByteOrder.LITTLE_ENDIAN)
+ {
+ buffer.put ((byte) value);
+ buffer.put ((byte) (value >> 8));
+ buffer.put ((byte) (value >> 16));
+ buffer.put ((byte) (value >> 24));
+ buffer.put ((byte) (value >> 32));
+ buffer.put ((byte) (value >> 40));
+ buffer.put ((byte) (value >> 48));
+ buffer.put ((byte) (value >> 56));
+ }
+ else
+ {
+ buffer.put ((byte) (value >> 56));
+ buffer.put ((byte) (value >> 48));
+ buffer.put ((byte) (value >> 40));
+ buffer.put ((byte) (value >> 32));
+ buffer.put ((byte) (value >> 24));
+ buffer.put ((byte) (value >> 16));
+ buffer.put ((byte) (value >> 8));
+ buffer.put ((byte) value);
+ }
+ }
+
+ public static long getLong (ByteBuffer buffer, int index, ByteOrder order)
+ {
+ checkAvailableForRead (buffer, index, 8);
+
+ if (order == ByteOrder.LITTLE_ENDIAN)
+ {
+ return ((buffer.get (index) & 0xff)
+ + ((buffer.get (++index) & 0xff) << 8)
+ + ((buffer.get (++index) & 0xff) << 16)
+ + ((buffer.get (++index) & 0xffL) << 24)
+ + ((buffer.get (++index) & 0xffL) << 32)
+ + ((buffer.get (++index) & 0xffL) << 40)
+ + ((buffer.get (++index) & 0xffL) << 48)
+ + (((long) buffer.get (++index)) << 56));
+ }
+
+ return ((((long) buffer.get (index)) << 56)
+ + ((buffer.get (++index) & 0xffL) << 48)
+ + ((buffer.get (++index) & 0xffL) << 40)
+ + ((buffer.get (++index) & 0xffL) << 32)
+ + ((buffer.get (++index) & 0xffL) << 24)
+ + ((buffer.get (++index) & 0xff) << 16)
+ + ((buffer.get (++index) & 0xff) << 8)
+ + (buffer.get (++index) & 0xff));
+ }
+
+ public static void putLong (ByteBuffer buffer, int index,
+ long value, ByteOrder order)
+ {
+ checkAvailableForWrite (buffer, index, 8);
+
+ if (order == ByteOrder.LITTLE_ENDIAN)
+ {
+ buffer.put (index, (byte) value);
+ buffer.put (++index, (byte) (value >> 8));
+ buffer.put (++index, (byte) (value >> 16));
+ buffer.put (++index, (byte) (value >> 24));
+ buffer.put (++index, (byte) (value >> 32));
+ buffer.put (++index, (byte) (value >> 40));
+ buffer.put (++index, (byte) (value >> 48));
+ buffer.put (++index, (byte) (value >> 56));
+ }
+ else
+ {
+ buffer.put (index, (byte) (value >> 56));
+ buffer.put (++index, (byte) (value >> 48));
+ buffer.put (++index, (byte) (value >> 40));
+ buffer.put (++index, (byte) (value >> 32));
+ buffer.put (++index, (byte) (value >> 24));
+ buffer.put (++index, (byte) (value >> 16));
+ buffer.put (++index, (byte) (value >> 8));
+ buffer.put (++index, (byte) value);
+ }
+ }
+
+ public static float getFloat (ByteBuffer buffer, ByteOrder order)
+ {
+ return Float.intBitsToFloat (getInt (buffer, order));
+ }
+
+ public static void putFloat (ByteBuffer buffer, float value, ByteOrder order)
+ {
+ putInt (buffer, Float.floatToRawIntBits (value), order);
+ }
+
+ public static float getFloat (ByteBuffer buffer, int index, ByteOrder order)
+ {
+ return Float.intBitsToFloat (getInt (buffer, index, order));
+ }
+
+ public static void putFloat (ByteBuffer buffer, int index,
+ float value, ByteOrder order)
+ {
+ putInt (buffer, index, Float.floatToRawIntBits (value), order);
+ }
+
+ public static double getDouble (ByteBuffer buffer, ByteOrder order)
+ {
+ return Double.longBitsToDouble (getLong (buffer, order));
+ }
+
+ public static void putDouble (ByteBuffer buffer, double value, ByteOrder order)
+ {
+ putLong (buffer, Double.doubleToLongBits (value), order);
+ }
+
+ public static double getDouble (ByteBuffer buffer, int index, ByteOrder order)
+ {
+ return Double.longBitsToDouble (getLong (buffer, index, order));
+ }
+
+ public static void putDouble (ByteBuffer buffer, int index,
+ double value, ByteOrder order)
+ {
+ putLong (buffer, index, Double.doubleToLongBits (value), order);
+ }
+} // ByteBufferHelper
Index: gnu/java/nio/CharViewBufferImpl.java
===================================================================
RCS file: gnu/java/nio/CharViewBufferImpl.java
diff -N gnu/java/nio/CharViewBufferImpl.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/java/nio/CharViewBufferImpl.java 18 Mar 2004 00:10:22 -0000
@@ -0,0 +1,163 @@
+/* CharViewBufferImpl.java --
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.nio;
+import java.nio.*;
+
+public class CharViewBufferImpl extends CharBuffer
+{
+ /** Position in bb (i.e. a byte offset) where this buffer starts. */
+ private int offset;
+ private ByteBuffer bb;
+ private boolean readOnly;
+ private ByteOrder endian;
+
+ CharViewBufferImpl (ByteBuffer bb, int capacity)
+ {
+ super (capacity, capacity, 0, -1);
+ this.bb = bb;
+ this.offset = bb.position();
+ this.readOnly = bb.isReadOnly();
+ this.endian = bb.order();
+ }
+
+ public CharViewBufferImpl (ByteBuffer bb, int offset, int capacity,
+ int limit, int position, int mark,
+ boolean readOnly, ByteOrder endian)
+ {
+ super (capacity, limit, position, mark);
+ this.bb = bb;
+ this.offset = offset;
+ this.readOnly = readOnly;
+ this.endian = endian;
+ }
+
+ public char get ()
+ {
+ int p = position();
+ char result = ByteBufferHelper.getChar(bb, (p << 1) + offset, endian);
+ position(p + 1);
+ return result;
+ }
+
+ public char get (int index)
+ {
+ return ByteBufferHelper.getChar(bb, (index << 1) + offset, endian);
+ }
+
+ public CharBuffer put (char value)
+ {
+ int p = position();
+ ByteBufferHelper.putChar(bb, (p << 1) + offset, value, endian);
+ position(p + 1);
+ return this;
+ }
+
+ public CharBuffer put (int index, char value)
+ {
+ ByteBufferHelper.putChar(bb, (index << 1) + offset, value, endian);
+ return this;
+ }
+
+ public CharBuffer compact ()
+ {
+ if (position () > 0)
+ {
+ int count = limit () - position ();
+ bb.shiftDown(offset, offset + 2 * position(), 2 * count);
+ position (count);
+ limit (capacity ());
+ }
+ return this;
+ }
+
+ public CharBuffer slice ()
+ {
+ // Create a sliced copy of this object that shares its content.
+ return new CharViewBufferImpl (bb, (position () >> 1) + offset,
+ remaining (), remaining (), 0, -1,
+ isReadOnly (), endian);
+ }
+
+ CharBuffer duplicate (boolean readOnly)
+ {
+ int pos = position();
+ reset();
+ int mark = position();
+ position(pos);
+ return new CharViewBufferImpl (bb, offset, capacity(), limit(),
+ pos, mark, readOnly, endian);
+ }
+
+ public CharBuffer duplicate ()
+ {
+ return duplicate(readOnly);
+ }
+
+ public CharBuffer asReadOnlyBuffer ()
+ {
+ return duplicate(true);
+ }
+
+ public CharSequence subSequence (int start, int end)
+ {
+ if (start < 0
+ || end < start
+ || end > length ())
+ throw new IndexOutOfBoundsException ();
+
+ return new CharViewBufferImpl (bb, array_offset, capacity (),
+ position () + end, position () + start,
+ -1, isReadOnly (), endian);
+ }
+
+ public boolean isReadOnly ()
+ {
+ return readOnly;
+ }
+
+ public boolean isDirect ()
+ {
+ return bb.isDirect ();
+ }
+
+ public ByteOrder order ()
+ {
+ return endian;
+ }
+}
Index: gnu/java/nio/DirectByteBufferImpl.java
===================================================================
RCS file: gnu/java/nio/DirectByteBufferImpl.java
diff -N gnu/java/nio/DirectByteBufferImpl.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/java/nio/DirectByteBufferImpl.java 18 Mar 2004 00:10:22 -0000
@@ -0,0 +1,364 @@
+/* DirectByteBufferImpl.java --
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.nio;
+import java.nio.*;
+
+import gnu.classpath.Configuration;
+import gnu.gcj.RawData;
+
+public class DirectByteBufferImpl extends ByteBuffer
+{
+ static
+ {
+ // load the shared library needed for native methods.
+ if (Configuration.INIT_LOAD_LIBRARY)
+ {
+ System.loadLibrary ("javanio");
+ }
+ }
+
+ /** Used by MappedByteBufferImpl to prevent premature GC. */
+ protected Object owner;
+
+ RawData address;
+ private boolean readOnly;
+
+ public DirectByteBufferImpl (RawData address, long len)
+ {
+ this (null, address, (int) len, (int) len, 0, false);
+ }
+
+ public DirectByteBufferImpl (Object owner, RawData address,
+ int capacity, int limit,
+ int position, boolean readOnly)
+ {
+ super (capacity, limit, position, -1);
+ this.address = address;
+ this.readOnly = readOnly;
+ this.owner = owner;
+ }
+
+ private static native RawData allocateImpl (int capacity);
+ private static native void freeImpl (RawData address);
+
+ protected void finalize () throws Throwable
+ {
+ freeImpl (address);
+ }
+
+ static native byte getImpl (RawData address, int index);
+ static native void putImpl (RawData address, int index, byte value);
+
+ public byte get ()
+ {
+ int pos = position();
+ if (pos >= limit())
+ throw new BufferUnderflowException();
+ byte result = getImpl (address, pos);
+ position (pos + 1);
+ return result;
+ }
+
+ public byte get (int index)
+ {
+ if (index >= limit())
+ throw new BufferUnderflowException();
+ return getImpl (address, index);
+ }
+
+ static native void getImpl (RawData address, int index,
+ byte[] dst, int offset, int length);
+
+ public ByteBuffer get (byte[] dst, int offset, int length)
+ {
+ if (offset < 0 || length < 0 || offset + length > dst.length)
+ throw new IndexOutOfBoundsException ();
+ if (length > remaining())
+ throw new BufferUnderflowException();
+
+ int index = position();
+ getImpl(address, index, dst, offset, length);
+ position(index+length);
+
+ return this;
+ }
+
+ public ByteBuffer put (byte value)
+ {
+ int pos = position();
+ if (pos >= limit())
+ throw new BufferUnderflowException();
+ putImpl (address, pos, value);
+ position (pos + 1);
+ return this;
+ }
+
+ public ByteBuffer put (int index, byte value)
+ {
+ if (index >= limit())
+ throw new BufferUnderflowException();
+ putImpl (address, index, value);
+ return this;
+ }
+
+ native void shiftDown (int dst_offset, int src_offset, int count);
+
+ public ByteBuffer compact ()
+ {
+ int pos = position();
+ if (pos > 0)
+ {
+ int count = remaining();
+ shiftDown(0, pos, count);
+ position(count);
+ limit(capacity());
+ }
+ return this;
+ }
+
+ public static native RawData adjustAddress(RawData address, int offset);
+
+ public ByteBuffer slice ()
+ {
+ int rem = remaining();
+ return new DirectByteBufferImpl (owner,
+ adjustAddress(address, position()),
+ rem, rem, 0, isReadOnly ());
+ }
+
+ private ByteBuffer duplicate (boolean readOnly)
+ {
+ int pos = position();
+ reset();
+ int mark = position();
+ position(pos);
+ DirectByteBufferImpl result
+ = new DirectByteBufferImpl (owner, address, capacity (), limit (),
+ pos, readOnly);
+ if (mark != pos)
+ {
+ result.position(mark);
+ result.mark();
+ result.position(pos);
+ }
+ return result;
+ }
+
+ public ByteBuffer duplicate ()
+ {
+ return duplicate(isReadOnly());
+ }
+
+ public ByteBuffer asReadOnlyBuffer ()
+ {
+ return duplicate(true);
+ }
+
+ public boolean isReadOnly ()
+ {
+ return readOnly;
+ }
+
+ public boolean isDirect ()
+ {
+ return true;
+ }
+
+ public CharBuffer asCharBuffer ()
+ {
+ return new CharViewBufferImpl (this, remaining() >> 1);
+ }
+
+ public ShortBuffer asShortBuffer ()
+ {
+ return new ShortViewBufferImpl (this, remaining() >> 1);
+ }
+
+ public IntBuffer asIntBuffer ()
+ {
+ return new IntViewBufferImpl (this, remaining() >> 2);
+ }
+
+ public LongBuffer asLongBuffer ()
+ {
+ return new LongViewBufferImpl (this, remaining() >> 3);
+ }
+
+ public FloatBuffer asFloatBuffer ()
+ {
+ return new FloatViewBufferImpl (this, remaining() >> 2);
+ }
+
+ public DoubleBuffer asDoubleBuffer ()
+ {
+ return new DoubleViewBufferImpl (this, remaining() >> 3);
+ }
+
+ final public char getChar ()
+ {
+ return ByteBufferHelper.getChar(this, order());
+ }
+
+ final public ByteBuffer putChar (char value)
+ {
+ ByteBufferHelper.putChar(this, value, order());
+ return this;
+ }
+
+ final public char getChar (int index)
+ {
+ return ByteBufferHelper.getChar(this, index, order());
+ }
+
+ final public ByteBuffer putChar (int index, char value)
+ {
+ ByteBufferHelper.putChar(this, index, value, order());
+ return this;
+ }
+
+ final public short getShort ()
+ {
+ return ByteBufferHelper.getShort(this, order());
+ }
+
+ final public ByteBuffer putShort (short value)
+ {
+ ByteBufferHelper.putShort(this, value, order());
+ return this;
+ }
+
+ final public short getShort (int index)
+ {
+ return ByteBufferHelper.getShort(this, index, order());
+ }
+
+ final public ByteBuffer putShort (int index, short value)
+ {
+ ByteBufferHelper.putShort(this, index, value, order());
+ return this;
+ }
+
+ final public int getInt ()
+ {
+ return ByteBufferHelper.getInt(this, order());
+ }
+
+ final public ByteBuffer putInt (int value)
+ {
+ ByteBufferHelper.putInt(this, value, order());
+ return this;
+ }
+
+ final public int getInt (int index)
+ {
+ return ByteBufferHelper.getInt(this, index, order());
+ }
+
+ final public ByteBuffer putInt (int index, int value)
+ {
+ ByteBufferHelper.putInt(this, index, value, order());
+ return this;
+ }
+
+ final public long getLong ()
+ {
+ return ByteBufferHelper.getLong(this, order());
+ }
+
+ final public ByteBuffer putLong (long value)
+ {
+ ByteBufferHelper.putLong (this, value, order());
+ return this;
+ }
+
+ final public long getLong (int index)
+ {
+ return ByteBufferHelper.getLong (this, index, order());
+ }
+
+ final public ByteBuffer putLong (int index, long value)
+ {
+ ByteBufferHelper.putLong (this, index, value, order());
+ return this;
+ }
+
+ final public float getFloat ()
+ {
+ return ByteBufferHelper.getFloat (this, order());
+ }
+
+ final public ByteBuffer putFloat (float value)
+ {
+ ByteBufferHelper.putFloat (this, value, order());
+ return this;
+ }
+
+ public final float getFloat (int index)
+ {
+ return ByteBufferHelper.getFloat (this, index, order());
+ }
+
+ final public ByteBuffer putFloat (int index, float value)
+ {
+ ByteBufferHelper.putFloat (this, index, value, order());
+ return this;
+ }
+
+ final public double getDouble ()
+ {
+ return ByteBufferHelper.getDouble (this, order());
+ }
+
+ final public ByteBuffer putDouble (double value)
+ {
+ ByteBufferHelper.putDouble (this, value, order());
+ return this;
+ }
+
+ final public double getDouble (int index)
+ {
+ return ByteBufferHelper.getDouble (this, index, order());
+ }
+
+ final public ByteBuffer putDouble (int index, double value)
+ {
+ ByteBufferHelper.putDouble (this, index, value, order());
+ return this;
+ }
+}
Index: gnu/java/nio/DoubleViewBufferImpl.java
===================================================================
RCS file: gnu/java/nio/DoubleViewBufferImpl.java
diff -N gnu/java/nio/DoubleViewBufferImpl.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/java/nio/DoubleViewBufferImpl.java 18 Mar 2004 00:10:22 -0000
@@ -0,0 +1,150 @@
+/* DoubleViewBufferImpl.java --
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.nio;
+import java.nio.*;
+
+public class DoubleViewBufferImpl extends DoubleBuffer
+{
+ /** Position in bb (i.e. a byte offset) where this buffer starts. */
+ private int offset;
+ private ByteBuffer bb;
+ private boolean readOnly;
+ private ByteOrder endian;
+
+ DoubleViewBufferImpl (ByteBuffer bb, int capacity)
+ {
+ super (capacity, capacity, 0, -1);
+ this.bb = bb;
+ this.offset = bb.position();
+ this.readOnly = bb.isReadOnly();
+ this.endian = bb.order();
+ }
+
+ public DoubleViewBufferImpl (ByteBuffer bb, int offset, int capacity,
+ int limit, int position, int mark,
+ boolean readOnly, ByteOrder endian)
+ {
+ super (capacity, limit, position, mark);
+ this.bb = bb;
+ this.offset = offset;
+ this.readOnly = readOnly;
+ this.endian = endian;
+ }
+
+ public double get ()
+ {
+ int p = position();
+ double result = ByteBufferHelper.getDouble(bb, (p << 3) + offset, endian);
+ position(p + 1);
+ return result;
+ }
+
+ public double get (int index)
+ {
+ return ByteBufferHelper.getDouble(bb, (index << 3) + offset, endian);
+ }
+
+ public DoubleBuffer put (double value)
+ {
+ int p = position();
+ ByteBufferHelper.putDouble(bb, (p << 3) + offset, value, endian);
+ position(p + 1);
+ return this;
+ }
+
+ public DoubleBuffer put (int index, double value)
+ {
+ ByteBufferHelper.putDouble(bb, (index << 3) + offset, value, endian);
+ return this;
+ }
+
+ public DoubleBuffer compact ()
+ {
+ if (position () > 0)
+ {
+ int count = limit () - position ();
+ bb.shiftDown(offset, offset + 8 * position(), 8 * count);
+ position (count);
+ limit (capacity ());
+ }
+ return this;
+ }
+
+ public DoubleBuffer slice ()
+ {
+ return new DoubleViewBufferImpl (bb, (position () >> 3) + offset,
+ remaining(), remaining(), 0, -1,
+ readOnly, endian);
+ }
+
+ DoubleBuffer duplicate (boolean readOnly)
+ {
+ int pos = position();
+ reset();
+ int mark = position();
+ position(pos);
+ return new DoubleViewBufferImpl (bb, offset, capacity(), limit(),
+ pos, mark, readOnly, endian);
+ }
+
+ public DoubleBuffer duplicate ()
+ {
+ return duplicate(readOnly);
+ }
+
+ public DoubleBuffer asReadOnlyBuffer ()
+ {
+ return duplicate(true);
+ }
+
+ public boolean isReadOnly ()
+ {
+ return readOnly;
+ }
+
+ public boolean isDirect ()
+ {
+ return bb.isDirect ();
+ }
+
+ public ByteOrder order ()
+ {
+ return endian;
+ }
+}
Index: gnu/java/nio/FloatViewBufferImpl.java
===================================================================
RCS file: gnu/java/nio/FloatViewBufferImpl.java
diff -N gnu/java/nio/FloatViewBufferImpl.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/java/nio/FloatViewBufferImpl.java 18 Mar 2004 00:10:22 -0000
@@ -0,0 +1,151 @@
+/* FloatViewBufferImpl.java --
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.nio;
+import java.nio.*;
+
+public class FloatViewBufferImpl extends FloatBuffer
+{
+ /** Position in bb (i.e. a byte offset) where this buffer starts. */
+ private int offset;
+ private ByteBuffer bb;
+ private boolean readOnly;
+ private ByteOrder endian;
+
+ FloatViewBufferImpl (ByteBuffer bb, int capacity)
+ {
+ super (capacity, capacity, 0, -1);
+ this.bb = bb;
+ this.offset = bb.position();
+ this.readOnly = bb.isReadOnly();
+ this.endian = bb.order();
+ }
+
+ public FloatViewBufferImpl (ByteBuffer bb, int offset, int capacity,
+ int limit, int position, int mark,
+ boolean readOnly, ByteOrder endian)
+ {
+ super (capacity, limit, position, mark);
+ this.bb = bb;
+ this.offset = offset;
+ this.readOnly = readOnly;
+ this.endian = endian;
+ }
+
+ public float get ()
+ {
+ int p = position();
+ float result = ByteBufferHelper.getFloat(bb, (p << 2) + offset, endian);
+ position(p + 1);
+ return result;
+ }
+
+ public float get (int index)
+ {
+ return ByteBufferHelper.getFloat(bb, (index << 2) + offset, endian);
+ }
+
+ public FloatBuffer put (float value)
+ {
+ int p = position();
+ ByteBufferHelper.putFloat(bb, (p << 2) + offset, value, endian);
+ position(p + 1);
+ return this;
+ }
+
+ public FloatBuffer put (int index, float value)
+ {
+ ByteBufferHelper.putFloat(bb, (index << 2) + offset, value, endian);
+ return this;
+ }
+
+ public FloatBuffer compact ()
+ {
+ if (position () > 0)
+ {
+ int count = limit () - position ();
+ bb.shiftDown(offset, offset + 4 * position(), 4 * count);
+ position (count);
+ limit (capacity ());
+ }
+ return this;
+ }
+
+ public FloatBuffer slice ()
+ {
+ // Create a sliced copy of this object that shares its content.
+ return new FloatViewBufferImpl (bb, (position () >> 2) + offset,
+ remaining(), remaining(), 0, -1,
+ readOnly, endian);
+ }
+
+ FloatBuffer duplicate (boolean readOnly)
+ {
+ int pos = position();
+ reset();
+ int mark = position();
+ position(pos);
+ return new FloatViewBufferImpl (bb, offset, capacity(), limit(),
+ pos, mark, readOnly, endian);
+ }
+
+ public FloatBuffer duplicate ()
+ {
+ return duplicate(readOnly);
+ }
+
+ public FloatBuffer asReadOnlyBuffer ()
+ {
+ return duplicate(true);
+ }
+
+ public boolean isReadOnly ()
+ {
+ return readOnly;
+ }
+
+ public boolean isDirect ()
+ {
+ return bb.isDirect ();
+ }
+
+ public ByteOrder order ()
+ {
+ return endian;
+ }
+}
Index: gnu/java/nio/IntViewBufferImpl.java
===================================================================
RCS file: gnu/java/nio/IntViewBufferImpl.java
diff -N gnu/java/nio/IntViewBufferImpl.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/java/nio/IntViewBufferImpl.java 18 Mar 2004 00:10:22 -0000
@@ -0,0 +1,151 @@
+/* IntViewBufferImpl.java --
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.nio;
+import java.nio.*;
+
+public class IntViewBufferImpl extends IntBuffer
+{
+ /** Position in bb (i.e. a byte offset) where this buffer starts. */
+ private int offset;
+ private ByteBuffer bb;
+ private boolean readOnly;
+ private ByteOrder endian;
+
+ IntViewBufferImpl (ByteBuffer bb, int capacity)
+ {
+ super (capacity, capacity, 0, -1);
+ this.bb = bb;
+ this.offset = bb.position();
+ this.readOnly = bb.isReadOnly();
+ this.endian = bb.order();
+ }
+
+ public IntViewBufferImpl (ByteBuffer bb, int offset, int capacity,
+ int limit, int position, int mark,
+ boolean readOnly, ByteOrder endian)
+ {
+ super (capacity, limit, position, mark);
+ this.bb = bb;
+ this.offset = offset;
+ this.readOnly = readOnly;
+ this.endian = endian;
+ }
+
+ public int get ()
+ {
+ int p = position();
+ int result = ByteBufferHelper.getInt(bb, (p << 2) + offset, endian);
+ position(p + 1);
+ return result;
+ }
+
+ public int get (int index)
+ {
+ return ByteBufferHelper.getInt(bb, (index << 2) + offset, endian);
+ }
+
+ public IntBuffer put (int value)
+ {
+ int p = position();
+ ByteBufferHelper.putInt(bb, (p << 2) + offset, value, endian);
+ position(p + 1);
+ return this;
+ }
+
+ public IntBuffer put (int index, int value)
+ {
+ ByteBufferHelper.putInt(bb, (index << 2) + offset, value, endian);
+ return this;
+ }
+
+ public IntBuffer compact ()
+ {
+ if (position () > 0)
+ {
+ int count = limit () - position ();
+ bb.shiftDown(offset, offset + 4 * position(), 4 * count);
+ position (count);
+ limit (capacity ());
+ }
+ return this;
+ }
+
+ public IntBuffer slice ()
+ {
+ // Create a sliced copy of this object that shares its content.
+ return new IntViewBufferImpl (bb, (position () >> 2) + offset,
+ remaining(), remaining(), 0, -1,
+ readOnly, endian);
+ }
+
+ IntBuffer duplicate (boolean readOnly)
+ {
+ int pos = position();
+ reset();
+ int mark = position();
+ position(pos);
+ return new IntViewBufferImpl (bb, offset, capacity(), limit(),
+ pos, mark, readOnly, endian);
+ }
+
+ public IntBuffer duplicate ()
+ {
+ return duplicate(readOnly);
+ }
+
+ public IntBuffer asReadOnlyBuffer ()
+ {
+ return duplicate(true);
+ }
+
+ public boolean isReadOnly ()
+ {
+ return readOnly;
+ }
+
+ public boolean isDirect ()
+ {
+ return bb.isDirect ();
+ }
+
+ public ByteOrder order ()
+ {
+ return endian;
+ }
+}
Index: gnu/java/nio/LongViewBufferImpl.java
===================================================================
RCS file: gnu/java/nio/LongViewBufferImpl.java
diff -N gnu/java/nio/LongViewBufferImpl.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/java/nio/LongViewBufferImpl.java 18 Mar 2004 00:10:22 -0000
@@ -0,0 +1,151 @@
+/* LongViewBufferImpl.java --
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.nio;
+import java.nio.*;
+
+public class LongViewBufferImpl extends LongBuffer
+{
+ /** Position in bb (i.e. a byte offset) where this buffer starts. */
+ private int offset;
+ private ByteBuffer bb;
+ private boolean readOnly;
+ private ByteOrder endian;
+
+ LongViewBufferImpl (ByteBuffer bb, int capacity)
+ {
+ super (capacity, capacity, 0, -1);
+ this.bb = bb;
+ this.offset = bb.position();
+ this.readOnly = bb.isReadOnly();
+ this.endian = bb.order();
+ }
+
+ public LongViewBufferImpl (ByteBuffer bb, int offset, int capacity,
+ int limit, int position, int mark,
+ boolean readOnly, ByteOrder endian)
+ {
+ super (capacity, limit, position, mark);
+ this.bb = bb;
+ this.offset = offset;
+ this.readOnly = readOnly;
+ this.endian = endian;
+ }
+
+ public long get ()
+ {
+ int p = position();
+ long result = ByteBufferHelper.getLong(bb, (p << 3) + offset, endian);
+ position(p + 1);
+ return result;
+ }
+
+ public long get (int index)
+ {
+ return ByteBufferHelper.getLong(bb, (index << 3) + offset, endian);
+ }
+
+ public LongBuffer put (long value)
+ {
+ int p = position();
+ ByteBufferHelper.putLong(bb, (p << 3) + offset, value, endian);
+ position(p + 1);
+ return this;
+ }
+
+ public LongBuffer put (int index, long value)
+ {
+ ByteBufferHelper.putLong(bb, (index << 3) + offset, value, endian);
+ return this;
+ }
+
+ public LongBuffer compact ()
+ {
+ if (position () > 0)
+ {
+ int count = limit () - position ();
+ bb.shiftDown(offset, offset + 8 * position(), 8 * count);
+ position (count);
+ limit (capacity ());
+ }
+ return this;
+ }
+
+ public LongBuffer slice ()
+ {
+ // Create a sliced copy of this object that shares its content.
+ return new LongViewBufferImpl (bb, (position () >> 3) + offset,
+ remaining(), remaining(), 0, -1,
+ readOnly, endian);
+ }
+
+ LongBuffer duplicate (boolean readOnly)
+ {
+ int pos = position();
+ reset();
+ int mark = position();
+ position(pos);
+ return new LongViewBufferImpl (bb, offset, capacity(), limit(),
+ pos, mark, readOnly, endian);
+ }
+
+ public LongBuffer duplicate ()
+ {
+ return duplicate(readOnly);
+ }
+
+ public LongBuffer asReadOnlyBuffer ()
+ {
+ return duplicate(true);
+ }
+
+ public boolean isReadOnly ()
+ {
+ return readOnly;
+ }
+
+ public boolean isDirect ()
+ {
+ return bb.isDirect ();
+ }
+
+ public ByteOrder order ()
+ {
+ return endian;
+ }
+}
Index: gnu/java/nio/MappedByteBufferImpl.java
===================================================================
RCS file: gnu/java/nio/MappedByteBufferImpl.java
diff -N gnu/java/nio/MappedByteBufferImpl.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/java/nio/MappedByteBufferImpl.java 18 Mar 2004 00:10:22 -0000
@@ -0,0 +1,344 @@
+/* MappedByteBufferImpl.java --
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.nio;
+
+import java.nio.*;
+import java.io.IOException;
+import gnu.java.nio.channels.FileChannelImpl;
+import gnu.gcj.RawData;
+
+public class MappedByteBufferImpl extends MappedByteBuffer
+{
+ boolean readOnly;
+ RawData address;
+
+ /** Posix uses this for the pointer returned by mmap;
+ * Win32 uses it for the pointer returned by MapViewOfFile. */
+ public RawData implPtr;
+ /** Posix uses this for the actual length passed to mmap;
+ * Win32 uses it for the pointer returned by CreateFileMapping. */
+ public long implLen;
+
+ public MappedByteBufferImpl (RawData address, int size, boolean readOnly)
+ throws IOException
+ {
+ super(size, size, 0, -1);
+ this.address = address;
+ this.readOnly = readOnly;
+ }
+
+ public boolean isReadOnly ()
+ {
+ return readOnly;
+ }
+
+ public byte get ()
+ {
+ int pos = position();
+ if (pos >= limit())
+ throw new BufferUnderflowException();
+ byte result = DirectByteBufferImpl.getImpl(address, pos);
+ position (pos + 1);
+ return result;
+ }
+
+ public ByteBuffer put (byte value)
+ {
+ int pos = position();
+ if (pos >= limit())
+ throw new BufferUnderflowException();
+ DirectByteBufferImpl.putImpl(address, pos, value);
+ position(pos + 1);
+ return this;
+ }
+
+ public byte get (int index)
+ {
+ if (index >= limit())
+ throw new BufferUnderflowException();
+ return DirectByteBufferImpl.getImpl(address, index);
+ }
+
+ public ByteBuffer get (byte[] dst, int offset, int length)
+ {
+ if (offset < 0 || length < 0 || offset + length > dst.length)
+ throw new IndexOutOfBoundsException ();
+ if (length > remaining())
+ throw new BufferUnderflowException();
+
+ int index = position();
+ DirectByteBufferImpl.getImpl(address, index, dst, offset, length);
+ position(index+length);
+
+ return this;
+ }
+
+ public ByteBuffer put (int index, byte value)
+ {
+ if (index >= limit())
+ throw new BufferUnderflowException();
+ DirectByteBufferImpl.putImpl(address, index, value);
+ return this;
+ }
+
+ public ByteBuffer compact ()
+ {
+ int pos = position();
+ if (pos > 0)
+ {
+ int count = remaining();
+ shiftDown(0, pos, count);
+ position(count);
+ limit(capacity());
+ }
+ return this;
+ }
+
+ public boolean isDirect ()
+ {
+ return true;
+ }
+
+ public ByteBuffer slice ()
+ {
+ int rem = remaining();
+ return new DirectByteBufferImpl (this,
+ DirectByteBufferImpl
+ .adjustAddress(address, position()),
+ rem, rem, 0, isReadOnly ());
+ }
+
+ private ByteBuffer duplicate (boolean readOnly)
+ {
+ int pos = position();
+ reset();
+ int mark = position();
+ position(pos);
+ DirectByteBufferImpl result
+ = new DirectByteBufferImpl (this, address, capacity (), limit (),
+ pos, readOnly);
+ if (mark != pos)
+ {
+ result.position(mark);
+ result.mark();
+ result.position(pos);
+ }
+ return result;
+ }
+
+ public ByteBuffer duplicate ()
+ {
+ return duplicate(isReadOnly());
+ }
+
+ public ByteBuffer asReadOnlyBuffer ()
+ {
+ return duplicate(true);
+ }
+
+ public CharBuffer asCharBuffer ()
+ {
+ return new CharViewBufferImpl (this, remaining() >> 1);
+ }
+
+ public ShortBuffer asShortBuffer ()
+ {
+ return new ShortViewBufferImpl (this, remaining() >> 1);
+ }
+
+ public IntBuffer asIntBuffer ()
+ {
+ return new IntViewBufferImpl (this, remaining() >> 2);
+ }
+
+ public LongBuffer asLongBuffer ()
+ {
+ return new LongViewBufferImpl (this, remaining() >> 3);
+ }
+
+ public FloatBuffer asFloatBuffer ()
+ {
+ return new FloatViewBufferImpl (this, remaining() >> 2);
+ }
+
+ public DoubleBuffer asDoubleBuffer ()
+ {
+ return new DoubleViewBufferImpl (this, remaining() >> 3);
+ }
+
+ final public char getChar ()
+ {
+ return ByteBufferHelper.getChar(this, order());
+ }
+
+ final public ByteBuffer putChar (char value)
+ {
+ ByteBufferHelper.putChar(this, value, order());
+ return this;
+ }
+
+ final public char getChar (int index)
+ {
+ return ByteBufferHelper.getChar(this, index, order());
+ }
+
+ final public ByteBuffer putChar (int index, char value)
+ {
+ ByteBufferHelper.putChar(this, index, value, order());
+ return this;
+ }
+
+ final public short getShort ()
+ {
+ return ByteBufferHelper.getShort(this, order());
+ }
+
+ final public ByteBuffer putShort (short value)
+ {
+ ByteBufferHelper.putShort(this, value, order());
+ return this;
+ }
+
+ final public short getShort (int index)
+ {
+ return ByteBufferHelper.getShort(this, index, order());
+ }
+
+ final public ByteBuffer putShort (int index, short value)
+ {
+ ByteBufferHelper.putShort(this, index, value, order());
+ return this;
+ }
+
+ final public int getInt ()
+ {
+ return ByteBufferHelper.getInt(this, order());
+ }
+
+ final public ByteBuffer putInt (int value)
+ {
+ ByteBufferHelper.putInt(this, value, order());
+ return this;
+ }
+
+ final public int getInt (int index)
+ {
+ return ByteBufferHelper.getInt(this, index, order());
+ }
+
+ final public ByteBuffer putInt (int index, int value)
+ {
+ ByteBufferHelper.putInt(this, index, value, order());
+ return this;
+ }
+
+ final public long getLong ()
+ {
+ return ByteBufferHelper.getLong(this, order());
+ }
+
+ final public ByteBuffer putLong (long value)
+ {
+ ByteBufferHelper.putLong (this, value, order());
+ return this;
+ }
+
+ final public long getLong (int index)
+ {
+ return ByteBufferHelper.getLong (this, index, order());
+ }
+
+ final public ByteBuffer putLong (int index, long value)
+ {
+ ByteBufferHelper.putLong (this, index, value, order());
+ return this;
+ }
+
+ final public float getFloat ()
+ {
+ return ByteBufferHelper.getFloat (this, order());
+ }
+
+ final public ByteBuffer putFloat (float value)
+ {
+ ByteBufferHelper.putFloat (this, value, order());
+ return this;
+ }
+
+ public final float getFloat (int index)
+ {
+ return ByteBufferHelper.getFloat (this, index, order());
+ }
+
+ final public ByteBuffer putFloat (int index, float value)
+ {
+ ByteBufferHelper.putFloat (this, index, value, order());
+ return this;
+ }
+
+ final public double getDouble ()
+ {
+ return ByteBufferHelper.getDouble (this, order());
+ }
+
+ final public ByteBuffer putDouble (double value)
+ {
+ ByteBufferHelper.putDouble (this, value, order());
+ return this;
+ }
+
+ final public double getDouble (int index)
+ {
+ return ByteBufferHelper.getDouble (this, index, order());
+ }
+
+ final public ByteBuffer putDouble (int index, double value)
+ {
+ ByteBufferHelper.putDouble (this, index, value, order());
+ return this;
+ }
+
+ // NOTE: In libgcj these methods are implemented in natFileChannelXxx.cc,
+ // because they're small, and to put them next to FileChannelImpl::mapImpl.
+ native void unmapImpl ();
+ native boolean isLoadedImpl ();
+ // FIXME: Try to load all pages into memory.
+ native void loadImpl();
+
+ native void forceImpl();
+}
Index: gnu/java/nio/ShortViewBufferImpl.java
===================================================================
RCS file: gnu/java/nio/ShortViewBufferImpl.java
diff -N gnu/java/nio/ShortViewBufferImpl.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/java/nio/ShortViewBufferImpl.java 18 Mar 2004 00:10:22 -0000
@@ -0,0 +1,151 @@
+/* ShortViewBufferImpl.java --
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.java.nio;
+import java.nio.*;
+
+public class ShortViewBufferImpl extends ShortBuffer
+{
+ /** Position in bb (i.e. a byte offset) where this buffer starts. */
+ private int offset;
+ private ByteBuffer bb;
+ private boolean readOnly;
+ private ByteOrder endian;
+
+ ShortViewBufferImpl (ByteBuffer bb, int capacity)
+ {
+ super (capacity, capacity, 0, -1);
+ this.bb = bb;
+ this.offset = bb.position();
+ this.readOnly = bb.isReadOnly();
+ this.endian = bb.order();
+ }
+
+ public ShortViewBufferImpl (ByteBuffer bb, int offset, int capacity,
+ int limit, int position, int mark,
+ boolean readOnly, ByteOrder endian)
+ {
+ super (capacity, limit, position, mark);
+ this.bb = bb;
+ this.offset = offset;
+ this.readOnly = readOnly;
+ this.endian = endian;
+ }
+
+ public short get ()
+ {
+ int p = position();
+ short result = ByteBufferHelper.getShort(bb, (p << 1) + offset, endian);
+ position(p + 1);
+ return result;
+ }
+
+ public short get (int index)
+ {
+ return ByteBufferHelper.getShort(bb, (index << 1) + offset, endian);
+ }
+
+ public ShortBuffer put (short value)
+ {
+ int p = position();
+ ByteBufferHelper.putShort(bb, (p << 1) + offset, value, endian);
+ position(p + 1);
+ return this;
+ }
+
+ public ShortBuffer put (int index, short value)
+ {
+ ByteBufferHelper.putShort(bb, (index << 1) + offset, value, endian);
+ return this;
+ }
+
+ public ShortBuffer compact ()
+ {
+ if (position () > 0)
+ {
+ int count = limit () - position ();
+ bb.shiftDown(offset, offset + 2 * position(), 2 * count);
+ position (count);
+ limit (capacity ());
+ }
+ return this;
+ }
+
+ public ShortBuffer slice ()
+ {
+ // Create a sliced copy of this object that shares its content.
+ return new ShortViewBufferImpl (bb, (position () >> 1) + offset,
+ remaining(), remaining(), 0, -1,
+ readOnly, endian);
+ }
+
+ ShortBuffer duplicate (boolean readOnly)
+ {
+ int pos = position();
+ reset();
+ int mark = position();
+ position(pos);
+ return new ShortViewBufferImpl (bb, offset, capacity(), limit(),
+ pos, mark, readOnly, endian);
+ }
+
+ public ShortBuffer duplicate ()
+ {
+ return duplicate(readOnly);
+ }
+
+ public ShortBuffer asReadOnlyBuffer ()
+ {
+ return duplicate(true);
+ }
+
+ public boolean isReadOnly ()
+ {
+ return readOnly;
+ }
+
+ public boolean isDirect ()
+ {
+ return bb.isDirect ();
+ }
+
+ public ByteOrder order ()
+ {
+ return endian;
+ }
+}
Index: gnu/java/nio/natDirectByteBufferImpl.cc
===================================================================
RCS file: gnu/java/nio/natDirectByteBufferImpl.cc
diff -N gnu/java/nio/natDirectByteBufferImpl.cc
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/java/nio/natDirectByteBufferImpl.cc 18 Mar 2004 00:10:22 -0000
@@ -0,0 +1,73 @@
+// natDirectByteBufferImpl.cc
+
+/* Copyright (C) 2003, 2004 Free Software Foundation
+
+ This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+details. */
+
+#include <config.h>
+
+#include <gcj/cni.h>
+#include <jvm.h>
+
+#include <stdlib.h>
+
+#include <gnu/gcj/RawData.h>
+#include <gnu/java/nio/DirectByteBufferImpl.h>
+
+using gnu::gcj::RawData;
+using gnu::java::nio::DirectByteBufferImpl;
+
+RawData*
+DirectByteBufferImpl::allocateImpl (jint capacity)
+{
+ return reinterpret_cast<gnu::gcj::RawData*> (::malloc (capacity));
+}
+
+void
+DirectByteBufferImpl::freeImpl (gnu::gcj::RawData* address)
+{
+ ::free (reinterpret_cast<void*> (address));
+}
+
+jbyte
+DirectByteBufferImpl::getImpl (RawData* address, jint index)
+{
+ jbyte* pointer = reinterpret_cast<jbyte*> (address) + index;
+ return *pointer;
+}
+
+void
+DirectByteBufferImpl::getImpl (RawData* address, jint index,
+ jbyteArray dst, jint offset, jint length)
+{
+ jbyte* src = reinterpret_cast<jbyte*> (address) + index;
+ memcpy (elements (dst) + offset, src, length);
+}
+
+void
+DirectByteBufferImpl::putImpl (gnu::gcj::RawData* address,
+ jint index, jbyte value)
+{
+ jbyte* pointer = reinterpret_cast<jbyte*> (address) + index;
+ *pointer = value;
+}
+
+RawData*
+DirectByteBufferImpl::adjustAddress (RawData* address, jint offset)
+{
+ jbyte* start = reinterpret_cast<jbyte*> (address) + offset;
+ return reinterpret_cast<RawData*>(start);
+}
+
+void
+DirectByteBufferImpl::shiftDown
+(jint dst_offset, jint src_offset, jint count)
+{
+ jbyte* dst = reinterpret_cast<jbyte*> (address) + array_offset + dst_offset;
+ jbyte* src = reinterpret_cast<jbyte*> (address) + array_offset + src_offset;
+ ::memmove(dst, src, count);
+}
Index: gnu/java/nio/channels/natFileChannelEcos.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/channels/natFileChannelEcos.cc,v
retrieving revision 1.2
diff -u -p -r1.2 natFileChannelEcos.cc
--- gnu/java/nio/channels/natFileChannelEcos.cc 11 Mar 2004 13:35:45 -0000 1.2
+++ gnu/java/nio/channels/natFileChannelEcos.cc 18 Mar 2004 00:10:22 -0000
@@ -26,20 +26,32 @@ details. */
#include <java/lang/NullPointerException.h>
#include <java/lang/String.h>
#include <java/io/FileNotFoundException.h>
-#include <java/nio/MappedByteBufferImpl.h>
+#include <gnu/java/nio/MappedByteBufferImpl.h>
#include <java/nio/channels/FileChannel.h>
#include <java/nio/channels/FileLock.h>
#include <gnu/java/nio/channels/FileChannelImpl.h>
using gnu::gcj::RawData;
using java::io::IOException;
-using java::nio::MappedByteBufferImpl;
+using gnu::java::nio::MappedByteBufferImpl;
using java::io::InterruptedIOException;
using java::io::FileNotFoundException;
using java::lang::ArrayIndexOutOfBoundsException;
using java::lang::NullPointerException;
using gnu::java::nio::channels::FileChannelImpl;
+extern "C" void diag_write_char (char c);
+
+static void
+diag_write (char *data, int len)
+{
+ while (len > 0)
+ {
+ diag_write_char (*data++);
+ len--;
+ }
+}
+
#define NO_FSYNC_MESSAGE "sync unsupported"
void
@@ -78,6 +90,8 @@ FileChannelImpl::open (jstring, jint)
void
FileChannelImpl::write (jint)
{
+ char d = (char) b;
+ ::diag_write (&d, 1);
}
void
@@ -87,6 +101,8 @@ FileChannelImpl::write (jbyteArray b, ji
throw new NullPointerException;
if (offset < 0 || len < 0 || offset + len > JvGetArrayLength (b))
throw new ArrayIndexOutOfBoundsException;
+ char *bytes = (char *)elements (b) + offset;
+ ::diag_write (bytes, len);
}
void
Index: gnu/java/nio/channels/natFileChannelPosix.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/channels/natFileChannelPosix.cc,v
retrieving revision 1.2
diff -u -p -r1.2 natFileChannelPosix.cc
--- gnu/java/nio/channels/natFileChannelPosix.cc 13 Mar 2004 23:07:58 -0000 1.2
+++ gnu/java/nio/channels/natFileChannelPosix.cc 18 Mar 2004 00:10:22 -0000
@@ -39,7 +39,7 @@ details. */
#include <java/lang/String.h>
#include <java/lang/Thread.h>
#include <java/nio/ByteBuffer.h>
-#include <java/nio/MappedByteBufferImpl.h>
+#include <gnu/java/nio/MappedByteBufferImpl.h>
#include <java/nio/channels/FileChannel.h>
#include <java/nio/channels/FileLock.h>
#include <gnu/java/nio/channels/FileChannelImpl.h>
@@ -80,7 +80,7 @@ msync_adaptor(int (*msync)(T_implPtr cad
using gnu::gcj::RawData;
using java::io::IOException;
-using java::nio::MappedByteBufferImpl;
+using gnu::java::nio::MappedByteBufferImpl;
using java::io::InterruptedIOException;
using java::io::FileNotFoundException;
using java::lang::ArrayIndexOutOfBoundsException;
Index: gnu/java/nio/channels/natFileChannelWin32.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/java/nio/channels/natFileChannelWin32.cc,v
retrieving revision 1.1
diff -u -p -r1.1 natFileChannelWin32.cc
--- gnu/java/nio/channels/natFileChannelWin32.cc 29 Feb 2004 19:09:28 -0000 1.1
+++ gnu/java/nio/channels/natFileChannelWin32.cc 18 Mar 2004 00:10:23 -0000
@@ -35,14 +35,14 @@ details. */
#include <java/lang/String.h>
#include <java/lang/Thread.h>
#include <java/nio/ByteBuffer.h>
-#include <java/nio/MappedByteBufferImpl.h>
+#include <gnu/java/nio/MappedByteBufferImpl.h>
#include <java/nio/channels/FileChannel.h>
#include <java/nio/channels/FileLock.h>
#include <gnu/java/nio/channels/FileChannelImpl.h>
using gnu::gcj::RawData;
using java::io::IOException;
-using java::nio::MappedByteBufferImpl;
+using gnu::java::nio::MappedByteBufferImpl;
using java::io::InterruptedIOException;
using java::io::FileNotFoundException;
using java::lang::ArrayIndexOutOfBoundsException;
Index: java/nio/ByteBuffer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/ByteBuffer.java,v
retrieving revision 1.16
diff -u -p -r1.16 ByteBuffer.java
--- java/nio/ByteBuffer.java 16 Feb 2004 20:00:33 -0000 1.16
+++ java/nio/ByteBuffer.java 18 Mar 2004 00:10:23 -0000
@@ -37,6 +37,7 @@ exception statement from your version. *
package java.nio;
+import gnu.java.nio.*;
/**
* @since 1.4
Index: java/nio/ByteBufferHelper.java
===================================================================
RCS file: java/nio/ByteBufferHelper.java
diff -N java/nio/ByteBufferHelper.java
--- java/nio/ByteBufferHelper.java 8 Feb 2004 21:02:53 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,381 +0,0 @@
-/* ByteBufferImpl.java --
- Copyright (C) 2003, 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package java.nio;
-
-/**
- * @author Michael Koch <konqueror@gmx.de>
- */
-final class ByteBufferHelper
-{
- private static void checkRemainingForRead (ByteBuffer buffer, int bytes)
- {
- if (buffer.remaining() < bytes)
- throw new BufferUnderflowException();
- }
-
- private static void checkRemainingForWrite (ByteBuffer buffer, int bytes)
- {
- if (buffer.remaining() < bytes)
- throw new BufferOverflowException();
- }
-
- private static void checkAvailableForRead (ByteBuffer buffer,
- int index, int bytes)
- {
- if (buffer.limit() < (index + bytes))
- throw new BufferUnderflowException();
- }
-
- private static void checkAvailableForWrite (ByteBuffer buffer,
- int index, int bytes)
- {
- if (buffer.limit() < (index + bytes))
- throw new BufferOverflowException();
- }
-
- public static char getChar (ByteBuffer buffer, ByteOrder order)
- {
- return (char) getShort (buffer, order);
- }
-
- public static void putChar (ByteBuffer buffer, char value, ByteOrder order)
- {
- putShort (buffer, (short) value, order);
- }
-
- public static char getChar (ByteBuffer buffer, int index, ByteOrder order)
- {
- return (char) getShort (buffer, index, order);
- }
-
- public static void putChar (ByteBuffer buffer, int index,
- char value, ByteOrder order)
- {
- putShort (buffer, index, (short) value, order);
- }
-
- public static short getShort (ByteBuffer buffer, ByteOrder order)
- {
- checkRemainingForRead (buffer, 2);
-
- if (order == ByteOrder.LITTLE_ENDIAN)
- {
- return (short) ((buffer.get() & 0xff)
- + (buffer.get() << 8));
- }
-
- return (short) ((buffer.get() << 8)
- + (buffer.get() & 0xff));
- }
-
- public static void putShort (ByteBuffer buffer, short value, ByteOrder order)
- {
- checkRemainingForWrite (buffer, 2);
-
- if (order == ByteOrder.LITTLE_ENDIAN)
- {
- buffer.put ((byte) value);
- buffer.put ((byte) (value >> 8));
- }
- else
- {
- buffer.put ((byte) (value >> 8));
- buffer.put ((byte) value);
- }
- }
-
- public static short getShort (ByteBuffer buffer,
- int index, ByteOrder order)
- {
- checkAvailableForRead (buffer, index, 2);
-
- if (order == ByteOrder.LITTLE_ENDIAN)
- {
- return (short) ((buffer.get (index) & 0xff)
- + (buffer.get (++index) << 8));
- }
-
- return (short) ((buffer.get (index) << 8)
- + (buffer.get (++index) & 0xff));
- }
-
- public static void putShort (ByteBuffer buffer, int index,
- short value, ByteOrder order)
- {
- checkAvailableForWrite (buffer, index, 2);
-
- if (order == ByteOrder.LITTLE_ENDIAN)
- {
- buffer.put (index, (byte) value);
- buffer.put (++index, (byte) (value >> 8));
- }
- else
- {
- buffer.put (index, (byte) (value >> 8));
- buffer.put (++index, (byte) value);
- }
- }
-
- public static int getInt (ByteBuffer buffer, ByteOrder order)
- {
- checkRemainingForRead (buffer, 4);
-
- if (order == ByteOrder.LITTLE_ENDIAN)
- {
- return ((buffer.get() & 0xff)
- + ((buffer.get() & 0xff) << 8)
- + ((buffer.get() & 0xff) << 16)
- + (buffer.get() << 24));
- }
-
- return (int) ((buffer.get() << 24)
- + ((buffer.get() & 0xff) << 16)
- + ((buffer.get() & 0xff) << 8)
- + (buffer.get() & 0xff));
- }
-
- public static void putInt (ByteBuffer buffer, int value, ByteOrder order)
- {
- checkRemainingForWrite (buffer, 4);
-
- if (order == ByteOrder.LITTLE_ENDIAN)
- {
- buffer.put ((byte) value);
- buffer.put ((byte) (value >> 8));
- buffer.put ((byte) (value >> 16));
- buffer.put ((byte) (value >> 24));
- }
- else
- {
- buffer.put ((byte) (value >> 24));
- buffer.put ((byte) (value >> 16));
- buffer.put ((byte) (value >> 8));
- buffer.put ((byte) value);
- }
- }
-
- public static int getInt (ByteBuffer buffer, int index, ByteOrder order)
- {
- checkAvailableForRead (buffer, index, 4);
-
- if (order == ByteOrder.LITTLE_ENDIAN)
- {
- return ((buffer.get (index) & 0xff)
- + ((buffer.get (++index) & 0xff) << 8)
- + ((buffer.get (++index) & 0xff) << 16)
- + (buffer.get (++index) << 24));
- }
-
- return ((buffer.get (index) << 24)
- + ((buffer.get (++index) & 0xff) << 16)
- + ((buffer.get (++index) & 0xff) << 8)
- + (buffer.get (++index) & 0xff));
- }
-
- public static void putInt (ByteBuffer buffer, int index,
- int value, ByteOrder order)
- {
- checkAvailableForWrite (buffer, index, 4);
-
- if (order == ByteOrder.LITTLE_ENDIAN)
- {
- buffer.put (index, (byte) value);
- buffer.put (++index, (byte) (value >> 8));
- buffer.put (++index, (byte) (value >> 16));
- buffer.put (++index, (byte) (value >> 24));
- }
- else
- {
- buffer.put (index, (byte) (value >> 24));
- buffer.put (++index, (byte) (value >> 16));
- buffer.put (++index, (byte) (value >> 8));
- buffer.put (++index, (byte) value);
- }
- }
-
- public static long getLong (ByteBuffer buffer, ByteOrder order)
- {
- checkRemainingForRead (buffer, 8);
-
- if (order == ByteOrder.LITTLE_ENDIAN)
- {
- return ((buffer.get() & 0xff)
- + (((buffer.get() & 0xff)) << 8)
- + (((buffer.get() & 0xff)) << 16)
- + (((buffer.get() & 0xffL)) << 24)
- + (((buffer.get() & 0xffL)) << 32)
- + (((buffer.get() & 0xffL)) << 40)
- + (((buffer.get() & 0xffL)) << 48)
- + (((long) buffer.get()) << 56));
- }
-
- return ((((long) buffer.get()) << 56)
- + ((buffer.get() & 0xffL) << 48)
- + ((buffer.get() & 0xffL) << 40)
- + ((buffer.get() & 0xffL) << 32)
- + ((buffer.get() & 0xffL) << 24)
- + ((buffer.get() & 0xff) << 16)
- + ((buffer.get() & 0xff) << 8)
- + (buffer.get() & 0xff));
- }
-
- public static void putLong (ByteBuffer buffer, long value, ByteOrder order)
- {
- checkRemainingForWrite (buffer, 8);
-
- if (order == ByteOrder.LITTLE_ENDIAN)
- {
- buffer.put ((byte) value);
- buffer.put ((byte) (value >> 8));
- buffer.put ((byte) (value >> 16));
- buffer.put ((byte) (value >> 24));
- buffer.put ((byte) (value >> 32));
- buffer.put ((byte) (value >> 40));
- buffer.put ((byte) (value >> 48));
- buffer.put ((byte) (value >> 56));
- }
- else
- {
- buffer.put ((byte) (value >> 56));
- buffer.put ((byte) (value >> 48));
- buffer.put ((byte) (value >> 40));
- buffer.put ((byte) (value >> 32));
- buffer.put ((byte) (value >> 24));
- buffer.put ((byte) (value >> 16));
- buffer.put ((byte) (value >> 8));
- buffer.put ((byte) value);
- }
- }
-
- public static long getLong (ByteBuffer buffer, int index, ByteOrder order)
- {
- checkAvailableForRead (buffer, index, 8);
-
- if (order == ByteOrder.LITTLE_ENDIAN)
- {
- return ((buffer.get (index) & 0xff)
- + ((buffer.get (++index) & 0xff) << 8)
- + ((buffer.get (++index) & 0xff) << 16)
- + ((buffer.get (++index) & 0xffL) << 24)
- + ((buffer.get (++index) & 0xffL) << 32)
- + ((buffer.get (++index) & 0xffL) << 40)
- + ((buffer.get (++index) & 0xffL) << 48)
- + (((long) buffer.get (++index)) << 56));
- }
-
- return ((((long) buffer.get (index)) << 56)
- + ((buffer.get (++index) & 0xffL) << 48)
- + ((buffer.get (++index) & 0xffL) << 40)
- + ((buffer.get (++index) & 0xffL) << 32)
- + ((buffer.get (++index) & 0xffL) << 24)
- + ((buffer.get (++index) & 0xff) << 16)
- + ((buffer.get (++index) & 0xff) << 8)
- + (buffer.get (++index) & 0xff));
- }
-
- public static void putLong (ByteBuffer buffer, int index,
- long value, ByteOrder order)
- {
- checkAvailableForWrite (buffer, index, 8);
-
- if (order == ByteOrder.LITTLE_ENDIAN)
- {
- buffer.put (index, (byte) value);
- buffer.put (++index, (byte) (value >> 8));
- buffer.put (++index, (byte) (value >> 16));
- buffer.put (++index, (byte) (value >> 24));
- buffer.put (++index, (byte) (value >> 32));
- buffer.put (++index, (byte) (value >> 40));
- buffer.put (++index, (byte) (value >> 48));
- buffer.put (++index, (byte) (value >> 56));
- }
- else
- {
- buffer.put (index, (byte) (value >> 56));
- buffer.put (++index, (byte) (value >> 48));
- buffer.put (++index, (byte) (value >> 40));
- buffer.put (++index, (byte) (value >> 32));
- buffer.put (++index, (byte) (value >> 24));
- buffer.put (++index, (byte) (value >> 16));
- buffer.put (++index, (byte) (value >> 8));
- buffer.put (++index, (byte) value);
- }
- }
-
- public static float getFloat (ByteBuffer buffer, ByteOrder order)
- {
- return Float.intBitsToFloat (getInt (buffer, order));
- }
-
- public static void putFloat (ByteBuffer buffer, float value, ByteOrder order)
- {
- putInt (buffer, Float.floatToRawIntBits (value), order);
- }
-
- public static float getFloat (ByteBuffer buffer, int index, ByteOrder order)
- {
- return Float.intBitsToFloat (getInt (buffer, index, order));
- }
-
- public static void putFloat (ByteBuffer buffer, int index,
- float value, ByteOrder order)
- {
- putInt (buffer, index, Float.floatToRawIntBits (value), order);
- }
-
- public static double getDouble (ByteBuffer buffer, ByteOrder order)
- {
- return Double.longBitsToDouble (getLong (buffer, order));
- }
-
- public static void putDouble (ByteBuffer buffer, double value, ByteOrder order)
- {
- putLong (buffer, Double.doubleToLongBits (value), order);
- }
-
- public static double getDouble (ByteBuffer buffer, int index, ByteOrder order)
- {
- return Double.longBitsToDouble (getLong (buffer, index, order));
- }
-
- public static void putDouble (ByteBuffer buffer, int index,
- double value, ByteOrder order)
- {
- putLong (buffer, index, Double.doubleToLongBits (value), order);
- }
-} // ByteBufferHelper
Index: java/nio/ByteBufferImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/ByteBufferImpl.java,v
retrieving revision 1.6
diff -u -p -r1.6 ByteBufferImpl.java
--- java/nio/ByteBufferImpl.java 16 Feb 2004 20:00:33 -0000 1.6
+++ java/nio/ByteBufferImpl.java 18 Mar 2004 00:10:23 -0000
@@ -37,6 +37,7 @@ exception statement from your version. *
package java.nio;
+import gnu.java.nio.*;
/**
* This is a Heap memory implementation
Index: java/nio/CharViewBufferImpl.java
===================================================================
RCS file: java/nio/CharViewBufferImpl.java
diff -N java/nio/CharViewBufferImpl.java
--- java/nio/CharViewBufferImpl.java 16 Feb 2004 19:54:49 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,162 +0,0 @@
-/* CharViewBufferImpl.java --
- Copyright (C) 2003, 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.nio;
-
-class CharViewBufferImpl extends CharBuffer
-{
- /** Position in bb (i.e. a byte offset) where this buffer starts. */
- private int offset;
- private ByteBuffer bb;
- private boolean readOnly;
- private ByteOrder endian;
-
- CharViewBufferImpl (ByteBuffer bb, int capacity)
- {
- super (capacity, capacity, 0, -1);
- this.bb = bb;
- this.offset = bb.position();
- this.readOnly = bb.isReadOnly();
- this.endian = bb.order();
- }
-
- public CharViewBufferImpl (ByteBuffer bb, int offset, int capacity,
- int limit, int position, int mark,
- boolean readOnly, ByteOrder endian)
- {
- super (capacity, limit, position, mark);
- this.bb = bb;
- this.offset = offset;
- this.readOnly = readOnly;
- this.endian = endian;
- }
-
- public char get ()
- {
- int p = position();
- char result = ByteBufferHelper.getChar(bb, (p << 1) + offset, endian);
- position(p + 1);
- return result;
- }
-
- public char get (int index)
- {
- return ByteBufferHelper.getChar(bb, (index << 1) + offset, endian);
- }
-
- public CharBuffer put (char value)
- {
- int p = position();
- ByteBufferHelper.putChar(bb, (p << 1) + offset, value, endian);
- position(p + 1);
- return this;
- }
-
- public CharBuffer put (int index, char value)
- {
- ByteBufferHelper.putChar(bb, (index << 1) + offset, value, endian);
- return this;
- }
-
- public CharBuffer compact ()
- {
- if (position () > 0)
- {
- int count = limit () - position ();
- bb.shiftDown(offset, offset + 2 * position(), 2 * count);
- position (count);
- limit (capacity ());
- }
- return this;
- }
-
- public CharBuffer slice ()
- {
- // Create a sliced copy of this object that shares its content.
- return new CharViewBufferImpl (bb, (position () >> 1) + offset,
- remaining (), remaining (), 0, -1,
- isReadOnly (), endian);
- }
-
- CharBuffer duplicate (boolean readOnly)
- {
- int pos = position();
- reset();
- int mark = position();
- position(pos);
- return new CharViewBufferImpl (bb, offset, capacity(), limit(),
- pos, mark, readOnly, endian);
- }
-
- public CharBuffer duplicate ()
- {
- return duplicate(readOnly);
- }
-
- public CharBuffer asReadOnlyBuffer ()
- {
- return duplicate(true);
- }
-
- public CharSequence subSequence (int start, int end)
- {
- if (start < 0
- || end < start
- || end > length ())
- throw new IndexOutOfBoundsException ();
-
- return new CharViewBufferImpl (bb, array_offset, capacity (),
- position () + end, position () + start,
- -1, isReadOnly (), endian);
- }
-
- public boolean isReadOnly ()
- {
- return readOnly;
- }
-
- public boolean isDirect ()
- {
- return bb.isDirect ();
- }
-
- public ByteOrder order ()
- {
- return endian;
- }
-}
Index: java/nio/DirectByteBufferImpl.java
===================================================================
RCS file: java/nio/DirectByteBufferImpl.java
diff -N java/nio/DirectByteBufferImpl.java
--- java/nio/DirectByteBufferImpl.java 16 Feb 2004 20:00:33 -0000 1.8
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,363 +0,0 @@
-/* DirectByteBufferImpl.java --
- Copyright (C) 2003, 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.nio;
-
-import gnu.classpath.Configuration;
-import gnu.gcj.RawData;
-
-class DirectByteBufferImpl extends ByteBuffer
-{
- static
- {
- // load the shared library needed for native methods.
- if (Configuration.INIT_LOAD_LIBRARY)
- {
- System.loadLibrary ("javanio");
- }
- }
-
- /** Used by MappedByteBufferImpl to prevent premature GC. */
- protected Object owner;
-
- RawData address;
- private boolean readOnly;
-
- public DirectByteBufferImpl (RawData address, long len)
- {
- this (null, address, (int) len, (int) len, 0, false);
- }
-
- public DirectByteBufferImpl (Object owner, RawData address,
- int capacity, int limit,
- int position, boolean readOnly)
- {
- super (capacity, limit, position, -1);
- this.address = address;
- this.readOnly = readOnly;
- this.owner = owner;
- }
-
- private static native RawData allocateImpl (int capacity);
- private static native void freeImpl (RawData address);
-
- protected void finalize () throws Throwable
- {
- freeImpl (address);
- }
-
- static native byte getImpl (RawData address, int index);
- static native void putImpl (RawData address, int index, byte value);
-
- public byte get ()
- {
- int pos = position();
- if (pos >= limit())
- throw new BufferUnderflowException();
- byte result = getImpl (address, pos);
- position (pos + 1);
- return result;
- }
-
- public byte get (int index)
- {
- if (index >= limit())
- throw new BufferUnderflowException();
- return getImpl (address, index);
- }
-
- static native void getImpl (RawData address, int index,
- byte[] dst, int offset, int length);
-
- public ByteBuffer get (byte[] dst, int offset, int length)
- {
- if (offset < 0 || length < 0 || offset + length > dst.length)
- throw new IndexOutOfBoundsException ();
- if (length > remaining())
- throw new BufferUnderflowException();
-
- int index = position();
- getImpl(address, index, dst, offset, length);
- position(index+length);
-
- return this;
- }
-
- public ByteBuffer put (byte value)
- {
- int pos = position();
- if (pos >= limit())
- throw new BufferUnderflowException();
- putImpl (address, pos, value);
- position (pos + 1);
- return this;
- }
-
- public ByteBuffer put (int index, byte value)
- {
- if (index >= limit())
- throw new BufferUnderflowException();
- putImpl (address, index, value);
- return this;
- }
-
- native void shiftDown (int dst_offset, int src_offset, int count);
-
- public ByteBuffer compact ()
- {
- int pos = position();
- if (pos > 0)
- {
- int count = remaining();
- shiftDown(0, pos, count);
- position(count);
- limit(capacity());
- }
- return this;
- }
-
- public static native RawData adjustAddress(RawData address, int offset);
-
- public ByteBuffer slice ()
- {
- int rem = remaining();
- return new DirectByteBufferImpl (owner,
- adjustAddress(address, position()),
- rem, rem, 0, isReadOnly ());
- }
-
- private ByteBuffer duplicate (boolean readOnly)
- {
- int pos = position();
- reset();
- int mark = position();
- position(pos);
- DirectByteBufferImpl result
- = new DirectByteBufferImpl (owner, address, capacity (), limit (),
- pos, readOnly);
- if (mark != pos)
- {
- result.position(mark);
- result.mark();
- result.position(pos);
- }
- return result;
- }
-
- public ByteBuffer duplicate ()
- {
- return duplicate(isReadOnly());
- }
-
- public ByteBuffer asReadOnlyBuffer ()
- {
- return duplicate(true);
- }
-
- public boolean isReadOnly ()
- {
- return readOnly;
- }
-
- public boolean isDirect ()
- {
- return true;
- }
-
- public CharBuffer asCharBuffer ()
- {
- return new CharViewBufferImpl (this, remaining() >> 1);
- }
-
- public ShortBuffer asShortBuffer ()
- {
- return new ShortViewBufferImpl (this, remaining() >> 1);
- }
-
- public IntBuffer asIntBuffer ()
- {
- return new IntViewBufferImpl (this, remaining() >> 2);
- }
-
- public LongBuffer asLongBuffer ()
- {
- return new LongViewBufferImpl (this, remaining() >> 3);
- }
-
- public FloatBuffer asFloatBuffer ()
- {
- return new FloatViewBufferImpl (this, remaining() >> 2);
- }
-
- public DoubleBuffer asDoubleBuffer ()
- {
- return new DoubleViewBufferImpl (this, remaining() >> 3);
- }
-
- final public char getChar ()
- {
- return ByteBufferHelper.getChar(this, order());
- }
-
- final public ByteBuffer putChar (char value)
- {
- ByteBufferHelper.putChar(this, value, order());
- return this;
- }
-
- final public char getChar (int index)
- {
- return ByteBufferHelper.getChar(this, index, order());
- }
-
- final public ByteBuffer putChar (int index, char value)
- {
- ByteBufferHelper.putChar(this, index, value, order());
- return this;
- }
-
- final public short getShort ()
- {
- return ByteBufferHelper.getShort(this, order());
- }
-
- final public ByteBuffer putShort (short value)
- {
- ByteBufferHelper.putShort(this, value, order());
- return this;
- }
-
- final public short getShort (int index)
- {
- return ByteBufferHelper.getShort(this, index, order());
- }
-
- final public ByteBuffer putShort (int index, short value)
- {
- ByteBufferHelper.putShort(this, index, value, order());
- return this;
- }
-
- final public int getInt ()
- {
- return ByteBufferHelper.getInt(this, order());
- }
-
- final public ByteBuffer putInt (int value)
- {
- ByteBufferHelper.putInt(this, value, order());
- return this;
- }
-
- final public int getInt (int index)
- {
- return ByteBufferHelper.getInt(this, index, order());
- }
-
- final public ByteBuffer putInt (int index, int value)
- {
- ByteBufferHelper.putInt(this, index, value, order());
- return this;
- }
-
- final public long getLong ()
- {
- return ByteBufferHelper.getLong(this, order());
- }
-
- final public ByteBuffer putLong (long value)
- {
- ByteBufferHelper.putLong (this, value, order());
- return this;
- }
-
- final public long getLong (int index)
- {
- return ByteBufferHelper.getLong (this, index, order());
- }
-
- final public ByteBuffer putLong (int index, long value)
- {
- ByteBufferHelper.putLong (this, index, value, order());
- return this;
- }
-
- final public float getFloat ()
- {
- return ByteBufferHelper.getFloat (this, order());
- }
-
- final public ByteBuffer putFloat (float value)
- {
- ByteBufferHelper.putFloat (this, value, order());
- return this;
- }
-
- public final float getFloat (int index)
- {
- return ByteBufferHelper.getFloat (this, index, order());
- }
-
- final public ByteBuffer putFloat (int index, float value)
- {
- ByteBufferHelper.putFloat (this, index, value, order());
- return this;
- }
-
- final public double getDouble ()
- {
- return ByteBufferHelper.getDouble (this, order());
- }
-
- final public ByteBuffer putDouble (double value)
- {
- ByteBufferHelper.putDouble (this, value, order());
- return this;
- }
-
- final public double getDouble (int index)
- {
- return ByteBufferHelper.getDouble (this, index, order());
- }
-
- final public ByteBuffer putDouble (int index, double value)
- {
- ByteBufferHelper.putDouble (this, index, value, order());
- return this;
- }
-}
Index: java/nio/DoubleViewBufferImpl.java
===================================================================
RCS file: java/nio/DoubleViewBufferImpl.java
diff -N java/nio/DoubleViewBufferImpl.java
--- java/nio/DoubleViewBufferImpl.java 16 Feb 2004 19:54:49 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,149 +0,0 @@
-/* DoubleViewBufferImpl.java --
- Copyright (C) 2003, 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.nio;
-
-class DoubleViewBufferImpl extends DoubleBuffer
-{
- /** Position in bb (i.e. a byte offset) where this buffer starts. */
- private int offset;
- private ByteBuffer bb;
- private boolean readOnly;
- private ByteOrder endian;
-
- DoubleViewBufferImpl (ByteBuffer bb, int capacity)
- {
- super (capacity, capacity, 0, -1);
- this.bb = bb;
- this.offset = bb.position();
- this.readOnly = bb.isReadOnly();
- this.endian = bb.order();
- }
-
- public DoubleViewBufferImpl (ByteBuffer bb, int offset, int capacity,
- int limit, int position, int mark,
- boolean readOnly, ByteOrder endian)
- {
- super (capacity, limit, position, mark);
- this.bb = bb;
- this.offset = offset;
- this.readOnly = readOnly;
- this.endian = endian;
- }
-
- public double get ()
- {
- int p = position();
- double result = ByteBufferHelper.getDouble(bb, (p << 3) + offset, endian);
- position(p + 1);
- return result;
- }
-
- public double get (int index)
- {
- return ByteBufferHelper.getDouble(bb, (index << 3) + offset, endian);
- }
-
- public DoubleBuffer put (double value)
- {
- int p = position();
- ByteBufferHelper.putDouble(bb, (p << 3) + offset, value, endian);
- position(p + 1);
- return this;
- }
-
- public DoubleBuffer put (int index, double value)
- {
- ByteBufferHelper.putDouble(bb, (index << 3) + offset, value, endian);
- return this;
- }
-
- public DoubleBuffer compact ()
- {
- if (position () > 0)
- {
- int count = limit () - position ();
- bb.shiftDown(offset, offset + 8 * position(), 8 * count);
- position (count);
- limit (capacity ());
- }
- return this;
- }
-
- public DoubleBuffer slice ()
- {
- return new DoubleViewBufferImpl (bb, (position () >> 3) + offset,
- remaining(), remaining(), 0, -1,
- readOnly, endian);
- }
-
- DoubleBuffer duplicate (boolean readOnly)
- {
- int pos = position();
- reset();
- int mark = position();
- position(pos);
- return new DoubleViewBufferImpl (bb, offset, capacity(), limit(),
- pos, mark, readOnly, endian);
- }
-
- public DoubleBuffer duplicate ()
- {
- return duplicate(readOnly);
- }
-
- public DoubleBuffer asReadOnlyBuffer ()
- {
- return duplicate(true);
- }
-
- public boolean isReadOnly ()
- {
- return readOnly;
- }
-
- public boolean isDirect ()
- {
- return bb.isDirect ();
- }
-
- public ByteOrder order ()
- {
- return endian;
- }
-}
Index: java/nio/FloatViewBufferImpl.java
===================================================================
RCS file: java/nio/FloatViewBufferImpl.java
diff -N java/nio/FloatViewBufferImpl.java
--- java/nio/FloatViewBufferImpl.java 16 Feb 2004 19:54:49 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,150 +0,0 @@
-/* FloatViewBufferImpl.java --
- Copyright (C) 2003, 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.nio;
-
-class FloatViewBufferImpl extends FloatBuffer
-{
- /** Position in bb (i.e. a byte offset) where this buffer starts. */
- private int offset;
- private ByteBuffer bb;
- private boolean readOnly;
- private ByteOrder endian;
-
- FloatViewBufferImpl (ByteBuffer bb, int capacity)
- {
- super (capacity, capacity, 0, -1);
- this.bb = bb;
- this.offset = bb.position();
- this.readOnly = bb.isReadOnly();
- this.endian = bb.order();
- }
-
- public FloatViewBufferImpl (ByteBuffer bb, int offset, int capacity,
- int limit, int position, int mark,
- boolean readOnly, ByteOrder endian)
- {
- super (capacity, limit, position, mark);
- this.bb = bb;
- this.offset = offset;
- this.readOnly = readOnly;
- this.endian = endian;
- }
-
- public float get ()
- {
- int p = position();
- float result = ByteBufferHelper.getFloat(bb, (p << 2) + offset, endian);
- position(p + 1);
- return result;
- }
-
- public float get (int index)
- {
- return ByteBufferHelper.getFloat(bb, (index << 2) + offset, endian);
- }
-
- public FloatBuffer put (float value)
- {
- int p = position();
- ByteBufferHelper.putFloat(bb, (p << 2) + offset, value, endian);
- position(p + 1);
- return this;
- }
-
- public FloatBuffer put (int index, float value)
- {
- ByteBufferHelper.putFloat(bb, (index << 2) + offset, value, endian);
- return this;
- }
-
- public FloatBuffer compact ()
- {
- if (position () > 0)
- {
- int count = limit () - position ();
- bb.shiftDown(offset, offset + 4 * position(), 4 * count);
- position (count);
- limit (capacity ());
- }
- return this;
- }
-
- public FloatBuffer slice ()
- {
- // Create a sliced copy of this object that shares its content.
- return new FloatViewBufferImpl (bb, (position () >> 2) + offset,
- remaining(), remaining(), 0, -1,
- readOnly, endian);
- }
-
- FloatBuffer duplicate (boolean readOnly)
- {
- int pos = position();
- reset();
- int mark = position();
- position(pos);
- return new FloatViewBufferImpl (bb, offset, capacity(), limit(),
- pos, mark, readOnly, endian);
- }
-
- public FloatBuffer duplicate ()
- {
- return duplicate(readOnly);
- }
-
- public FloatBuffer asReadOnlyBuffer ()
- {
- return duplicate(true);
- }
-
- public boolean isReadOnly ()
- {
- return readOnly;
- }
-
- public boolean isDirect ()
- {
- return bb.isDirect ();
- }
-
- public ByteOrder order ()
- {
- return endian;
- }
-}
Index: java/nio/IntViewBufferImpl.java
===================================================================
RCS file: java/nio/IntViewBufferImpl.java
diff -N java/nio/IntViewBufferImpl.java
--- java/nio/IntViewBufferImpl.java 16 Feb 2004 19:54:49 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,150 +0,0 @@
-/* IntViewBufferImpl.java --
- Copyright (C) 2003, 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.nio;
-
-class IntViewBufferImpl extends IntBuffer
-{
- /** Position in bb (i.e. a byte offset) where this buffer starts. */
- private int offset;
- private ByteBuffer bb;
- private boolean readOnly;
- private ByteOrder endian;
-
- IntViewBufferImpl (ByteBuffer bb, int capacity)
- {
- super (capacity, capacity, 0, -1);
- this.bb = bb;
- this.offset = bb.position();
- this.readOnly = bb.isReadOnly();
- this.endian = bb.order();
- }
-
- public IntViewBufferImpl (ByteBuffer bb, int offset, int capacity,
- int limit, int position, int mark,
- boolean readOnly, ByteOrder endian)
- {
- super (capacity, limit, position, mark);
- this.bb = bb;
- this.offset = offset;
- this.readOnly = readOnly;
- this.endian = endian;
- }
-
- public int get ()
- {
- int p = position();
- int result = ByteBufferHelper.getInt(bb, (p << 2) + offset, endian);
- position(p + 1);
- return result;
- }
-
- public int get (int index)
- {
- return ByteBufferHelper.getInt(bb, (index << 2) + offset, endian);
- }
-
- public IntBuffer put (int value)
- {
- int p = position();
- ByteBufferHelper.putInt(bb, (p << 2) + offset, value, endian);
- position(p + 1);
- return this;
- }
-
- public IntBuffer put (int index, int value)
- {
- ByteBufferHelper.putInt(bb, (index << 2) + offset, value, endian);
- return this;
- }
-
- public IntBuffer compact ()
- {
- if (position () > 0)
- {
- int count = limit () - position ();
- bb.shiftDown(offset, offset + 4 * position(), 4 * count);
- position (count);
- limit (capacity ());
- }
- return this;
- }
-
- public IntBuffer slice ()
- {
- // Create a sliced copy of this object that shares its content.
- return new IntViewBufferImpl (bb, (position () >> 2) + offset,
- remaining(), remaining(), 0, -1,
- readOnly, endian);
- }
-
- IntBuffer duplicate (boolean readOnly)
- {
- int pos = position();
- reset();
- int mark = position();
- position(pos);
- return new IntViewBufferImpl (bb, offset, capacity(), limit(),
- pos, mark, readOnly, endian);
- }
-
- public IntBuffer duplicate ()
- {
- return duplicate(readOnly);
- }
-
- public IntBuffer asReadOnlyBuffer ()
- {
- return duplicate(true);
- }
-
- public boolean isReadOnly ()
- {
- return readOnly;
- }
-
- public boolean isDirect ()
- {
- return bb.isDirect ();
- }
-
- public ByteOrder order ()
- {
- return endian;
- }
-}
Index: java/nio/LongViewBufferImpl.java
===================================================================
RCS file: java/nio/LongViewBufferImpl.java
diff -N java/nio/LongViewBufferImpl.java
--- java/nio/LongViewBufferImpl.java 16 Feb 2004 19:54:49 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,150 +0,0 @@
-/* LongViewBufferImpl.java --
- Copyright (C) 2003, 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.nio;
-
-class LongViewBufferImpl extends LongBuffer
-{
- /** Position in bb (i.e. a byte offset) where this buffer starts. */
- private int offset;
- private ByteBuffer bb;
- private boolean readOnly;
- private ByteOrder endian;
-
- LongViewBufferImpl (ByteBuffer bb, int capacity)
- {
- super (capacity, capacity, 0, -1);
- this.bb = bb;
- this.offset = bb.position();
- this.readOnly = bb.isReadOnly();
- this.endian = bb.order();
- }
-
- public LongViewBufferImpl (ByteBuffer bb, int offset, int capacity,
- int limit, int position, int mark,
- boolean readOnly, ByteOrder endian)
- {
- super (capacity, limit, position, mark);
- this.bb = bb;
- this.offset = offset;
- this.readOnly = readOnly;
- this.endian = endian;
- }
-
- public long get ()
- {
- int p = position();
- long result = ByteBufferHelper.getLong(bb, (p << 3) + offset, endian);
- position(p + 1);
- return result;
- }
-
- public long get (int index)
- {
- return ByteBufferHelper.getLong(bb, (index << 3) + offset, endian);
- }
-
- public LongBuffer put (long value)
- {
- int p = position();
- ByteBufferHelper.putLong(bb, (p << 3) + offset, value, endian);
- position(p + 1);
- return this;
- }
-
- public LongBuffer put (int index, long value)
- {
- ByteBufferHelper.putLong(bb, (index << 3) + offset, value, endian);
- return this;
- }
-
- public LongBuffer compact ()
- {
- if (position () > 0)
- {
- int count = limit () - position ();
- bb.shiftDown(offset, offset + 8 * position(), 8 * count);
- position (count);
- limit (capacity ());
- }
- return this;
- }
-
- public LongBuffer slice ()
- {
- // Create a sliced copy of this object that shares its content.
- return new LongViewBufferImpl (bb, (position () >> 3) + offset,
- remaining(), remaining(), 0, -1,
- readOnly, endian);
- }
-
- LongBuffer duplicate (boolean readOnly)
- {
- int pos = position();
- reset();
- int mark = position();
- position(pos);
- return new LongViewBufferImpl (bb, offset, capacity(), limit(),
- pos, mark, readOnly, endian);
- }
-
- public LongBuffer duplicate ()
- {
- return duplicate(readOnly);
- }
-
- public LongBuffer asReadOnlyBuffer ()
- {
- return duplicate(true);
- }
-
- public boolean isReadOnly ()
- {
- return readOnly;
- }
-
- public boolean isDirect ()
- {
- return bb.isDirect ();
- }
-
- public ByteOrder order ()
- {
- return endian;
- }
-}
Index: java/nio/MappedByteBufferImpl.java
===================================================================
RCS file: java/nio/MappedByteBufferImpl.java
diff -N java/nio/MappedByteBufferImpl.java
--- java/nio/MappedByteBufferImpl.java 29 Feb 2004 19:12:45 -0000 1.7
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,344 +0,0 @@
-/* MappedByteBufferImpl.java --
- Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.nio;
-
-import java.io.IOException;
-import gnu.java.nio.channels.FileChannelImpl;
-import gnu.gcj.RawData;
-
-class MappedByteBufferImpl extends MappedByteBuffer
-{
- boolean readOnly;
- RawData address;
-
- /** Posix uses this for the pointer returned by mmap;
- * Win32 uses it for the pointer returned by MapViewOfFile. */
- public RawData implPtr;
- /** Posix uses this for the actual length passed to mmap;
- * Win32 uses it for the pointer returned by CreateFileMapping. */
- public long implLen;
-
- public MappedByteBufferImpl (RawData address, int size, boolean readOnly)
- throws IOException
- {
- super(size, size, 0, -1);
- this.address = address;
- this.readOnly = readOnly;
- }
-
- public boolean isReadOnly ()
- {
- return readOnly;
- }
-
- public byte get ()
- {
- int pos = position();
- if (pos >= limit())
- throw new BufferUnderflowException();
- byte result = DirectByteBufferImpl.getImpl(address, pos);
- position (pos + 1);
- return result;
- }
-
- public ByteBuffer put (byte value)
- {
- int pos = position();
- if (pos >= limit())
- throw new BufferUnderflowException();
- DirectByteBufferImpl.putImpl(address, pos, value);
- position(pos + 1);
- return this;
- }
-
- public byte get (int index)
- {
- if (index >= limit())
- throw new BufferUnderflowException();
- return DirectByteBufferImpl.getImpl(address, index);
- }
-
- public ByteBuffer get (byte[] dst, int offset, int length)
- {
- if (offset < 0 || length < 0 || offset + length > dst.length)
- throw new IndexOutOfBoundsException ();
- if (length > remaining())
- throw new BufferUnderflowException();
-
- int index = position();
- DirectByteBufferImpl.getImpl(address, index, dst, offset, length);
- position(index+length);
-
- return this;
- }
-
- public ByteBuffer put (int index, byte value)
- {
- if (index >= limit())
- throw new BufferUnderflowException();
- DirectByteBufferImpl.putImpl(address, index, value);
- return this;
- }
-
- public ByteBuffer compact ()
- {
- int pos = position();
- if (pos > 0)
- {
- int count = remaining();
- shiftDown(0, pos, count);
- position(count);
- limit(capacity());
- }
- return this;
- }
-
- public boolean isDirect ()
- {
- return true;
- }
-
- public ByteBuffer slice ()
- {
- int rem = remaining();
- return new DirectByteBufferImpl (this,
- DirectByteBufferImpl
- .adjustAddress(address, position()),
- rem, rem, 0, isReadOnly ());
- }
-
- private ByteBuffer duplicate (boolean readOnly)
- {
- int pos = position();
- reset();
- int mark = position();
- position(pos);
- DirectByteBufferImpl result
- = new DirectByteBufferImpl (this, address, capacity (), limit (),
- pos, readOnly);
- if (mark != pos)
- {
- result.position(mark);
- result.mark();
- result.position(pos);
- }
- return result;
- }
-
- public ByteBuffer duplicate ()
- {
- return duplicate(isReadOnly());
- }
-
- public ByteBuffer asReadOnlyBuffer ()
- {
- return duplicate(true);
- }
-
- public CharBuffer asCharBuffer ()
- {
- return new CharViewBufferImpl (this, remaining() >> 1);
- }
-
- public ShortBuffer asShortBuffer ()
- {
- return new ShortViewBufferImpl (this, remaining() >> 1);
- }
-
- public IntBuffer asIntBuffer ()
- {
- return new IntViewBufferImpl (this, remaining() >> 2);
- }
-
- public LongBuffer asLongBuffer ()
- {
- return new LongViewBufferImpl (this, remaining() >> 3);
- }
-
- public FloatBuffer asFloatBuffer ()
- {
- return new FloatViewBufferImpl (this, remaining() >> 2);
- }
-
- public DoubleBuffer asDoubleBuffer ()
- {
- return new DoubleViewBufferImpl (this, remaining() >> 3);
- }
-
- final public char getChar ()
- {
- return ByteBufferHelper.getChar(this, order());
- }
-
- final public ByteBuffer putChar (char value)
- {
- ByteBufferHelper.putChar(this, value, order());
- return this;
- }
-
- final public char getChar (int index)
- {
- return ByteBufferHelper.getChar(this, index, order());
- }
-
- final public ByteBuffer putChar (int index, char value)
- {
- ByteBufferHelper.putChar(this, index, value, order());
- return this;
- }
-
- final public short getShort ()
- {
- return ByteBufferHelper.getShort(this, order());
- }
-
- final public ByteBuffer putShort (short value)
- {
- ByteBufferHelper.putShort(this, value, order());
- return this;
- }
-
- final public short getShort (int index)
- {
- return ByteBufferHelper.getShort(this, index, order());
- }
-
- final public ByteBuffer putShort (int index, short value)
- {
- ByteBufferHelper.putShort(this, index, value, order());
- return this;
- }
-
- final public int getInt ()
- {
- return ByteBufferHelper.getInt(this, order());
- }
-
- final public ByteBuffer putInt (int value)
- {
- ByteBufferHelper.putInt(this, value, order());
- return this;
- }
-
- final public int getInt (int index)
- {
- return ByteBufferHelper.getInt(this, index, order());
- }
-
- final public ByteBuffer putInt (int index, int value)
- {
- ByteBufferHelper.putInt(this, index, value, order());
- return this;
- }
-
- final public long getLong ()
- {
- return ByteBufferHelper.getLong(this, order());
- }
-
- final public ByteBuffer putLong (long value)
- {
- ByteBufferHelper.putLong (this, value, order());
- return this;
- }
-
- final public long getLong (int index)
- {
- return ByteBufferHelper.getLong (this, index, order());
- }
-
- final public ByteBuffer putLong (int index, long value)
- {
- ByteBufferHelper.putLong (this, index, value, order());
- return this;
- }
-
- final public float getFloat ()
- {
- return ByteBufferHelper.getFloat (this, order());
- }
-
- final public ByteBuffer putFloat (float value)
- {
- ByteBufferHelper.putFloat (this, value, order());
- return this;
- }
-
- public final float getFloat (int index)
- {
- return ByteBufferHelper.getFloat (this, index, order());
- }
-
- final public ByteBuffer putFloat (int index, float value)
- {
- ByteBufferHelper.putFloat (this, index, value, order());
- return this;
- }
-
- final public double getDouble ()
- {
- return ByteBufferHelper.getDouble (this, order());
- }
-
- final public ByteBuffer putDouble (double value)
- {
- ByteBufferHelper.putDouble (this, value, order());
- return this;
- }
-
- final public double getDouble (int index)
- {
- return ByteBufferHelper.getDouble (this, index, order());
- }
-
- final public ByteBuffer putDouble (int index, double value)
- {
- ByteBufferHelper.putDouble (this, index, value, order());
- return this;
- }
-
- // NOTE: In libgcj these methods are implemented in natFileChannelXxx.cc,
- // because they're small, and to put them next to FileChannelImpl::mapImpl.
- native void unmapImpl ();
- native boolean isLoadedImpl ();
- // FIXME: Try to load all pages into memory.
- native void loadImpl();
-
- native void forceImpl();
-}
Index: java/nio/ShortViewBufferImpl.java
===================================================================
RCS file: java/nio/ShortViewBufferImpl.java
diff -N java/nio/ShortViewBufferImpl.java
--- java/nio/ShortViewBufferImpl.java 16 Feb 2004 19:54:49 -0000 1.3
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,150 +0,0 @@
-/* ShortViewBufferImpl.java --
- Copyright (C) 2003, 2004 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-
-package java.nio;
-
-class ShortViewBufferImpl extends ShortBuffer
-{
- /** Position in bb (i.e. a byte offset) where this buffer starts. */
- private int offset;
- private ByteBuffer bb;
- private boolean readOnly;
- private ByteOrder endian;
-
- ShortViewBufferImpl (ByteBuffer bb, int capacity)
- {
- super (capacity, capacity, 0, -1);
- this.bb = bb;
- this.offset = bb.position();
- this.readOnly = bb.isReadOnly();
- this.endian = bb.order();
- }
-
- public ShortViewBufferImpl (ByteBuffer bb, int offset, int capacity,
- int limit, int position, int mark,
- boolean readOnly, ByteOrder endian)
- {
- super (capacity, limit, position, mark);
- this.bb = bb;
- this.offset = offset;
- this.readOnly = readOnly;
- this.endian = endian;
- }
-
- public short get ()
- {
- int p = position();
- short result = ByteBufferHelper.getShort(bb, (p << 1) + offset, endian);
- position(p + 1);
- return result;
- }
-
- public short get (int index)
- {
- return ByteBufferHelper.getShort(bb, (index << 1) + offset, endian);
- }
-
- public ShortBuffer put (short value)
- {
- int p = position();
- ByteBufferHelper.putShort(bb, (p << 1) + offset, value, endian);
- position(p + 1);
- return this;
- }
-
- public ShortBuffer put (int index, short value)
- {
- ByteBufferHelper.putShort(bb, (index << 1) + offset, value, endian);
- return this;
- }
-
- public ShortBuffer compact ()
- {
- if (position () > 0)
- {
- int count = limit () - position ();
- bb.shiftDown(offset, offset + 2 * position(), 2 * count);
- position (count);
- limit (capacity ());
- }
- return this;
- }
-
- public ShortBuffer slice ()
- {
- // Create a sliced copy of this object that shares its content.
- return new ShortViewBufferImpl (bb, (position () >> 1) + offset,
- remaining(), remaining(), 0, -1,
- readOnly, endian);
- }
-
- ShortBuffer duplicate (boolean readOnly)
- {
- int pos = position();
- reset();
- int mark = position();
- position(pos);
- return new ShortViewBufferImpl (bb, offset, capacity(), limit(),
- pos, mark, readOnly, endian);
- }
-
- public ShortBuffer duplicate ()
- {
- return duplicate(readOnly);
- }
-
- public ShortBuffer asReadOnlyBuffer ()
- {
- return duplicate(true);
- }
-
- public boolean isReadOnly ()
- {
- return readOnly;
- }
-
- public boolean isDirect ()
- {
- return bb.isDirect ();
- }
-
- public ByteOrder order ()
- {
- return endian;
- }
-}
Index: java/nio/natDirectByteBufferImpl.cc
===================================================================
RCS file: java/nio/natDirectByteBufferImpl.cc
diff -N java/nio/natDirectByteBufferImpl.cc
--- java/nio/natDirectByteBufferImpl.cc 16 Feb 2004 20:00:33 -0000 1.4
+++ /dev/null 1 Jan 1970 00:00:00 -0000
@@ -1,73 +0,0 @@
-// natDirectByteBufferImpl.cc
-
-/* Copyright (C) 2003, 2004 Free Software Foundation
-
- This file is part of libgcj.
-
-This software is copyrighted work licensed under the terms of the
-Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
-details. */
-
-#include <config.h>
-
-#include <gcj/cni.h>
-#include <jvm.h>
-
-#include <stdlib.h>
-
-#include <gnu/gcj/RawData.h>
-#include <java/nio/DirectByteBufferImpl.h>
-
-using gnu::gcj::RawData;
-using java::nio::DirectByteBufferImpl;
-
-RawData*
-java::nio::DirectByteBufferImpl::allocateImpl (jint capacity)
-{
- return reinterpret_cast<gnu::gcj::RawData*> (::malloc (capacity));
-}
-
-void
-java::nio::DirectByteBufferImpl::freeImpl (gnu::gcj::RawData* address)
-{
- ::free (reinterpret_cast<void*> (address));
-}
-
-jbyte
-DirectByteBufferImpl::getImpl (RawData* address, jint index)
-{
- jbyte* pointer = reinterpret_cast<jbyte*> (address) + index;
- return *pointer;
-}
-
-void
-DirectByteBufferImpl::getImpl (RawData* address, jint index,
- jbyteArray dst, jint offset, jint length)
-{
- jbyte* src = reinterpret_cast<jbyte*> (address) + index;
- memcpy (elements (dst) + offset, src, length);
-}
-
-void
-java::nio::DirectByteBufferImpl::putImpl (gnu::gcj::RawData* address,
- jint index, jbyte value)
-{
- jbyte* pointer = reinterpret_cast<jbyte*> (address) + index;
- *pointer = value;
-}
-
-RawData*
-java::nio::DirectByteBufferImpl::adjustAddress (RawData* address, jint offset)
-{
- jbyte* start = reinterpret_cast<jbyte*> (address) + offset;
- return reinterpret_cast<RawData*>(start);
-}
-
-void
-java::nio::DirectByteBufferImpl::shiftDown
-(jint dst_offset, jint src_offset, jint count)
-{
- jbyte* dst = reinterpret_cast<jbyte*> (address) + array_offset + dst_offset;
- jbyte* src = reinterpret_cast<jbyte*> (address) + array_offset + src_offset;
- ::memmove(dst, src, count);
-}
Index: testsuite/Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/testsuite/Makefile.in,v
retrieving revision 1.53
diff -u -p -r1.53 Makefile.in
--- testsuite/Makefile.in 13 Jan 2004 17:37:23 -0000 1.53
+++ testsuite/Makefile.in 18 Mar 2004 00:10:24 -0000
@@ -172,7 +172,7 @@ RUNTEST = "`if [ -f $(top_srcdir)/../dej
AM_RUNTESTFLAGS = INTERPRETER=$(INTERPRETER)
CONFIG_HEADER = ../include/config.h ../gcj/libgcj-config.h
CONFIG_CLEAN_FILES =
-DIST_COMMON = ChangeLog Makefile.am Makefile.in
+DIST_COMMON = Makefile.am Makefile.in
DISTFILES = $(DIST_COMMON) $(SOURCES) $(HEADERS) $(TEXINFOS) $(EXTRA_DIST)