This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

FYI: Patch: java.nio


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


I commited the attached obvious patch to fix several bugs in java.nio.
This now means that there are no known bugs in the java.nio buffers 
implementation. Even direct buffers are supported via JNI.

Of course there is always one exception: Currently the buffers only 
work 100% on little endian architectures (i386). For big endian 
support I plan to rewrite some of the stuff. I will shift this as 
i386 is our main platform currently and I have not yet received a bug 
report about it :-).

I will now focus on the selector stuff to make CVS with selected 
network channels. There still some FileChannel features which need to 
be implemented later (locking, memory mappting, etc.).


Michael
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/K58YWSOgCCdjSDsRAhbmAJ0fd1hmTyPRuH3TT5QS9ROiNYuqVQCfY+U6
xtogCOvB7/ROCHQCeSzIBXQ=
=GwPH
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.2081
diff -u -b -B -r1.2081 ChangeLog
--- ChangeLog	2 Aug 2003 09:15:04 -0000	1.2081
+++ ChangeLog	2 Aug 2003 11:10:49 -0000
@@ -1,5 +1,54 @@
 2003-08-02  Michael Koch  <konqueror@gmx.de>
 
+	* java/nio/ByteBufferImpl.java
+	(getChar): Check remaining bytes, fixed comment about endianess.
+	(putChar): Likewise.
+	(getShort): Likewise.
+	(putShort): Likewise.
+	(getInt): Check remaining bytes, fixed conversion, fixed comment about
+	endianess.
+	(putInt): Likewise.
+	(getLong): Likewise.
+	(putLong): Likewise.
+	(getFloat): Likewise.
+	(putFloat): Likewise.
+	(getDouble): Likewise.
+	(putDouble): Likewise.
+	* java/nio/DirectByteBufferImpl.java
+	(getChar): Wrapped code, fixed comment about endianess.
+	(putchar): Likewise.
+	(getShort): Likewise.
+	(putShort): Likewise.
+	(getInt): Fixed conversion, fixed comment about endianess.
+	(putInt): Likewise.
+	(getLong): Likewise.
+	(putLong): Likewise.
+	(getFloat): Likewise.
+	(putFloat): Likewise.
+	(getDouble): Likewise.
+	(putDouble): Likewise.
+	* java/nio/MappedByteBufferImpl.java
+	(compact): Implemented.
+	(getChar): Implemented.
+	(putChar): Implemented.
+	(getDouble): Implemented.
+	(putdouble): Implemented.
+	(getFloat): Implemented.
+	(putFloat): Implemented.
+	(getInt): Implemented.
+	(putInt): Implemented.
+	(getLong): Implemented.
+	(putLong): Implemented.
+	(getShort): Implemented.
+	(putShort): Implemented.
+	* java/nio/channels/FileChannelImpl.java
+	(read): Set position where to access file.
+	(write): Likewise.
+	(transferTo): Flip buffer after read and before write.
+	(transferFrom): Likewise.
+
+2003-08-02  Michael Koch  <konqueror@gmx.de>
+
 	* gnu/java/lang/ArrayHelper.java
 	(equalsArray): Reformated, added method documentation.
 
Index: java/nio/ByteBufferImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/ByteBufferImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 ByteBufferImpl.java
--- java/nio/ByteBufferImpl.java	27 Jun 2003 13:34:11 -0000	1.2
+++ java/nio/ByteBufferImpl.java	2 Aug 2003 11:10:49 -0000
@@ -182,13 +182,20 @@
   
   final public char getChar ()
   {
-    // FIXME: this handles big endian only
-    return (char) (((get () & 0xff) << 8) + (get () & 0xff));
+    if (remaining() < 2)
+      throw new BufferUnderflowException();
+
+    // FIXME: this handles little endian only
+    return (char) (((get () & 0xff) << 8)
+                   + (get () & 0xff));
   }
   
   final public ByteBuffer putChar (char value)
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 2)
+      throw new BufferOverflowException();
+
+    // FIXME: this handles little endian only
     put ((byte) ((((int) value) & 0xff00) >> 8));
     put ((byte) (((int) value) & 0x00ff));
     return this;
