aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/nio/ByteBufferImpl.java
diff options
context:
space:
mode:
authorMichael Koch <mkoch@gcc.gnu.org>2005-04-20 06:05:04 +0000
committerMichael Koch <mkoch@gcc.gnu.org>2005-04-20 06:05:04 +0000
commitebce970d7fa5aac9c4dea5381784441e155dbb64 (patch)
tree299c11c27a0bdee12676f0fa833c032c9a885cc7 /libjava/java/nio/ByteBufferImpl.java
parentce254988cf72001d72092a6ec0935121bfe64185 (diff)
downloadgcc-ebce970d7fa5aac9c4dea5381784441e155dbb64.zip
gcc-ebce970d7fa5aac9c4dea5381784441e155dbb64.tar.gz
gcc-ebce970d7fa5aac9c4dea5381784441e155dbb64.tar.bz2
[multiple changes]
2005-04-20 Sven de Marothy <sven@physto.se> * java/nio/ByteBufferImpl.java: (putChar): Inlined for speed. (put, get): Bulk methods can use arraycopy. * java/nio/CharBufferImpl.java: (put, get): Bulk methods can use arraycopy. 2005-04-20 Jeroen Frijters <jeroen@frijters.net> * java/nio/ByteBufferImpl.java (get(), put(byte)): Inlined checks and field updates. * java/nio/CharBufferImpl.java (CharBufferImpl(CharBufferImpl)): Copy array_offset field. (get(), put(char)): Inlined checks and field updates. Fixed to take array_offset into account. (get(int), put(int, char)): Fixed to take array_offset into account. From-SVN: r98445
Diffstat (limited to 'libjava/java/nio/ByteBufferImpl.java')
-rw-r--r--libjava/java/nio/ByteBufferImpl.java66
1 files changed, 55 insertions, 11 deletions
diff --git a/libjava/java/nio/ByteBufferImpl.java b/libjava/java/nio/ByteBufferImpl.java
index d9f2462..4796170 100644
--- a/libjava/java/nio/ByteBufferImpl.java
+++ b/libjava/java/nio/ByteBufferImpl.java
@@ -144,13 +144,43 @@ final class ByteBufferImpl extends ByteBuffer
*/
public byte get ()
{
- checkForUnderflow();
+ if (pos >= limit)
+ throw new BufferUnderflowException();
- byte result = backing_buffer [position () + array_offset];
- position (position () + 1);
- return result;
+ return backing_buffer [(pos++) + array_offset];
}
-
+
+ /**
+ * Bulk get
+ */
+ public ByteBuffer get (byte[] dst, int offset, int length)
+ {
+ checkArraySize(dst.length, offset, length);
+ if ( (limit - pos) < length) // check for overflow
+ throw new BufferUnderflowException();
+
+ System.arraycopy(backing_buffer, pos + array_offset,
+ dst, offset, length);
+ pos += length;
+
+ return this;
+ }
+
+ /**
+ * Relative bulk put(), overloads the ByteBuffer impl.
+ */
+ public ByteBuffer put (byte[] src, int offset, int length)
+ {
+ if ( (limit - pos) < length) // check for overflow
+ throw new BufferOverflowException();
+ checkArraySize(src.length, offset, length);
+
+ System.arraycopy(src, offset, backing_buffer, pos + array_offset, length);
+ pos += length;
+
+ return this;
+ }
+
/**
* Relative put method. Writes <code>value</code> to the next position
* in the buffer.
@@ -161,12 +191,12 @@ final class ByteBufferImpl extends ByteBuffer
*/
public ByteBuffer put (byte value)
{
- checkIfReadOnly();
- checkForOverflow();
+ if (readOnly)
+ throw new ReadOnlyBufferException();
+ if (pos >= limit)
+ throw new BufferOverflowException();
- int pos = position();
- backing_buffer [pos + array_offset] = value;
- position (pos + 1);
+ backing_buffer [(pos++) + array_offset] = value;
return this;
}
@@ -208,7 +238,21 @@ final class ByteBufferImpl extends ByteBuffer
public ByteBuffer putChar (char value)
{
- ByteBufferHelper.putChar(this, value, order());
+ if (readOnly)
+ throw new ReadOnlyBufferException ();
+ if ( (limit-pos) < 2)
+ throw new BufferOverflowException();
+
+ if (endian == ByteOrder.LITTLE_ENDIAN)
+ {
+ backing_buffer [(pos++) + array_offset] = (byte)(value&0xFF);
+ backing_buffer [(pos++) + array_offset] = (byte)(value>>8);
+ }
+ else
+ {
+ backing_buffer [(pos++) + array_offset] = (byte)(value>>8);
+ backing_buffer [(pos++) + array_offset] = (byte)(value&0xFF);
+ }
return this;
}