[kaffe] CVS kaffe (dalibor): Resynced with GNU Classpath
Kaffe CVS
cvs-commits at kaffe.org
Mon Feb 23 15:09:02 PST 2004
PatchSet 4455
Date: 2004/02/23 22:56:35
Author: dalibor
Branch: HEAD
Tag: (none)
Log:
Resynced with GNU Classpath
2004-02-23 Dalibor Topic <robilad at kaffe.org>
Resynced with GNU Classpath
2004-02-17 Per Bothner <per at bothner.com>
* java/nio/CharBufferImpl.java: Inline super constructor.
* java/nio/DoubleBufferImpl.java: Likewise.
* java/nio/FloatBufferImpl.java: Likewise.
* java/nio/IntBufferImpl.java: Likewise.
* java/nio/LongBufferImpl.java: Likewise.
* java/nio/ShortBufferImpl.java: Likewise.
* java/nio/CharBuffer.java: Remove unused constructor.
* java/nio/DoubleBuffer.java: Likewise.
* java/nio/FloatBuffer.java: Likewise.
* java/nio/IntBuffer.java: Likewise.
* java/nio/LongBuffer.java: Likewise.
* java/nio/ShortBuffer.java: Likewise.
* java/nio/CharViewBufferImpl.java: New convenience constructor.
Fix buggy call to super constructor.
* java/nio/DoubleViewBufferImpl.java: Likewise.
* java/nio/FloatViewBufferImpl.java: Likewise.
* java/nio/IntViewBufferImpl.java: Likewise.
* java/nio/LongViewBufferImpl.java: Likewise.
* java/nio/ShortViewBufferImpl.java: Likewise.
* java/nio/ByteBuffer.java (endian): Make non-private so other
java.nio classes can inherit it.
(<init>): Don't bother clearing array_offset.
* java/nio/ByteBuffer.java (allocate): Re-implement using wrap.
* java/nio/ByteBuffer.java (get(byte[],int,int)): Check underflow.
Remove redundant test.
* java/nio/ByteBufferImpl.java (asCharBuffer, asShortBuffer,
asIntBuffer, asLongBuffer, asFloatBuffer, asDoubleBuffer):
Use new XxxViewBufferImpl constructors.
* java/nio/MappedByteBufferImpl.java: Likewise.
* java/nio/DirectByteBufferImpl.java: Likewise.
* java/nio/ByteBufferImpl.java: Remove one constructor.
Inline super in remaining constructor.
* java/nio/ByteBuffer.java: Remove unused constructor.
* java/nio/ByteBufferImpl.java (shiftDown): New optimized method.
* java/nio/ByteBufferImpl.java (get, put): Add array_offset.
2004-02-11 Per Bothner <per at bothner.com>
* java/nio/ByteBuffer.java (shiftDown): New helper method.
* java/nio/ByteBufferImpl.java (compact): Use new shiftDown method.
* sava/nio/ByteBufferHelper.java: Remove redundant 'final' specifiers.
Pass ByteOrder parameter to most methods, since the underlying
ByteBuffer's order isn't always what we should use.
* java/nio/ByteBufferImpl.java: Pass byte-order various places.
* java/nio/DirectByteBufferImpl.java: Likewise.
Use ByteBufferHelper methods.
* java/nio/MappedByteBufferImpl.java: Likewise.
(compact): Use shiftDown.
* java/nio/CharViewBufferImpl.java (<init>): Pass byte-order.
(get, put): Use ByteBufferHelper.
(compact): Use new shiftDown method.
(duplicate(boolean)): New helper method.
(duplicate, asReadOnlyBuffer): Use it. (order): Return endian field.
* java/nio/DoubleViewBufferImpl.java: Likewise.
* java/nio/FloatViewBufferImpl.java: Likewise.
* java/nio/IntViewBufferImpl.java: Likewise.
* java/nio/LongViewBufferImpl.java: Likewise.
* java/nio/ShortViewBufferImpl.java: Likewise.
* java/nio/CharViewBufferImpl.java (subsequence): Redundant test.
* java/nio/DirectByteBufferImpl.java (shiftDown): New native method.
(compact): Re-implement using shiftDown.
Members:
ChangeLog:1.2035->1.2036
libraries/javalib/java/nio/ByteBuffer.java:1.8->1.9
libraries/javalib/java/nio/ByteBufferHelper.java:1.2->1.3
libraries/javalib/java/nio/ByteBufferImpl.java:1.3->1.4
libraries/javalib/java/nio/CharBuffer.java:1.7->1.8
libraries/javalib/java/nio/CharBufferImpl.java:1.2->1.3
libraries/javalib/java/nio/CharViewBufferImpl.java:1.1->1.2
libraries/javalib/java/nio/DirectByteBufferImpl.java:1.4->1.5
libraries/javalib/java/nio/DoubleBuffer.java:1.6->1.7
libraries/javalib/java/nio/DoubleBufferImpl.java:1.2->1.3
libraries/javalib/java/nio/DoubleViewBufferImpl.java:1.1->1.2
libraries/javalib/java/nio/FloatBuffer.java:1.6->1.7
libraries/javalib/java/nio/FloatBufferImpl.java:1.2->1.3
libraries/javalib/java/nio/FloatViewBufferImpl.java:1.1->1.2
libraries/javalib/java/nio/IntBuffer.java:1.6->1.7
libraries/javalib/java/nio/IntBufferImpl.java:1.2->1.3
libraries/javalib/java/nio/IntViewBufferImpl.java:1.1->1.2
libraries/javalib/java/nio/LongBuffer.java:1.6->1.7
libraries/javalib/java/nio/LongBufferImpl.java:1.2->1.3
libraries/javalib/java/nio/LongViewBufferImpl.java:1.1->1.2
libraries/javalib/java/nio/MappedByteBufferImpl.java:1.2->1.3
libraries/javalib/java/nio/ShortBuffer.java:1.6->1.7
libraries/javalib/java/nio/ShortBufferImpl.java:1.2->1.3
libraries/javalib/java/nio/ShortViewBufferImpl.java:1.1->1.2
libraries/javalib/java/nio/channels/spi/AbstractInterruptibleChannel.java:1.3->1.4
libraries/javalib/java/nio/channels/spi/AbstractSelectableChannel.java:1.5->1.6
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.2035 kaffe/ChangeLog:1.2036
--- kaffe/ChangeLog:1.2035 Mon Feb 23 22:38:46 2004
+++ kaffe/ChangeLog Mon Feb 23 22:56:35 2004
@@ -2,6 +2,80 @@
Resynced with GNU Classpath
+ 2004-02-17 Per Bothner <per at bothner.com>
+
+ * java/nio/CharBufferImpl.java: Inline super constructor.
+ * java/nio/DoubleBufferImpl.java: Likewise.
+ * java/nio/FloatBufferImpl.java: Likewise.
+ * java/nio/IntBufferImpl.java: Likewise.
+ * java/nio/LongBufferImpl.java: Likewise.
+ * java/nio/ShortBufferImpl.java: Likewise.
+ * java/nio/CharBuffer.java: Remove unused constructor.
+ * java/nio/DoubleBuffer.java: Likewise.
+ * java/nio/FloatBuffer.java: Likewise.
+ * java/nio/IntBuffer.java: Likewise.
+ * java/nio/LongBuffer.java: Likewise.
+ * java/nio/ShortBuffer.java: Likewise.
+ * java/nio/CharViewBufferImpl.java: New convenience constructor.
+ Fix buggy call to super constructor.
+ * java/nio/DoubleViewBufferImpl.java: Likewise.
+ * java/nio/FloatViewBufferImpl.java: Likewise.
+ * java/nio/IntViewBufferImpl.java: Likewise.
+ * java/nio/LongViewBufferImpl.java: Likewise.
+ * java/nio/ShortViewBufferImpl.java: Likewise.
+
+ * java/nio/ByteBuffer.java (endian): Make non-private so other
+ java.nio classes can inherit it.
+ (<init>): Don't bother clearing array_offset.
+ * java/nio/ByteBuffer.java (allocate): Re-implement using wrap.
+ * java/nio/ByteBuffer.java (get(byte[],int,int)): Check underflow.
+ Remove redundant test.
+
+ * java/nio/ByteBufferImpl.java (asCharBuffer, asShortBuffer,
+ asIntBuffer, asLongBuffer, asFloatBuffer, asDoubleBuffer):
+ Use new XxxViewBufferImpl constructors.
+ * java/nio/MappedByteBufferImpl.java: Likewise.
+ * java/nio/DirectByteBufferImpl.java: Likewise.
+
+ * java/nio/ByteBufferImpl.java: Remove one constructor.
+ Inline super in remaining constructor.
+ * java/nio/ByteBuffer.java: Remove unused constructor.
+
+ * java/nio/ByteBufferImpl.java (shiftDown): New optimized method.
+
+ * java/nio/ByteBufferImpl.java (get, put): Add array_offset.
+
+ 2004-02-11 Per Bothner <per at bothner.com>
+
+ * java/nio/ByteBuffer.java (shiftDown): New helper method.
+ * java/nio/ByteBufferImpl.java (compact): Use new shiftDown method.
+ * sava/nio/ByteBufferHelper.java: Remove redundant 'final' specifiers.
+ Pass ByteOrder parameter to most methods, since the underlying
+ ByteBuffer's order isn't always what we should use.
+ * java/nio/ByteBufferImpl.java: Pass byte-order various places.
+ * java/nio/DirectByteBufferImpl.java: Likewise.
+ Use ByteBufferHelper methods.
+ * java/nio/MappedByteBufferImpl.java: Likewise.
+ (compact): Use shiftDown.
+ * java/nio/CharViewBufferImpl.java (<init>): Pass byte-order.
+ (get, put): Use ByteBufferHelper.
+ (compact): Use new shiftDown method.
+ (duplicate(boolean)): New helper method.
+ (duplicate, asReadOnlyBuffer): Use it.
+ (order): Return endian field.
+ * java/nio/DoubleViewBufferImpl.java: Likewise.
+ * java/nio/FloatViewBufferImpl.java: Likewise.
+ * java/nio/IntViewBufferImpl.java: Likewise.
+ * java/nio/LongViewBufferImpl.java: Likewise.
+ * java/nio/ShortViewBufferImpl.java: Likewise.
+ * java/nio/CharViewBufferImpl.java (subsequence): Redundant test.
+ * java/nio/DirectByteBufferImpl.java (shiftDown): New native method.
+ (compact): Re-implement using shiftDown.
+
+2004-02-23 Dalibor Topic <robilad at kaffe.org>
+
+ Resynced with GNU Classpath
+
2004-02-06 Mohan Embar <gnustuff at thisiscool.com>
* gnu/java/nio/SocketChannelImpl.java
Index: kaffe/libraries/javalib/java/nio/ByteBuffer.java
diff -u kaffe/libraries/javalib/java/nio/ByteBuffer.java:1.8 kaffe/libraries/javalib/java/nio/ByteBuffer.java:1.9
--- kaffe/libraries/javalib/java/nio/ByteBuffer.java:1.8 Sat Nov 22 18:50:16 2003
+++ kaffe/libraries/javalib/java/nio/ByteBuffer.java Mon Feb 23 22:56:37 2004
@@ -1,5 +1,5 @@
/* ByteBuffer.java --
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -44,7 +44,7 @@
public abstract class ByteBuffer extends Buffer
implements Comparable
{
- private ByteOrder endian = ByteOrder.BIG_ENDIAN;
+ ByteOrder endian = ByteOrder.BIG_ENDIAN;
int array_offset;
byte[] backing_buffer;
@@ -52,16 +52,8 @@
ByteBuffer (int capacity, int limit, int position, int mark)
{
super (capacity, limit, position, mark);
- array_offset = 0;
}
- ByteBuffer (byte[] buffer, int offset, int capacity, int limit, int position, int mark)
- {
- super (capacity, limit, position, mark);
- this.backing_buffer = buffer;
- this.array_offset = offset;
- }
-
/**
* Allocates a new direct byte buffer.
*/
@@ -75,7 +67,7 @@
*/
public static ByteBuffer allocate (int capacity)
{
- return new ByteBufferImpl (capacity);
+ return wrap(new byte[capacity], 0, capacity);
}
/**
@@ -87,6 +79,14 @@
*/
final public static ByteBuffer wrap (byte[] array, int offset, int length)
{
+ // FIXME: In GCJ and other implementations where arrays may not
+ // move we might consider, at least when offset==0:
+ // return new DirectByteBufferImpl(array,
+ // address_of_data(array) + offset,
+ // length, length, 0, false);
+ // This may be more efficient, mainly because we can then use the
+ // same logic for all ByteBuffers.
+
return new ByteBufferImpl (array, 0, array.length, offset + length, offset, -1, false);
}
@@ -116,11 +116,10 @@
*/
public ByteBuffer get (byte[] dst, int offset, int length)
{
- if ((offset < 0)
- || (offset > dst.length)
- || (length < 0)
- || (length > (dst.length - offset)))
+ if (offset < 0 || length < 0 || offset + length > dst.length)
throw new IndexOutOfBoundsException ();
+ if (length > remaining())
+ throw new BufferUnderflowException();
for (int i = offset; i < offset + length; i++)
{
@@ -382,8 +381,14 @@
*/
public abstract ByteBuffer compact ();
+ void shiftDown (int dst_offset, int src_offset, int count)
+ {
+ for (int i = 0; i < count; i++)
+ put(dst_offset + i, get(src_offset + i));
+ }
+
/**
- * Tells wether or not this buffer is direct.
+ * Tells whether or not this buffer is direct.
*/
public abstract boolean isDirect ();
Index: kaffe/libraries/javalib/java/nio/ByteBufferHelper.java
diff -u kaffe/libraries/javalib/java/nio/ByteBufferHelper.java:1.2 kaffe/libraries/javalib/java/nio/ByteBufferHelper.java:1.3
--- kaffe/libraries/javalib/java/nio/ByteBufferHelper.java:1.2 Wed Oct 22 10:34:55 2003
+++ kaffe/libraries/javalib/java/nio/ByteBufferHelper.java Mon Feb 23 22:56:37 2004
@@ -1,5 +1,5 @@
/* ByteBufferImpl.java --
- Copyright (C) 2003 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -42,58 +42,58 @@
*/
final class ByteBufferHelper
{
- private static final void checkRemainingForRead (ByteBuffer buffer, int bytes)
+ private static void checkRemainingForRead (ByteBuffer buffer, int bytes)
{
if (buffer.remaining() < bytes)
throw new BufferUnderflowException();
}
- private static final void checkRemainingForWrite (ByteBuffer buffer, int bytes)
+ private static void checkRemainingForWrite (ByteBuffer buffer, int bytes)
{
if (buffer.remaining() < bytes)
throw new BufferOverflowException();
}
- private static final void checkAvailableForRead (ByteBuffer buffer,
- int index, int bytes)
+ private static void checkAvailableForRead (ByteBuffer buffer,
+ int index, int bytes)
{
if (buffer.limit() < (index + bytes))
throw new BufferUnderflowException();
}
- private static final void checkAvailableForWrite (ByteBuffer buffer,
- int index, int bytes)
+ private static void checkAvailableForWrite (ByteBuffer buffer,
+ int index, int bytes)
{
if (buffer.limit() < (index + bytes))
throw new BufferOverflowException();
}
- public static final char getChar (ByteBuffer buffer)
+ public static char getChar (ByteBuffer buffer, ByteOrder order)
{
- return (char) getShort (buffer);
+ return (char) getShort (buffer, order);
}
- public static final ByteBuffer putChar (ByteBuffer buffer, char value)
+ public static void putChar (ByteBuffer buffer, char value, ByteOrder order)
{
- return putShort (buffer, (short) value);
+ putShort (buffer, (short) value, order);
}
- public static final char getChar (ByteBuffer buffer, int index)
+ public static char getChar (ByteBuffer buffer, int index, ByteOrder order)
{
- return (char) getShort (buffer, index);
+ return (char) getShort (buffer, index, order);
}
- public static final ByteBuffer putChar (ByteBuffer buffer, int index,
- char value)
+ public static void putChar (ByteBuffer buffer, int index,
+ char value, ByteOrder order)
{
- return putShort (buffer, index, (short) value);
+ putShort (buffer, index, (short) value, order);
}
- public static final short getShort (ByteBuffer buffer)
+ public static short getShort (ByteBuffer buffer, ByteOrder order)
{
checkRemainingForRead (buffer, 2);
- if (buffer.order() == ByteOrder.LITTLE_ENDIAN)
+ if (order == ByteOrder.LITTLE_ENDIAN)
{
return (short) ((buffer.get() & 0xff)
+ (buffer.get() << 8));
@@ -103,11 +103,11 @@
+ (buffer.get() & 0xff));
}
- public static final ByteBuffer putShort (ByteBuffer buffer, short value)
+ public static void putShort (ByteBuffer buffer, short value, ByteOrder order)
{
checkRemainingForWrite (buffer, 2);
- if (buffer.order() == ByteOrder.LITTLE_ENDIAN)
+ if (order == ByteOrder.LITTLE_ENDIAN)
{
buffer.put ((byte) value);
buffer.put ((byte) (value >> 8));
@@ -117,15 +117,14 @@
buffer.put ((byte) (value >> 8));
buffer.put ((byte) value);
}
-
- return buffer;
}
- public static final short getShort (ByteBuffer buffer, int index)
+ public static short getShort (ByteBuffer buffer,
+ int index, ByteOrder order)
{
checkAvailableForRead (buffer, index, 2);
- if (buffer.order() == ByteOrder.LITTLE_ENDIAN)
+ if (order == ByteOrder.LITTLE_ENDIAN)
{
return (short) ((buffer.get (index) & 0xff)
+ (buffer.get (++index) << 8));
@@ -135,12 +134,12 @@
+ (buffer.get (++index) & 0xff));
}
- public static final ByteBuffer putShort (ByteBuffer buffer, int index,
- short value)
+ public static void putShort (ByteBuffer buffer, int index,
+ short value, ByteOrder order)
{
checkAvailableForWrite (buffer, index, 2);
- if (buffer.order() == ByteOrder.LITTLE_ENDIAN)
+ if (order == ByteOrder.LITTLE_ENDIAN)
{
buffer.put (index, (byte) value);
buffer.put (++index, (byte) (value >> 8));
@@ -150,15 +149,13 @@
buffer.put (index, (byte) (value >> 8));
buffer.put (++index, (byte) value);
}
-
- return buffer;
}
- public static final int getInt (ByteBuffer buffer)
+ public static int getInt (ByteBuffer buffer, ByteOrder order)
{
checkRemainingForRead (buffer, 4);
- if (buffer.order() == ByteOrder.LITTLE_ENDIAN)
+ if (order == ByteOrder.LITTLE_ENDIAN)
{
return ((buffer.get() & 0xff)
+ ((buffer.get() & 0xff) << 8)
@@ -172,11 +169,11 @@
+ (buffer.get() & 0xff));
}
- public static final ByteBuffer putInt (ByteBuffer buffer, int value)
+ public static void putInt (ByteBuffer buffer, int value, ByteOrder order)
{
checkRemainingForWrite (buffer, 4);
- if (buffer.order() == ByteOrder.LITTLE_ENDIAN)
+ if (order == ByteOrder.LITTLE_ENDIAN)
{
buffer.put ((byte) value);
buffer.put ((byte) (value >> 8));
@@ -190,15 +187,13 @@
buffer.put ((byte) (value >> 8));
buffer.put ((byte) value);
}
-
- return buffer;
}
- public static final int getInt (ByteBuffer buffer, int index)
+ public static int getInt (ByteBuffer buffer, int index, ByteOrder order)
{
checkAvailableForRead (buffer, index, 4);
- if (buffer.order() == ByteOrder.LITTLE_ENDIAN)
+ if (order == ByteOrder.LITTLE_ENDIAN)
{
return ((buffer.get (index) & 0xff)
+ ((buffer.get (++index) & 0xff) << 8)
@@ -212,12 +207,12 @@
+ (buffer.get (++index) & 0xff));
}
- public static final ByteBuffer putInt (ByteBuffer buffer, int index,
- int value)
+ public static void putInt (ByteBuffer buffer, int index,
+ int value, ByteOrder order)
{
checkAvailableForWrite (buffer, index, 4);
- if (buffer.order() == ByteOrder.LITTLE_ENDIAN)
+ if (order == ByteOrder.LITTLE_ENDIAN)
{
buffer.put (index, (byte) value);
buffer.put (++index, (byte) (value >> 8));
@@ -231,15 +226,13 @@
buffer.put (++index, (byte) (value >> 8));
buffer.put (++index, (byte) value);
}
-
- return buffer;
}
- public static final long getLong (ByteBuffer buffer)
+ public static long getLong (ByteBuffer buffer, ByteOrder order)
{
checkRemainingForRead (buffer, 8);
- if (buffer.order() == ByteOrder.LITTLE_ENDIAN)
+ if (order == ByteOrder.LITTLE_ENDIAN)
{
return ((buffer.get() & 0xff)
+ (((buffer.get() & 0xff)) << 8)
@@ -261,11 +254,11 @@
+ (buffer.get() & 0xff));
}
- public static final ByteBuffer putLong (ByteBuffer buffer, long value)
+ public static void putLong (ByteBuffer buffer, long value, ByteOrder order)
{
checkRemainingForWrite (buffer, 8);
- if (buffer.order() == ByteOrder.LITTLE_ENDIAN)
+ if (order == ByteOrder.LITTLE_ENDIAN)
{
buffer.put ((byte) value);
buffer.put ((byte) (value >> 8));
@@ -287,15 +280,13 @@
buffer.put ((byte) (value >> 8));
buffer.put ((byte) value);
}
-
- return buffer;
}
- public static final long getLong (ByteBuffer buffer, int index)
+ public static long getLong (ByteBuffer buffer, int index, ByteOrder order)
{
checkAvailableForRead (buffer, index, 8);
- if (buffer.order() == ByteOrder.LITTLE_ENDIAN)
+ if (order == ByteOrder.LITTLE_ENDIAN)
{
return ((buffer.get (index) & 0xff)
+ ((buffer.get (++index) & 0xff) << 8)
@@ -317,12 +308,12 @@
+ (buffer.get (++index) & 0xff));
}
- public static final ByteBuffer putLong (ByteBuffer buffer, int index,
- long value)
+ public static void putLong (ByteBuffer buffer, int index,
+ long value, ByteOrder order)
{
checkAvailableForWrite (buffer, index, 8);
- if (buffer.order() == ByteOrder.LITTLE_ENDIAN)
+ if (order == ByteOrder.LITTLE_ENDIAN)
{
buffer.put (index, (byte) value);
buffer.put (++index, (byte) (value >> 8));
@@ -344,50 +335,47 @@
buffer.put (++index, (byte) (value >> 8));
buffer.put (++index, (byte) value);
}
-
- return buffer;
}
- public static final float getFloat (ByteBuffer buffer)
+ public static float getFloat (ByteBuffer buffer, ByteOrder order)
{
- return Float.intBitsToFloat (getInt (buffer));
+ return Float.intBitsToFloat (getInt (buffer, order));
}
- public static final ByteBuffer putFloat (ByteBuffer buffer, float value)
+ public static void putFloat (ByteBuffer buffer, float value, ByteOrder order)
{
- return putInt (buffer, Float.floatToRawIntBits (value));
+ putInt (buffer, Float.floatToRawIntBits (value), order);
}
- public static final float getFloat (ByteBuffer buffer, int index)
+ public static float getFloat (ByteBuffer buffer, int index, ByteOrder order)
{
- return Float.intBitsToFloat (getInt (buffer, index));
+ return Float.intBitsToFloat (getInt (buffer, index, order));
}
- public static final ByteBuffer putFloat (ByteBuffer buffer, int index,
- float value)
+ public static void putFloat (ByteBuffer buffer, int index,
+ float value, ByteOrder order)
{
- return putInt (buffer, index, Float.floatToRawIntBits (value));
+ putInt (buffer, index, Float.floatToRawIntBits (value), order);
}
- public static final double getDouble (ByteBuffer buffer)
+ public static double getDouble (ByteBuffer buffer, ByteOrder order)
{
- return Double.longBitsToDouble (getLong (buffer));
+ return Double.longBitsToDouble (getLong (buffer, order));
}
- public static final ByteBuffer putDouble (ByteBuffer buffer, double value)
+ public static void putDouble (ByteBuffer buffer, double value, ByteOrder order)
{
- return putLong (buffer, Double.doubleToLongBits (value));
+ putLong (buffer, Double.doubleToLongBits (value), order);
}
- public static final double getDouble (ByteBuffer buffer, int index)
+ public static double getDouble (ByteBuffer buffer, int index, ByteOrder order)
{
- return Double.longBitsToDouble (getLong (buffer, index));
+ return Double.longBitsToDouble (getLong (buffer, index, order));
}
- public static final ByteBuffer putDouble (ByteBuffer buffer, int index,
- double value)
+ public static void putDouble (ByteBuffer buffer, int index,
+ double value, ByteOrder order)
{
- return putLong (buffer, index, Double.doubleToLongBits (value));
+ putLong (buffer, index, Double.doubleToLongBits (value), order);
}
-
} // ByteBufferHelper
Index: kaffe/libraries/javalib/java/nio/ByteBufferImpl.java
diff -u kaffe/libraries/javalib/java/nio/ByteBufferImpl.java:1.3 kaffe/libraries/javalib/java/nio/ByteBufferImpl.java:1.4
--- kaffe/libraries/javalib/java/nio/ByteBufferImpl.java:1.3 Sun Sep 28 19:54:12 2003
+++ kaffe/libraries/javalib/java/nio/ByteBufferImpl.java Mon Feb 23 22:56:37 2004
@@ -1,5 +1,5 @@
/* ByteBufferImpl.java --
- Copyright (C) 2002, 2003 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -45,45 +45,42 @@
{
private boolean readOnly;
- ByteBufferImpl (int capacity)
- {
- this (new byte [capacity], 0, capacity, capacity, 0, -1, false);
- }
-
ByteBufferImpl (byte[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly)
{
- super (buffer, offset, capacity, limit, position, mark);
+ super (capacity, limit, position, mark);
+ this.backing_buffer = buffer;
+ this.array_offset = offset;
this.readOnly = readOnly;
}
public CharBuffer asCharBuffer ()
{
- return new CharViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly ());
+ return new CharViewBufferImpl (this, remaining() >> 1);
}
public ShortBuffer asShortBuffer ()
{
- return new ShortViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly ());
+ return new ShortViewBufferImpl (this, remaining() >> 1);
}
public IntBuffer asIntBuffer ()
{
- return new IntViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly ());
+ return new IntViewBufferImpl (this, remaining() >> 2);
}
public LongBuffer asLongBuffer ()
{
- return new LongViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly ());
+ return new LongViewBufferImpl (this, remaining() >> 3);
}
public FloatBuffer asFloatBuffer ()
{
- return new FloatViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly ());
+ return new FloatViewBufferImpl (this, remaining() >> 2);
}
public DoubleBuffer asDoubleBuffer ()
{
- return new DoubleViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly ());
+ return new DoubleViewBufferImpl (this, remaining() >> 3);
}
public boolean isReadOnly ()
@@ -106,17 +103,23 @@
return new ByteBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true);
}
+ void shiftDown (int dst_offset, int src_offset, int count)
+ {
+ System.arraycopy(backing_buffer, array_offset + src_offset,
+ backing_buffer, array_offset + dst_offset,
+ count);
+ }
+
public ByteBuffer compact ()
{
- int copied = 0;
-
- while (remaining () > 0)
+ int pos = position();
+ if (pos > 0)
{
- put (copied, get ());
- copied++;
+ int count = remaining();
+ shiftDown(0, pos, count);
+ position(count);
+ limit(capacity());
}
-
- position (copied);
return this;
}
@@ -130,7 +133,7 @@
*/
final public byte get ()
{
- byte result = backing_buffer [position ()];
+ byte result = backing_buffer [position () + array_offset];
position (position () + 1);
return result;
}
@@ -145,9 +148,10 @@
{
if (readOnly)
throw new ReadOnlyBufferException ();
-
- backing_buffer [position ()] = value;
- position (position () + 1);
+
+ int pos = position();
+ backing_buffer [pos + array_offset] = value;
+ position (pos + 1);
return this;
}
@@ -160,7 +164,7 @@
*/
final public byte get (int index)
{
- return backing_buffer [index];
+ return backing_buffer [index + array_offset];
}
/**
@@ -176,127 +180,139 @@
if (readOnly)
throw new ReadOnlyBufferException ();
- backing_buffer [index] = value;
+ backing_buffer [index + array_offset] = value;
return this;
}
final public char getChar ()
{
- return ByteBufferHelper.getChar (this);
+ return ByteBufferHelper.getChar(this, order());
}
final public ByteBuffer putChar (char value)
{
- return ByteBufferHelper.putChar (this, value);
+ ByteBufferHelper.putChar(this, value, order());
+ return this;
}
final public char getChar (int index)
{
- return ByteBufferHelper.getChar (this, index);
+ return ByteBufferHelper.getChar(this, index, order());
}
final public ByteBuffer putChar (int index, char value)
{
- return ByteBufferHelper.putChar (this, index, value);
+ ByteBufferHelper.putChar(this, index, value, order());
+ return this;
}
final public short getShort ()
{
- return ByteBufferHelper.getShort (this);
+ return ByteBufferHelper.getShort(this, order());
}
final public ByteBuffer putShort (short value)
{
- return ByteBufferHelper.putShort (this, value);
+ ByteBufferHelper.putShort(this, value, order());
+ return this;
}
final public short getShort (int index)
{
- return ByteBufferHelper.getShort (this, index);
+ return ByteBufferHelper.getShort(this, index, order());
}
final public ByteBuffer putShort (int index, short value)
{
- return ByteBufferHelper.putShort (this, index, value);
+ ByteBufferHelper.putShort(this, index, value, order());
+ return this;
}
final public int getInt ()
{
- return ByteBufferHelper.getInt (this);
+ return ByteBufferHelper.getInt(this, order());
}
final public ByteBuffer putInt (int value)
{
- return ByteBufferHelper.putInt (this, value);
+ ByteBufferHelper.putInt(this, value, order());
+ return this;
}
final public int getInt (int index)
{
- return ByteBufferHelper.getInt (this, index);
+ return ByteBufferHelper.getInt(this, index, order());
}
final public ByteBuffer putInt (int index, int value)
{
- return ByteBufferHelper.putInt (this, index, value);
+ ByteBufferHelper.putInt(this, index, value, order());
+ return this;
}
final public long getLong ()
{
- return ByteBufferHelper.getLong (this);
+ return ByteBufferHelper.getLong(this, order());
}
final public ByteBuffer putLong (long value)
{
- return ByteBufferHelper.putLong (this, value);
+ ByteBufferHelper.putLong (this, value, order());
+ return this;
}
final public long getLong (int index)
{
- return ByteBufferHelper.getLong (this, index);
+ return ByteBufferHelper.getLong (this, index, order());
}
final public ByteBuffer putLong (int index, long value)
{
- return ByteBufferHelper.putLong (this, index, value);
+ ByteBufferHelper.putLong (this, index, value, order());
+ return this;
}
final public float getFloat ()
{
- return ByteBufferHelper.getFloat (this);
+ return ByteBufferHelper.getFloat (this, order());
}
final public ByteBuffer putFloat (float value)
{
- return ByteBufferHelper.putFloat (this, value);
+ ByteBufferHelper.putFloat (this, value, order());
+ return this;
}
- final public float getFloat (int index)
+ public final float getFloat (int index)
{
- return ByteBufferHelper.getFloat (this, index);
+ return ByteBufferHelper.getFloat (this, index, order());
}
- public final ByteBuffer putFloat (int index, float value)
+ final public ByteBuffer putFloat (int index, float value)
{
- return ByteBufferHelper.putFloat (this, index, value);
+ ByteBufferHelper.putFloat (this, index, value, order());
+ return this;
}
final public double getDouble ()
{
- return ByteBufferHelper.getDouble (this);
+ return ByteBufferHelper.getDouble (this, order());
}
final public ByteBuffer putDouble (double value)
{
- return ByteBufferHelper.putDouble (this, value);
+ ByteBufferHelper.putDouble (this, value, order());
+ return this;
}
final public double getDouble (int index)
{
- return ByteBufferHelper.getDouble (this, index);
+ return ByteBufferHelper.getDouble (this, index, order());
}
final public ByteBuffer putDouble (int index, double value)
{
- return ByteBufferHelper.putDouble (this, index, value);
+ ByteBufferHelper.putDouble (this, index, value, order());
+ return this;
}
}
Index: kaffe/libraries/javalib/java/nio/CharBuffer.java
diff -u kaffe/libraries/javalib/java/nio/CharBuffer.java:1.7 kaffe/libraries/javalib/java/nio/CharBuffer.java:1.8
--- kaffe/libraries/javalib/java/nio/CharBuffer.java:1.7 Sun Aug 10 18:47:53 2003
+++ kaffe/libraries/javalib/java/nio/CharBuffer.java Mon Feb 23 22:56:37 2004
@@ -53,13 +53,6 @@
array_offset = 0;
}
- CharBuffer (char[] buffer, int offset, int capacity, int limit, int position, int mark)
- {
- super (capacity, limit, position, mark);
- this.backing_buffer = buffer;
- this.array_offset = offset;
- }
-
/**
* Allocates a new <code>CharBuffer</code> object with a given capacity.
*/
Index: kaffe/libraries/javalib/java/nio/CharBufferImpl.java
diff -u kaffe/libraries/javalib/java/nio/CharBufferImpl.java:1.2 kaffe/libraries/javalib/java/nio/CharBufferImpl.java:1.3
--- kaffe/libraries/javalib/java/nio/CharBufferImpl.java:1.2 Sun Aug 10 18:47:53 2003
+++ kaffe/libraries/javalib/java/nio/CharBufferImpl.java Mon Feb 23 22:56:37 2004
@@ -52,7 +52,9 @@
CharBufferImpl (char[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly)
{
- super (buffer, offset, capacity, limit, position, mark);
+ super (capacity, limit, position, mark);
+ this.backing_buffer = buffer;
+ this.array_offset = offset;
this.readOnly = readOnly;
}
Index: kaffe/libraries/javalib/java/nio/CharViewBufferImpl.java
diff -u kaffe/libraries/javalib/java/nio/CharViewBufferImpl.java:1.1 kaffe/libraries/javalib/java/nio/CharViewBufferImpl.java:1.2
--- kaffe/libraries/javalib/java/nio/CharViewBufferImpl.java:1.1 Wed May 28 18:15:45 2003
+++ kaffe/libraries/javalib/java/nio/CharViewBufferImpl.java Mon Feb 23 22:56:37 2004
@@ -1,5 +1,5 @@
/* CharViewBufferImpl.java --
- Copyright (C) 2003 Free Software Foundation, Inc.
+ Copyright (C) 2003, 2004 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -40,54 +40,56 @@
class CharViewBufferImpl extends CharBuffer
{
- private boolean readOnly;
+ /** Position in bb (i.e. a byte offset) where this buffer starts. */
private int offset;
private ByteBuffer bb;
+ private boolean readOnly;
private ByteOrder endian;
- public CharViewBufferImpl (ByteBuffer bb, boolean readOnly)
+ CharViewBufferImpl (ByteBuffer bb, int capacity)
{
- super (bb.remaining () >> 1, bb.remaining () >> 1, bb.position (), 0);
+ super (capacity, capacity, 0, -1);
this.bb = bb;
- this.readOnly = readOnly;
- // FIXME: What if this is called from CharByteBufferImpl and ByteBuffer has changed its endianess ?
- this.endian = bb.order ();
+ 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)
+ int limit, int position, int mark,
+ boolean readOnly, ByteOrder endian)
{
- super (limit >> 1, limit >> 1, position >> 1, mark >> 1);
+ super (capacity, limit, position, mark);
this.bb = bb;
this.offset = offset;
this.readOnly = readOnly;
*** Patch too long, truncated ***
More information about the kaffe
mailing list