@@ -196,13 +203,18 @@
   
   final public char getChar (int index)
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 2)
+      throw new BufferUnderflowException();
+
+    // FIXME: this handles little endian only
     return (char) (((get (index) & 0xff) << 8) + (get (index + 1) & 0xff));
   }
   
   final public ByteBuffer putChar (int index, char value)
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 2)
+      throw new BufferOverflowException();
+    // FIXME: this handles little endian only
     put (index, (byte) ((((int) value) & 0xff00) >> 8));
     put (index + 1, (byte) (((int) value) & 0x00ff));
     return this;
@@ -210,13 +222,19 @@
 
   final public short getShort ()
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 2)
+      throw new BufferUnderflowException();
+
+    // FIXME: this handles little endian only
     return (short) (((get () & 0xff) << 8) + (get () & 0xff));
   }
   
   final public ByteBuffer putShort (short value)
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 2)
+      throw new BufferOverflowException();
+
+    // FIXME: this handles little endian only
     put ((byte) ((((int) value) & 0xff00) >> 8));
     put ((byte) (((int) value) & 0x00ff));
     return this;
@@ -224,13 +242,19 @@
   
   final public short getShort (int index)
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 2)
+      throw new BufferUnderflowException();
+
+    // FIXME: this handles little endian only
     return (short) (((get (index) & 0xff) << 8) + (get (index + 1) & 0xff));
   }
   
   final public ByteBuffer putShort (int index, short value)
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 2)
+      throw new BufferOverflowException();
+
+    // FIXME: this handles little endian only
     put (index, (byte) ((((int) value) & 0xff00) >> 8));
     put (index + 1, (byte) (((int) value) & 0x00ff));
     return this;
@@ -238,58 +262,76 @@
 
   final public int getInt ()
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 4)
+      throw new BufferUnderflowException();
+
+    // FIXME: this handles little endian only
     return (int) (((get () & 0xff) << 24)
-                  + (get () & 0xff) << 16
-                  + (get () & 0xff) << 8
+                  + ((get () & 0xff) << 16)
+                  + ((get () & 0xff) << 8)
                   + (get () & 0xff));
   }
   
   final public ByteBuffer putInt (int value)
   {
-    // FIXME: this handles big endian only
-    put ((byte) ((((int) value) & 0xff000000) >> 24));
-    put ((byte) ((((int) value) & 0x00ff0000) >> 16));
-    put ((byte) ((((int) value) & 0x0000ff00) >> 8));
-    put ((byte) (((int) value) & 0x000000ff));
+    if (remaining() < 4)
+      throw new BufferOverflowException();
+
+    // FIXME: this handles little endian only
+    put ((byte) ((value & 0xff000000) >> 24));
+    put ((byte) ((value & 0x00ff0000) >> 16));
+    put ((byte) ((value & 0x0000ff00) >> 8));
+    put ((byte) (value & 0x000000ff));
     return this;
   }
   
   final public int getInt (int index)
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 4)
+      throw new BufferUnderflowException();
+
+    // FIXME: this handles little endian only
     return (int) (((get (index) & 0xff) << 24)
-                  + (get (index + 1) & 0xff) << 16
-                  + (get (index + 2) & 0xff) << 8
+                  + ((get (index + 1) & 0xff) << 16)
+                  + ((get (index + 2) & 0xff) << 8)
                   + (get (index + 3) & 0xff));
   }
   
   final public ByteBuffer putInt (int index, int value)
   {
-    // FIXME: this handles big endian only
-    put (index, (byte) ((((int) value) & 0xff000000) >> 24));
-    put (index + 1, (byte) ((((int) value) & 0x00ff0000) >> 16));
-    put (index + 2, (byte) ((((int) value) & 0x0000ff00) >> 8));
-    put (index + 3, (byte) (((int) value) & 0x000000ff));
+    if (remaining() < 4)
+      throw new BufferOverflowException();
+
+    // FIXME: this handles little endian only
+    put (index, (byte) ((value & 0xff000000) >> 24));
+    put (index + 1, (byte) ((value & 0x00ff0000) >> 16));
+    put (index + 2, (byte) ((value & 0x0000ff00) >> 8));
+    put (index + 3, (byte) (value & 0x000000ff));
     return this;
   }
 
   final public long getLong ()
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 8)
+      throw new BufferUnderflowException();
+
+    // FIXME: this handles little endian only
     return (long) (((get () & 0xff) << 56)
-                   + (get () & 0xff) << 48
-                   + (get () & 0xff) << 40
-                   + (get () & 0xff) << 32
-                   + (get () & 0xff) << 24
-                   + (get () & 0xff) << 16
-                   + (get () & 0xff) << 8
+                   + ((get () & 0xff) << 48)
+                   + ((get () & 0xff) << 40)
+                   + ((get () & 0xff) << 32)
+                   + ((get () & 0xff) << 24)
+                   + ((get () & 0xff) << 16)
+                   + ((get () & 0xff) << 8)
                    + (get () & 0xff));
   }
   
   final public ByteBuffer putLong (long value)
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 8)
+      throw new BufferOverflowException();
+
+    // FIXME: this handles little endian only
     put ((byte) ((value & 0xff00000000000000L) >> 56));
     put ((byte) ((value & 0x00ff000000000000L) >> 48));
     put ((byte) ((value & 0x0000ff0000000000L) >> 40));
