summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Koch <konqueror@gmx.de>2004-02-17 21:44:53 +0000
committerMichael Koch <konqueror@gmx.de>2004-02-17 21:44:53 +0000
commitfdd25e52a51557e1ce1711ba16f20d5e86804a40 (patch)
treee9d1e5f776f0929dfc14251777f2bf1446100110
parentaa55317081b358693ff281fe159049c6d7f89e7a (diff)
downloadclasspath-fdd25e52a51557e1ce1711ba16f20d5e86804a40.tar.gz
2004-02-17 Per Bothner <per@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.
-rw-r--r--ChangeLog43
-rw-r--r--java/nio/ByteBuffer.java27
-rw-r--r--java/nio/ByteBufferImpl.java41
-rw-r--r--java/nio/CharBuffer.java7
-rw-r--r--java/nio/CharBufferImpl.java4
-rw-r--r--java/nio/CharViewBufferImpl.java11
-rw-r--r--java/nio/DoubleBuffer.java7
-rw-r--r--java/nio/DoubleBufferImpl.java4
-rw-r--r--java/nio/DoubleViewBufferImpl.java11
-rw-r--r--java/nio/FloatBuffer.java7
-rw-r--r--java/nio/FloatBufferImpl.java4
-rw-r--r--java/nio/FloatViewBufferImpl.java11
-rw-r--r--java/nio/IntBuffer.java7
-rw-r--r--java/nio/IntBufferImpl.java4
-rw-r--r--java/nio/IntViewBufferImpl.java11
-rw-r--r--java/nio/LongBuffer.java7
-rw-r--r--java/nio/LongBufferImpl.java4
-rw-r--r--java/nio/LongViewBufferImpl.java11
-rw-r--r--java/nio/MappedByteBufferImpl.java14
-rw-r--r--java/nio/ShortBuffer.java7
-rw-r--r--java/nio/ShortBufferImpl.java4
-rw-r--r--java/nio/ShortViewBufferImpl.java11
22 files changed, 164 insertions, 93 deletions
diff --git a/ChangeLog b/ChangeLog
index d0ca42937..96f3af54a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,48 @@
2004-02-17 Per Bothner <per@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-17 Per Bothner <per@bothner.com>
+
* java/nio/channels/spi/AbstractInterruptibleChannel.java (close):
Set closed before calling implCloseChannel, as in the spec.
diff --git a/java/nio/ByteBuffer.java b/java/nio/ByteBuffer.java
index 9ca20618c..276b2dbcb 100644
--- a/java/nio/ByteBuffer.java
+++ b/java/nio/ByteBuffer.java
@@ -44,7 +44,7 @@ package java.nio;
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 @@ public abstract class ByteBuffer extends Buffer
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 abstract class ByteBuffer extends Buffer
*/
public static ByteBuffer allocate (int capacity)
{
- return new ByteBufferImpl (capacity);
+ return wrap(new byte[capacity], 0, capacity);
}
/**
@@ -87,6 +79,14 @@ public abstract class ByteBuffer extends Buffer
*/
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 abstract class ByteBuffer extends Buffer
*/
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++)
{
diff --git a/java/nio/ByteBufferImpl.java b/java/nio/ByteBufferImpl.java
index 6a3814862..5d3c3d31a 100644
--- a/java/nio/ByteBufferImpl.java
+++ b/java/nio/ByteBufferImpl.java
@@ -45,45 +45,42 @@ final class ByteBufferImpl extends ByteBuffer
{
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 @@ final class ByteBufferImpl extends ByteBuffer
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 class ByteBufferImpl extends ByteBuffer
*/
final public byte get ()
{
- byte result = backing_buffer [position ()];
+ byte result = backing_buffer [position () + array_offset];
position (position () + 1);
return result;
}
@@ -144,9 +148,10 @@ final class ByteBufferImpl extends ByteBuffer
{
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 class ByteBufferImpl extends ByteBuffer
*/
final public byte get (int index)
{
- return backing_buffer [index];
+ return backing_buffer [index + array_offset];
}
/**
@@ -175,7 +180,7 @@ final class ByteBufferImpl extends ByteBuffer
if (readOnly)
throw new ReadOnlyBufferException ();
- backing_buffer [index] = value;
+ backing_buffer [index + array_offset] = value;
return this;
}
diff --git a/java/nio/CharBuffer.java b/java/nio/CharBuffer.java
index 15a535709..3d488bad3 100644
--- a/java/nio/CharBuffer.java
+++ b/java/nio/CharBuffer.java
@@ -53,13 +53,6 @@ public abstract class CharBuffer extends Buffer
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.
*/
diff --git a/java/nio/CharBufferImpl.java b/java/nio/CharBufferImpl.java
index d22b4d1b2..aacc2cb26 100644
--- a/java/nio/CharBufferImpl.java
+++ b/java/nio/CharBufferImpl.java
@@ -52,7 +52,9 @@ final class CharBufferImpl extends CharBuffer
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;
}
diff --git a/java/nio/CharViewBufferImpl.java b/java/nio/CharViewBufferImpl.java
index b1cc90717..ee99cfbe0 100644
--- a/java/nio/CharViewBufferImpl.java
+++ b/java/nio/CharViewBufferImpl.java
@@ -46,11 +46,20 @@ class CharViewBufferImpl extends CharBuffer
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;
diff --git a/java/nio/DoubleBuffer.java b/java/nio/DoubleBuffer.java
index 644f33ba6..d669c2138 100644
--- a/java/nio/DoubleBuffer.java
+++ b/java/nio/DoubleBuffer.java
@@ -53,13 +53,6 @@ public abstract class DoubleBuffer extends Buffer
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 <code>DoubleBuffer</code> object with a given capacity.
*/
diff --git a/java/nio/DoubleBufferImpl.java b/java/nio/DoubleBufferImpl.java
index 8dacec9be..2c425dceb 100644
--- a/java/nio/DoubleBufferImpl.java
+++ b/java/nio/DoubleBufferImpl.java
@@ -52,7 +52,9 @@ final class DoubleBufferImpl extends DoubleBuffer
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;
}
diff --git a/java/nio/DoubleViewBufferImpl.java b/java/nio/DoubleViewBufferImpl.java
index ac27746ba..7df2f509b 100644
--- a/java/nio/DoubleViewBufferImpl.java
+++ b/java/nio/DoubleViewBufferImpl.java
@@ -46,11 +46,20 @@ class DoubleViewBufferImpl extends DoubleBuffer
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;
diff --git a/java/nio/FloatBuffer.java b/java/nio/FloatBuffer.java
index 5fcfc8e6e..0c7b04dd0 100644
--- a/java/nio/FloatBuffer.java
+++ b/java/nio/FloatBuffer.java
@@ -53,13 +53,6 @@ public abstract class FloatBuffer extends Buffer
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 <code>FloatBuffer</code> object with a given capacity.
*/
diff --git a/java/nio/FloatBufferImpl.java b/java/nio/FloatBufferImpl.java
index db0f52bb4..065841324 100644
--- a/java/nio/FloatBufferImpl.java
+++ b/java/nio/FloatBufferImpl.java
@@ -52,7 +52,9 @@ final class FloatBufferImpl extends FloatBuffer
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;
}
diff --git a/java/nio/FloatViewBufferImpl.java b/java/nio/FloatViewBufferImpl.java
index 88bc92553..c4caf9bf3 100644
--- a/java/nio/FloatViewBufferImpl.java
+++ b/java/nio/FloatViewBufferImpl.java
@@ -46,11 +46,20 @@ class FloatViewBufferImpl extends FloatBuffer
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;
diff --git a/java/nio/IntBuffer.java b/java/nio/IntBuffer.java
index 791678595..469a344ea 100644
--- a/java/nio/IntBuffer.java
+++ b/java/nio/IntBuffer.java
@@ -53,13 +53,6 @@ public abstract class IntBuffer extends Buffer
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 <code>IntBuffer</code> object with a given capacity.
*/
diff --git a/java/nio/IntBufferImpl.java b/java/nio/IntBufferImpl.java
index ec444c014..f14282710 100644
--- a/java/nio/IntBufferImpl.java
+++ b/java/nio/IntBufferImpl.java
@@ -52,7 +52,9 @@ final class IntBufferImpl extends IntBuffer
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;
}
diff --git a/java/nio/IntViewBufferImpl.java b/java/nio/IntViewBufferImpl.java
index 8e384c901..3c8e8e61c 100644
--- a/java/nio/IntViewBufferImpl.java
+++ b/java/nio/IntViewBufferImpl.java
@@ -46,11 +46,20 @@ class IntViewBufferImpl extends IntBuffer
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;
diff --git a/java/nio/LongBuffer.java b/java/nio/LongBuffer.java
index a39a83d94..712e0b3b5 100644
--- a/java/nio/LongBuffer.java
+++ b/java/nio/LongBuffer.java
@@ -53,13 +53,6 @@ public abstract class LongBuffer extends Buffer
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 <code>LongBuffer</code> object with a given capacity.
*/
diff --git a/java/nio/LongBufferImpl.java b/java/nio/LongBufferImpl.java
index b4fb3de5f..7f99f3366 100644
--- a/java/nio/LongBufferImpl.java
+++ b/java/nio/LongBufferImpl.java
@@ -52,7 +52,9 @@ final class LongBufferImpl extends LongBuffer
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;
}
diff --git a/java/nio/LongViewBufferImpl.java b/java/nio/LongViewBufferImpl.java
index a405ec871..9765de9cd 100644
--- a/java/nio/LongViewBufferImpl.java
+++ b/java/nio/LongViewBufferImpl.java
@@ -46,11 +46,20 @@ class LongViewBufferImpl extends LongBuffer
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;
diff --git a/java/nio/MappedByteBufferImpl.java b/java/nio/MappedByteBufferImpl.java
index 631fc91c9..ccec7e3e4 100644
--- a/java/nio/MappedByteBufferImpl.java
+++ b/java/nio/MappedByteBufferImpl.java
@@ -144,32 +144,32 @@ public class MappedByteBufferImpl extends MappedByteBuffer
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 ()
diff --git a/java/nio/ShortBuffer.java b/java/nio/ShortBuffer.java
index 6bd3de9c7..61097d04d 100644
--- a/java/nio/ShortBuffer.java
+++ b/java/nio/ShortBuffer.java
@@ -53,13 +53,6 @@ public abstract class ShortBuffer extends Buffer
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 <code>ShortBuffer</code> object with a given capacity.
*/
diff --git a/java/nio/ShortBufferImpl.java b/java/nio/ShortBufferImpl.java
index 5f6c60137..938d5ce89 100644
--- a/java/nio/ShortBufferImpl.java
+++ b/java/nio/ShortBufferImpl.java
@@ -52,7 +52,9 @@ final class ShortBufferImpl extends ShortBuffer
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;
}
diff --git a/java/nio/ShortViewBufferImpl.java b/java/nio/ShortViewBufferImpl.java
index b217f1cb5..04d778578 100644
--- a/java/nio/ShortViewBufferImpl.java
+++ b/java/nio/ShortViewBufferImpl.java
@@ -45,12 +45,21 @@ class ShortViewBufferImpl extends ShortBuffer
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 (limit >> 1, limit >> 1, position >> 1, mark >> 1);
+ super (capacity, limit, position, mark);
this.bb = bb;
this.offset = offset;
this.readOnly = readOnly;