Index: java/nio/ByteBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/ByteBuffer.java,v
retrieving revision 1.18
diff -u -b -B -r1.18 ByteBuffer.java
--- java/nio/ByteBuffer.java 11 Feb 2004 19:05:14 -0000 1.18
+++ java/nio/ByteBuffer.java 17 Feb 2004 21:43:24 -0000
@@ -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,14 +52,6 @@
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;
}
/**
@@ -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++)
{
Index: java/nio/ByteBufferImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/ByteBufferImpl.java,v
retrieving revision 1.4
diff -u -b -B -r1.4 ByteBufferImpl.java
--- java/nio/ByteBufferImpl.java 11 Feb 2004 19:05:14 -0000 1.4
+++ java/nio/ByteBufferImpl.java 17 Feb 2004 21:43:25 -0000
@@ -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 (), order());
+ return new CharViewBufferImpl (this, remaining() >> 1);
}
public ShortBuffer asShortBuffer ()
{
- return new ShortViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly (), order());
+ return new ShortViewBufferImpl (this, remaining() >> 1);
}
public IntBuffer asIntBuffer ()
{
- return new IntViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly (), order());
+ return new IntViewBufferImpl (this, remaining() >> 2);
}
public LongBuffer asLongBuffer ()
{
- return new LongViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly (), order());
+ return new LongViewBufferImpl (this, remaining() >> 3);
}
public FloatBuffer asFloatBuffer ()
{
- return new FloatViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly (), order());
+ return new FloatViewBufferImpl (this, remaining() >> 2);
}
public DoubleBuffer asDoubleBuffer ()
{
- return new DoubleViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly (), order());
+ return new DoubleViewBufferImpl (this, remaining() >> 3);
}
public boolean isReadOnly ()
@@ -106,6 +103,13 @@
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 pos = position();
@@ -129,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,8 +149,9 @@
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;
}
@@ -159,7 +164,7 @@
*/
final public byte get (int index)
{
- return backing_buffer [index];
+ return backing_buffer [index + array_offset];
}
/**
@@ -175,7 +180,7 @@
if (readOnly)
throw new ReadOnlyBufferException ();
- backing_buffer [index] = value;
+ backing_buffer [index + array_offset] = value;
return this;
}
Index: java/nio/CharBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/CharBuffer.java,v
retrieving revision 1.17
diff -u -b -B -r1.17 CharBuffer.java
--- java/nio/CharBuffer.java 11 Jun 2003 15:15:08 -0000 1.17
+++ java/nio/CharBuffer.java 17 Feb 2004 21:43:25 -0000
@@ -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 CharBuffer
object with a given capacity.
*/
Index: java/nio/CharBufferImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/CharBufferImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 CharBufferImpl.java
--- java/nio/CharBufferImpl.java 27 Jun 2003 21:03:52 -0000 1.2
+++ java/nio/CharBufferImpl.java 17 Feb 2004 21:43:25 -0000
@@ -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: java/nio/CharViewBufferImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/CharViewBufferImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 CharViewBufferImpl.java
--- java/nio/CharViewBufferImpl.java 11 Feb 2004 19:05:14 -0000 1.2
+++ java/nio/CharViewBufferImpl.java 17 Feb 2004 21:43:25 -0000
@@ -46,11 +46,20 @@
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 (limit >> 1, limit >> 1, position >> 1, mark >> 1);
+ super (capacity, limit, position, mark);
this.bb = bb;
this.offset = offset;
this.readOnly = readOnly;
Index: java/nio/DoubleBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/DoubleBuffer.java,v
retrieving revision 1.13
diff -u -b -B -r1.13 DoubleBuffer.java
--- java/nio/DoubleBuffer.java 11 Jun 2003 15:15:08 -0000 1.13
+++ java/nio/DoubleBuffer.java 17 Feb 2004 21:43:25 -0000
@@ -53,13 +53,6 @@
array_offset = 0;
}
- DoubleBuffer (double[] 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 DoubleBuffer
object with a given capacity.
*/
Index: java/nio/DoubleBufferImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/DoubleBufferImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 DoubleBufferImpl.java
--- java/nio/DoubleBufferImpl.java 27 Jun 2003 21:03:52 -0000 1.2
+++ java/nio/DoubleBufferImpl.java 17 Feb 2004 21:43:25 -0000
@@ -52,7 +52,9 @@
DoubleBufferImpl (double[] 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: java/nio/DoubleViewBufferImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/DoubleViewBufferImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 DoubleViewBufferImpl.java
--- java/nio/DoubleViewBufferImpl.java 11 Feb 2004 19:05:14 -0000 1.2
+++ java/nio/DoubleViewBufferImpl.java 17 Feb 2004 21:43:25 -0000
@@ -46,11 +46,20 @@
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 (limit >> 3, limit >> 3, position >> 3, mark >> 3);
+ super (capacity, limit, position, mark);
this.bb = bb;
this.offset = offset;
this.readOnly = readOnly;
Index: java/nio/FloatBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/FloatBuffer.java,v
retrieving revision 1.13
diff -u -b -B -r1.13 FloatBuffer.java
--- java/nio/FloatBuffer.java 11 Jun 2003 15:15:08 -0000 1.13
+++ java/nio/FloatBuffer.java 17 Feb 2004 21:43:25 -0000
@@ -53,13 +53,6 @@
array_offset = 0;
}
- FloatBuffer (float[] 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 FloatBuffer
object with a given capacity.
*/
Index: java/nio/FloatBufferImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/FloatBufferImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 FloatBufferImpl.java
--- java/nio/FloatBufferImpl.java 27 Jun 2003 21:03:52 -0000 1.2
+++ java/nio/FloatBufferImpl.java 17 Feb 2004 21:43:25 -0000
@@ -52,7 +52,9 @@
FloatBufferImpl (float[] 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: java/nio/FloatViewBufferImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/FloatViewBufferImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 FloatViewBufferImpl.java
--- java/nio/FloatViewBufferImpl.java 11 Feb 2004 19:05:14 -0000 1.2
+++ java/nio/FloatViewBufferImpl.java 17 Feb 2004 21:43:25 -0000
@@ -46,11 +46,20 @@
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 (limit >> 2, limit >> 2, position >> 2, mark >> 2);
+ super (capacity, limit, position, mark);
this.bb = bb;
this.offset = offset;
this.readOnly = readOnly;
Index: java/nio/IntBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/IntBuffer.java,v
retrieving revision 1.13
diff -u -b -B -r1.13 IntBuffer.java
--- java/nio/IntBuffer.java 11 Jun 2003 15:15:08 -0000 1.13
+++ java/nio/IntBuffer.java 17 Feb 2004 21:43:25 -0000
@@ -53,13 +53,6 @@
array_offset = 0;
}
- IntBuffer (int[] 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 IntBuffer
object with a given capacity.
*/
Index: java/nio/IntBufferImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/IntBufferImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 IntBufferImpl.java
--- java/nio/IntBufferImpl.java 27 Jun 2003 21:03:52 -0000 1.2
+++ java/nio/IntBufferImpl.java 17 Feb 2004 21:43:25 -0000
@@ -52,7 +52,9 @@
IntBufferImpl (int[] 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: java/nio/IntViewBufferImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/IntViewBufferImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 IntViewBufferImpl.java
--- java/nio/IntViewBufferImpl.java 11 Feb 2004 19:05:14 -0000 1.2
+++ java/nio/IntViewBufferImpl.java 17 Feb 2004 21:43:25 -0000
@@ -46,11 +46,20 @@
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 (limit >> 2, limit >> 2, position >> 2, mark >> 2);
+ super (capacity, limit, position, mark);
this.bb = bb;
this.offset = offset;
this.readOnly = readOnly;
Index: java/nio/LongBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/LongBuffer.java,v
retrieving revision 1.13
diff -u -b -B -r1.13 LongBuffer.java
--- java/nio/LongBuffer.java 11 Jun 2003 15:15:08 -0000 1.13
+++ java/nio/LongBuffer.java 17 Feb 2004 21:43:25 -0000
@@ -53,13 +53,6 @@
array_offset = 0;
}
- LongBuffer (long[] 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 LongBuffer
object with a given capacity.
*/
Index: java/nio/LongBufferImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/LongBufferImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 LongBufferImpl.java
--- java/nio/LongBufferImpl.java 27 Jun 2003 21:03:52 -0000 1.2
+++ java/nio/LongBufferImpl.java 17 Feb 2004 21:43:25 -0000
@@ -52,7 +52,9 @@
LongBufferImpl (long[] 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: java/nio/LongViewBufferImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/LongViewBufferImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 LongViewBufferImpl.java
--- java/nio/LongViewBufferImpl.java 11 Feb 2004 19:05:14 -0000 1.2
+++ java/nio/LongViewBufferImpl.java 17 Feb 2004 21:43:25 -0000
@@ -46,11 +46,20 @@
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 (limit >> 3, limit >> 3, position >> 3, mark >> 3);
+ super (capacity, limit, position, mark);
this.bb = bb;
this.offset = offset;
this.readOnly = readOnly;
Index: java/nio/MappedByteBufferImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/MappedByteBufferImpl.java,v
retrieving revision 1.6
diff -u -b -B -r1.6 MappedByteBufferImpl.java
--- java/nio/MappedByteBufferImpl.java 11 Feb 2004 19:05:14 -0000 1.6
+++ java/nio/MappedByteBufferImpl.java 17 Feb 2004 21:43:25 -0000
@@ -144,32 +144,32 @@
public CharBuffer asCharBuffer ()
{
- return new CharViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly (), order());
+ return new CharViewBufferImpl (this, remaining() >> 1);
}
public ShortBuffer asShortBuffer ()
{
- return new ShortViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly (), order());
+ return new ShortViewBufferImpl (this, remaining() >> 1);
}
public IntBuffer asIntBuffer ()
{
- return new IntViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly (), order());
+ return new IntViewBufferImpl (this, remaining() >> 2);
}
public LongBuffer asLongBuffer ()
{
- return new LongViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly (), order());
+ return new LongViewBufferImpl (this, remaining() >> 3);
}
public FloatBuffer asFloatBuffer ()
{
- return new FloatViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly (), order());
+ return new FloatViewBufferImpl (this, remaining() >> 2);
}
public DoubleBuffer asDoubleBuffer ()
{
- return new DoubleViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly (), order());
+ return new DoubleViewBufferImpl (this, remaining() >> 3);
}
final public char getChar ()
Index: java/nio/ShortBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/ShortBuffer.java,v
retrieving revision 1.14
diff -u -b -B -r1.14 ShortBuffer.java
--- java/nio/ShortBuffer.java 11 Jun 2003 15:15:08 -0000 1.14
+++ java/nio/ShortBuffer.java 17 Feb 2004 21:43:25 -0000
@@ -53,13 +53,6 @@
array_offset = 0;
}
- ShortBuffer (short[] 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 ShortBuffer
object with a given capacity.
*/
Index: java/nio/ShortBufferImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/ShortBufferImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 ShortBufferImpl.java
--- java/nio/ShortBufferImpl.java 27 Jun 2003 21:03:52 -0000 1.2
+++ java/nio/ShortBufferImpl.java 17 Feb 2004 21:43:25 -0000
@@ -52,7 +52,9 @@
ShortBufferImpl (short[] 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: java/nio/ShortViewBufferImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/ShortViewBufferImpl.java,v
retrieving revision 1.2
diff -u -b -B -r1.2 ShortViewBufferImpl.java
--- java/nio/ShortViewBufferImpl.java 11 Feb 2004 19:05:14 -0000 1.2
+++ java/nio/ShortViewBufferImpl.java 17 Feb 2004 21:43:25 -0000
@@ -46,11 +46,20 @@
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 (limit >> 1, limit >> 1, position >> 1, mark >> 1);
+ super (capacity, limit, position, mark);
this.bb = bb;
this.offset = offset;
this.readOnly = readOnly;