@@ -303,20 +345,26 @@
   
   final public long getLong (int index)
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 8)
+      throw new BufferUnderflowException();
+
+    // FIXME: this handles little endian only
     return (long) (((get (index) & 0xff) << 56)
-                   + (get (index + 1) & 0xff) << 48
-                   + (get (index + 2) & 0xff) << 40
-                   + (get (index + 3) & 0xff) << 32
-                   + (get (index + 4) & 0xff) << 24
-                   + (get (index + 5) & 0xff) << 16
-                   + (get (index + 6) & 0xff) << 8
+                   + ((get (index + 1) & 0xff) << 48)
+                   + ((get (index + 2) & 0xff) << 40)
+                   + ((get (index + 3) & 0xff) << 32)
+                   + ((get (index + 4) & 0xff) << 24)
+                   + ((get (index + 5) & 0xff) << 16)
+                   + ((get (index + 6) & 0xff) << 8)
                    + (get (index + 7) & 0xff));
   }
   
   final public ByteBuffer putLong (int index, long value)
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 8)
+      throw new BufferOverflowException();
+
+    // FIXME: this handles little endian only
     put (index, (byte) ((value & 0xff00000000000000L) >> 56));
     put (index + 1, (byte) ((value & 0x00ff000000000000L) >> 48));
     put (index + 2, (byte) ((value & 0x0000ff0000000000L) >> 40));
@@ -330,16 +378,22 @@
 
   final public float getFloat ()
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 4)
+      throw new BufferUnderflowException();
+
+    // FIXME: this handles little endian only
     return (float) (((get () & 0xff) << 24)
-                    + (get () & 0xff) << 16
-                    + (get () & 0xff) << 8
+                    + ((get () & 0xff) << 16)
+                    + ((get () & 0xff) << 8)
                     + (get () & 0xff));
   }
   
   final public ByteBuffer putFloat (float value)
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 4)
+      throw new BufferOverflowException();
+
+    // FIXME: this handles little endian only
     put ((byte) ((((int) value) & 0xff000000) >> 24));
     put ((byte) ((((int) value) & 0x00ff0000) >> 16));
     put ((byte) ((((int) value) & 0x0000ff00) >> 8));
@@ -349,16 +403,22 @@
   
   final public float getFloat (int index)
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 4)
+      throw new BufferUnderflowException();
+
+    // FIXME: this handles little endian only
     return (float) (((get (index) & 0xff) << 24)
-                    + (get (index + 1) & 0xff) << 16
-                    + (get (index + 2) & 0xff) << 8
+                    + ((get (index + 1) & 0xff) << 16)
+                    + ((get (index + 2) & 0xff) << 8)
                     + (get (index + 3) & 0xff));
   }
 
   final public ByteBuffer putFloat (int index, float value)
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 4)
+      throw new BufferOverflowException();
+
+    // FIXME: this handles little endian only
     put (index, (byte) ((((int) value) & 0xff000000) >> 24));
     put (index + 1, (byte) ((((int) value) & 0x00ff0000) >> 16));
     put (index + 2, (byte) ((((int) value) & 0x0000ff00) >> 8));
@@ -368,20 +428,26 @@
 
   final public double getDouble ()
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 8)
+      throw new BufferUnderflowException();
+
+    // FIXME: this handles little endian only
     return (double) (((get () & 0xff) << 56)
-                     + (get () & 0xff) << 48
-                     + (get () & 0xff) << 40
-                     + (get () & 0xff) << 32
-                     + (get () & 0xff) << 24
-                     + (get () & 0xff) << 16
-                     + (get () & 0xff) << 8
+                     + ((get () & 0xff) << 48)
+                     + ((get () & 0xff) << 40)
+                     + ((get () & 0xff) << 32)
+                     + ((get () & 0xff) << 24)
+                     + ((get () & 0xff) << 16)
+                     + ((get () & 0xff) << 8)
                      + (get () & 0xff));
   }
 
   final public ByteBuffer putDouble (double value)
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 8)
+      throw new BufferOverflowException();
+
+    // FIXME: this handles little endian only
     put ((byte) ((((long) value) & 0xff00000000000000L) >> 56));
     put ((byte) ((((long) value) & 0x00ff000000000000L) >> 48));
     put ((byte) ((((long) value) & 0x0000ff0000000000L) >> 40));
@@ -395,20 +461,26 @@
   
   final public double getDouble (int index)
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 8)
+      throw new BufferUnderflowException();
+
+    // FIXME: this handles little endian only
     return (double) (((get (index) & 0xff) << 56)
-                     + (get (index + 1) & 0xff) << 48
-                     + (get (index + 2) & 0xff) << 40
-                     + (get (index + 3) & 0xff) << 32
-                     + (get (index + 4) & 0xff) << 24
-                     + (get (index + 5) & 0xff) << 16
-                     + (get (index + 6) & 0xff) << 8
+                     + ((get (index + 1) & 0xff) << 48)
+                     + ((get (index + 2) & 0xff) << 40)
+                     + ((get (index + 3) & 0xff) << 32)
+                     + ((get (index + 4) & 0xff) << 24)
+                     + ((get (index + 5) & 0xff) << 16)
+                     + ((get (index + 6) & 0xff) << 8)
                      + (get (index + 7) & 0xff));
   }
   
   final public ByteBuffer putDouble (int index, double value)
   {
-    // FIXME: this handles big endian only
+    if (remaining() < 8)
+      throw new BufferOverflowException();
+
+    // FIXME: this handles little endian only
     put (index, (byte) ((((long) value) & 0xff00000000000000L) >> 56));
     put (index + 1, (byte) ((((long) value) & 0x00ff000000000000L) >> 48));
     put (index + 2, (byte) ((((long) value) & 0x0000ff0000000000L) >> 40));
Index: java/nio/DirectByteBufferImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/DirectByteBufferImpl.java,v
retrieving revision 1.3
diff -u -b -B -r1.3 DirectByteBufferImpl.java
--- java/nio/DirectByteBufferImpl.java	27 Jun 2003 13:34:11 -0000	1.3
+++ java/nio/DirectByteBufferImpl.java	2 Aug 2003 11:10:49 -0000
@@ -181,13 +181,14 @@
   
   final public char getChar ()
   {
-    // FIXME: this handles big endian only
-    return (char) (((get () & 0xff) << 8) + (get () & 0xff));
+    // FIXME: this handles little endian only
+    return (char) (((get () & 0xff) << 8)
+                   + (get () & 0xff));
   }
   
   final public ByteBuffer putChar (char value)
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     put ((byte) ((((int) value) & 0xff00) >> 8));
     put ((byte) (((int) value) & 0x00ff));
     return this;
@@ -195,13 +196,14 @@
   
   final public char getChar (int index)
   {
-    // FIXME: this handles big endian only
-    return (char) (((get (index) & 0xff) << 8) + (get (index + 1) & 0xff));
+    // FIXME: this handles little endian only
+    return (char) (((get (index) & 0xff) << 8)
+                   + (get (index + 1) & 0xff));
   }
   
   final public ByteBuffer putChar (int index, char value)
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     put (index, (byte) ((((int) value) & 0xff00) >> 8));
     put (index + 1, (byte) (((int) value) & 0x00ff));
     return this;
@@ -209,13 +211,14 @@
 
   final public short getShort ()
   {
-    // FIXME: this handles big endian only
-    return (short) (((get () & 0xff) << 8) + (get () & 0xff));
+    // FIXME: this handles little endian only
+    return (short) (((get () & 0xff) << 8)
+                    + (get () & 0xff));
   }
   
   final public ByteBuffer putShort (short value)
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     put ((byte) ((((int) value) & 0xff00) >> 8));
     put ((byte) (((int) value) & 0x00ff));
     return this;
@@ -223,13 +226,14 @@
   
   final public short getShort (int index)
   {
-    // FIXME: this handles big endian only
-    return (short) (((get (index) & 0xff) << 8) + (get (index + 1) & 0xff));
+    // FIXME: this handles little endian only
+    return (short) (((get (index) & 0xff) << 8)
+                    + (get (index + 1) & 0xff));
   }
   
   final public ByteBuffer putShort (int index, short value)
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     put (index, (byte) ((((int) value) & 0xff00) >> 8));
     put (index + 1, (byte) (((int) value) & 0x00ff));
     return this;
@@ -237,16 +241,16 @@
 
   final public int getInt ()
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     return (int) (((get () & 0xff) << 24)
-                  + (get () & 0xff) << 16
-                  + (get () & 0xff) << 8
+                  + ((get () & 0xff) << 16)
+                  + ((get () & 0xff) << 8)
                   + (get () & 0xff));
   }
   
   final public ByteBuffer putInt (int value)
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     put ((byte) ((((int) value) & 0xff000000) >> 24));
     put ((byte) ((((int) value) & 0x00ff0000) >> 16));
     put ((byte) ((((int) value) & 0x0000ff00) >> 8));
@@ -256,16 +260,16 @@
   
   final public int getInt (int index)
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     return (int) (((get (index) & 0xff) << 24)
-                  + (get (index + 1) & 0xff) << 16
-                  + (get (index + 2) & 0xff) << 8
+                  + ((get (index + 1) & 0xff) << 16)
+                  + ((get (index + 2) & 0xff) << 8)
                   + (get (index + 3) & 0xff));
   }
   
   final public ByteBuffer putInt (int index, int value)
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     put (index, (byte) ((((int) value) & 0xff000000) >> 24));
     put (index + 1, (byte) ((((int) value) & 0x00ff0000) >> 16));
     put (index + 2, (byte) ((((int) value) & 0x0000ff00) >> 8));
@@ -275,20 +279,20 @@
 
   final public long getLong ()
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     return (long) (((get () & 0xff) << 56)
-                   + (get () & 0xff) << 48
-                   + (get () & 0xff) << 40
-                   + (get () & 0xff) << 32
-                   + (get () & 0xff) << 24
-                   + (get () & 0xff) << 16
-                   + (get () & 0xff) << 8
+                   + ((get () & 0xff) << 48)
+                   + ((get () & 0xff) << 40)
+                   + ((get () & 0xff) << 32)
+                   + ((get () & 0xff) << 24)
+                   + ((get () & 0xff) << 16)
+                   + ((get () & 0xff) << 8)
                    + (get () & 0xff));
   }
   
   final public ByteBuffer putLong (long value)
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     put ((byte) ((value & 0xff00000000000000L) >> 56));
     put ((byte) ((value & 0x00ff000000000000L) >> 48));
     put ((byte) ((value & 0x0000ff0000000000L) >> 40));
@@ -302,20 +306,20 @@
   
   final public long getLong (int index)
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     return (long) (((get (index) & 0xff) << 56)
-                   + (get (index + 1) & 0xff) << 48
-                   + (get (index + 2) & 0xff) << 40
-                   + (get (index + 3) & 0xff) << 32
-                   + (get (index + 4) & 0xff) << 24
-                   + (get (index + 5) & 0xff) << 16
-                   + (get (index + 6) & 0xff) << 8
+                   + ((get (index + 1) & 0xff) << 48)
+                   + ((get (index + 2) & 0xff) << 40)
+                   + ((get (index + 3) & 0xff) << 32)
+                   + ((get (index + 4) & 0xff) << 24)
+                   + ((get (index + 5) & 0xff) << 16)
+                   + ((get (index + 6) & 0xff) << 8)
                    + (get (index + 7) & 0xff));
   }
   
   final public ByteBuffer putLong (int index, long value)
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     put (index, (byte) ((value & 0xff00000000000000L) >> 56));
     put (index + 1, (byte) ((value & 0x00ff000000000000L) >> 48));
     put (index + 2, (byte) ((value & 0x0000ff0000000000L) >> 40));
@@ -329,16 +333,16 @@
 
   final public float getFloat ()
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     return (float) (((get () & 0xff) << 24)
-                    + (get () & 0xff) << 16
-                    + (get () & 0xff) << 8
+                    + ((get () & 0xff) << 16)
+                    + ((get () & 0xff) << 8)
                     + (get () & 0xff));
   }
   
   final public ByteBuffer putFloat (float value)
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     put ((byte) ((((int) value) & 0xff000000) >> 24));
     put ((byte) ((((int) value) & 0x00ff0000) >> 16));
     put ((byte) ((((int) value) & 0x0000ff00) >> 8));
@@ -348,16 +352,16 @@
   
   final public float getFloat (int index)
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     return (float) (((get (index) & 0xff) << 24)
-                    + (get (index + 1) & 0xff) << 16
-                    + (get (index + 2) & 0xff) << 8
+                    + ((get (index + 1) & 0xff) << 16)
+                    + ((get (index + 2) & 0xff) << 8)
                     + (get (index + 3) & 0xff));
   }
 
   final public ByteBuffer putFloat (int index, float value)
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     put (index, (byte) ((((int) value) & 0xff000000) >> 24));
     put (index + 1, (byte) ((((int) value) & 0x00ff0000) >> 16));
     put (index + 2, (byte) ((((int) value) & 0x0000ff00) >> 8));
@@ -367,20 +371,20 @@
 
   final public double getDouble ()
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     return (double) (((get () & 0xff) << 56)
-                     + (get () & 0xff) << 48
-                     + (get () & 0xff) << 40
-                     + (get () & 0xff) << 32
-                     + (get () & 0xff) << 24
-                     + (get () & 0xff) << 16
-                     + (get () & 0xff) << 8
+                     + ((get () & 0xff) << 48)
+                     + ((get () & 0xff) << 40)
+                     + ((get () & 0xff) << 32)
+                     + ((get () & 0xff) << 24)
+                     + ((get () & 0xff) << 16)
+                     + ((get () & 0xff) << 8)
                      + (get () & 0xff));
   }
 
   final public ByteBuffer putDouble (double value)
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     put ((byte) ((((long) value) & 0xff00000000000000L) >> 56));
     put ((byte) ((((long) value) & 0x00ff000000000000L) >> 48));
     put ((byte) ((((long) value) & 0x0000ff0000000000L) >> 40));
@@ -394,20 +398,20 @@
   
   final public double getDouble (int index)
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     return (double) (((get (index) & 0xff) << 56)
-                     + (get (index + 1) & 0xff) << 48
-                     + (get (index + 2) & 0xff) << 40
-                     + (get (index + 3) & 0xff) << 32
-                     + (get (index + 4) & 0xff) << 24
-                     + (get (index + 5) & 0xff) << 16
-                     + (get (index + 6) & 0xff) << 8
+                     + ((get (index + 1) & 0xff) << 48)
+                     + ((get (index + 2) & 0xff) << 40)
+                     + ((get (index + 3) & 0xff) << 32)
+                     + ((get (index + 4) & 0xff) << 24)
+                     + ((get (index + 5) & 0xff) << 16)
+                     + ((get (index + 6) & 0xff) << 8)
                      + (get (index + 7) & 0xff));
   }
   
   final public ByteBuffer putDouble (int index, double value)
   {
-    // FIXME: this handles big endian only
+    // FIXME: this handles little endian only
     put (index, (byte) ((((long) value) & 0xff00000000000000L) >> 56));
     put (index + 1, (byte) ((((long) value) & 0x00ff000000000000L) >> 48));
     put (index + 2, (byte) ((((long) value) & 0x0000ff0000000000L) >> 40));
Index: java/nio/MappedByteBufferImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/MappedByteBufferImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 MappedByteBufferImpl.java
--- java/nio/MappedByteBufferImpl.java	13 Jul 2003 16:53:05 -0000	1.2
+++ java/nio/MappedByteBufferImpl.java	2 Aug 2003 11:10:49 -0000
@@ -102,7 +102,16 @@
 
   public ByteBuffer compact ()
   {
-    throw new Error ("Not implemented");
+    int copied = 0;
+    
+    while (remaining () > 0)
+      {
+	put (copied, get ());
+	copied++;
+      }
+
+    position (copied);
+    return this;
   }
 
   public boolean isDirect ()
@@ -157,7 +166,9 @@
 
   public char getChar ()
   {
-    throw new Error ("Not implemented");
+    char value = getChar (position());
+    position (position() + 2);
+    return value;
   }
 
   public char getChar (int index)
@@ -167,7 +178,9 @@
 
   public ByteBuffer putChar (char value)
   {
-    throw new Error ("Not implemented");
+    putChar (position(), value);
+    position (position() + 2);
+    return this;
   }
 
   public ByteBuffer putChar (int index, char value)
@@ -177,7 +190,9 @@
 
   public double getDouble ()
   {
-    throw new Error ("Not implemented");
+    double value = getDouble (position());
+    position (position() + 8);
+    return value;
   }
 
   public double getDouble (int index)
@@ -187,7 +202,9 @@
 
   public ByteBuffer putDouble (double value)
   {
-    throw new Error ("Not implemented");
+    putDouble (position(), value);
+    position (position() + 8);
+    return this;
   }
 
   public ByteBuffer putDouble (int index, double value)
@@ -197,7 +214,9 @@
 
   public float getFloat ()
   {
-    throw new Error ("Not implemented");
+    float value = getFloat (position ());
+    position (position() + 4);
+    return value;
   }
 
   public float getFloat (int index)
@@ -207,7 +226,9 @@
 
   public ByteBuffer putFloat (float value)
   {
-    throw new Error ("Not implemented");
+    putFloat (position(), value);
+    position (position() + 4);
+    return this;
   }
 
   public ByteBuffer putFloat (int index, float value)
@@ -217,7 +238,9 @@
 
   public int getInt ()
   {
-    throw new Error ("Not implemented");
+    int value = getInt (position());
+    position (position() + 8);
+    return value;
   }
 
   public int getInt (int index)
@@ -227,7 +250,9 @@
 
   public ByteBuffer putInt (int value)
   {
-    throw new Error ("Not implemented");
+    putInt (position(), value);
+    position (position() + 4);
+    return this;
   }
 
   public ByteBuffer putInt (int index, int value)
@@ -237,7 +262,9 @@
 
   public long getLong ()
   {
-    throw new Error ("Not implemented");
+    long value = getLong (position());
+    position (position() + 8);
+    return value;
   }
 
   public long getLong (int index)
@@ -247,7 +274,9 @@
 
   public ByteBuffer putLong (long value)
   {
-    throw new Error ("Not implemented");
+    putLong (position(), value);
+    position (position() + 8);
+    return this;
   }
 
   public ByteBuffer putLong (int index, long value)
@@ -257,7 +286,9 @@
 
   public short getShort ()
   {
-    throw new Error ("Not implemented");
+    short value = getShort (position());
+    position (position() + 2);
+    return value;
   }
 
   public short getShort (int index)
@@ -267,7 +298,9 @@
 
   public ByteBuffer putShort (short value)
   {
-    throw new Error ("Not implemented");
+    putShort (position(), value);
+    position (position() + 2);
+    return this;
   }
 
   public ByteBuffer putShort (int index, short value)
Index: java/nio/channels/FileChannelImpl.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/channels/FileChannelImpl.java,v
retrieving revision 1.1
diff -u -b -B -r1.1 FileChannelImpl.java
--- java/nio/channels/FileChannelImpl.java	13 Jul 2003 16:53:05 -0000	1.1
+++ java/nio/channels/FileChannelImpl.java	2 Aug 2003 11:10:49 -0000
@@ -146,6 +146,7 @@
     long oldPosition;
 
     oldPosition = implPosition ();
+    position (position);
     result = implRead (dst);
     implPosition (oldPosition);
     
@@ -208,6 +209,7 @@
     long oldPosition;
 
     oldPosition = implPosition ();
+    position (position);
     result = implWrite (src);
     implPosition (oldPosition);
     
@@ -298,6 +300,7 @@
     // XXX: count needs to be casted from long to int. Dataloss ?
     ByteBuffer buffer = ByteBuffer.allocate ((int) count);
     read (buffer, position);
+    buffer.flip();
     return target.write (buffer);
   }
 
@@ -317,6 +320,7 @@
     // XXX: count needs to be casted from long to int. Dataloss ?
     ByteBuffer buffer = ByteBuffer.allocate ((int) count);
     src.read (buffer);
+    buffer.flip();
     return write (buffer, position);
   }
 

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]