aboutsummaryrefslogtreecommitdiff
path: root/libjava/java
diff options
context:
space:
mode:
authorDalibor Topic <robilad@kaffe.org>2004-07-09 13:40:29 +0000
committerMichael Koch <mkoch@gcc.gnu.org>2004-07-09 13:40:29 +0000
commit23c41c08339da4bdf677ade01e17d940b7ce6201 (patch)
treec31d17690c1b5f17448be3c1f8e58e48109d8857 /libjava/java
parente484d7d5b33c3b6c9059d0e61fb08fd9e7f3bc68 (diff)
downloadgcc-23c41c08339da4bdf677ade01e17d940b7ce6201.zip
gcc-23c41c08339da4bdf677ade01e17d940b7ce6201.tar.gz
gcc-23c41c08339da4bdf677ade01e17d940b7ce6201.tar.bz2
Buffer.java, [...]: Fixed javadocs all over.
2004-07-09 Dalibor Topic <robilad@kaffe.org> * java/nio/Buffer.java, java/nio/ByteBuffer.java, java/nio/ByteBufferHelper.java, java/nio/ByteBufferImpl.java, java/nio/CharBuffer.java, java/nio/CharBufferImpl.java, java/nio/CharViewBufferImpl.java, java/nio/DirectByteBufferImpl.java, java/nio/DoubleBuffer.java, java/nio/DoubleBufferImpl.java, java/nio/DoubleViewBufferImpl.java, java/nio/FloatBuffer.java, java/nio/FloatBufferImpl.java, java/nio/FloatViewBufferImpl.java, java/nio/IntBuffer.java, java/nio/IntBufferImpl.java, java/nio/IntViewBufferImpl.java, java/nio/LongBuffer.java, java/nio/LongBufferImpl.java, java/nio/LongViewBufferImpl.java, java/nio/MappedByteBufferImpl.java, java/nio/ShortBuffer.java, java/nio/ShortBufferImpl.java, java/nio/ShortViewBufferImpl.java: Fixed javadocs all over. Improved input error checking. * java/nio/Buffer.java (checkForUnderflow, checkForOverflow, checkIndex, checkIfReadOnly, checkArraySize): New helper methods for error checking. * java/nio/ByteBufferHelper.java (checkRemainingForRead, checkRemainingForWrite, checkAvailableForRead, checkAvailableForWrite): Removed no longer needed methods. From-SVN: r84366
Diffstat (limited to 'libjava/java')
-rw-r--r--libjava/java/nio/Buffer.java113
-rw-r--r--libjava/java/nio/ByteBuffer.java49
-rw-r--r--libjava/java/nio/ByteBufferHelper.java50
-rw-r--r--libjava/java/nio/ByteBufferImpl.java24
-rw-r--r--libjava/java/nio/CharBuffer.java52
-rw-r--r--libjava/java/nio/CharBufferImpl.java29
-rw-r--r--libjava/java/nio/CharViewBufferImpl.java16
-rw-r--r--libjava/java/nio/DirectByteBufferImpl.java24
-rw-r--r--libjava/java/nio/DoubleBuffer.java42
-rw-r--r--libjava/java/nio/DoubleBufferImpl.java26
-rw-r--r--libjava/java/nio/DoubleViewBufferImpl.java14
-rw-r--r--libjava/java/nio/FloatBuffer.java42
-rw-r--r--libjava/java/nio/FloatBufferImpl.java26
-rw-r--r--libjava/java/nio/FloatViewBufferImpl.java14
-rw-r--r--libjava/java/nio/IntBuffer.java42
-rw-r--r--libjava/java/nio/IntBufferImpl.java28
-rw-r--r--libjava/java/nio/IntViewBufferImpl.java14
-rw-r--r--libjava/java/nio/LongBuffer.java42
-rw-r--r--libjava/java/nio/LongBufferImpl.java28
-rw-r--r--libjava/java/nio/LongViewBufferImpl.java14
-rw-r--r--libjava/java/nio/MappedByteBufferImpl.java24
-rw-r--r--libjava/java/nio/ShortBuffer.java42
-rw-r--r--libjava/java/nio/ShortBufferImpl.java28
-rw-r--r--libjava/java/nio/ShortViewBufferImpl.java14
24 files changed, 519 insertions, 278 deletions
diff --git a/libjava/java/nio/Buffer.java b/libjava/java/nio/Buffer.java
index c7f01b6..e717385 100644
--- a/libjava/java/nio/Buffer.java
+++ b/libjava/java/nio/Buffer.java
@@ -233,7 +233,7 @@ public abstract class Buffer
* Rewinds this buffer. The position is set to zero and the mark
* is discarded.
*
- * @this buffer
+ * @return this buffer
*/
public final Buffer rewind()
{
@@ -241,4 +241,115 @@ public abstract class Buffer
mark = -1;
return this;
}
+
+ /**
+ * Checks for underflow. This method is used internally to check
+ * whether a buffer has enough elements left to satisfy a read
+ * request.
+ *
+ * @exception BufferUnderflowException If there are no remaining
+ * elements in this buffer.
+ */
+ final void checkForUnderflow()
+ {
+ if (!hasRemaining())
+ throw new BufferUnderflowException();
+ }
+
+ /**
+ * Checks for underflow. This method is used internally to check
+ * whether a buffer has enough elements left to satisfy a read
+ * request for a given number of elements.
+ *
+ * @param length The length of a sequence of elements.
+ *
+ * @exception BufferUnderflowException If there are not enough
+ * remaining elements in this buffer.
+ */
+ final void checkForUnderflow(int length)
+ {
+ if (remaining() < length)
+ throw new BufferUnderflowException();
+ }
+
+ /**
+ * Checks for overflow. This method is used internally to check
+ * whether a buffer has enough space left to satisfy a write
+ * request.
+ *
+ * @exception BufferOverflowException If there is no remaining
+ * space in this buffer.
+ */
+ final void checkForOverflow()
+ {
+ if (!hasRemaining())
+ throw new BufferOverflowException();
+ }
+
+ /**
+ * Checks for overflow. This method is used internally to check
+ * whether a buffer has enough space left to satisfy a write
+ * request for a given number of elements.
+ *
+ * @param length The length of a sequence of elements.
+ *
+ * @exception BufferUnderflowException If there is not enough
+ * remaining space in this buffer.
+ */
+ final void checkForOverflow(int length)
+ {
+ if (remaining() < length)
+ throw new BufferOverflowException();
+ }
+
+ /**
+ * Checks if index is negative or not smaller than the buffer's
+ * limit. This method is used internally to check whether
+ * an indexed request can be fulfilled.
+ *
+ * @param index The requested position in the buffer.
+ *
+ * @exception IndexOutOfBoundsException If index is negative or not smaller
+ * than the buffer's limit.
+ */
+ final void checkIndex(int index)
+ {
+ if (index < 0
+ || index >= limit ())
+ throw new IndexOutOfBoundsException ();
+ }
+
+ /**
+ * Checks if buffer is read-only. This method is used internally to
+ * check if elements can be put into a buffer.
+ *
+ * @exception ReadOnlyBufferException If this buffer is read-only.
+ */
+ final void checkIfReadOnly()
+ {
+ if (isReadOnly())
+ throw new ReadOnlyBufferException ();
+ }
+
+ /**
+ * Checks whether an array is large enough to hold the given number of
+ * elements at the given offset. This method is used internally to
+ * check if an array is big enough.
+ *
+ * @param arraylength The length of the array.
+ * @param offset The offset within the array of the first byte to be read;
+ * must be non-negative and no larger than arraylength.
+ * @param length The number of bytes to be read from the given array;
+ * must be non-negative and no larger than arraylength - offset.
+ *
+ * @exception IndexOutOfBoundsException If the preconditions on the offset
+ * and length parameters do not hold
+ */
+ final static void checkArraySize(int arraylength, int offset, int length)
+ {
+ if ((offset < 0) ||
+ (length < 0) ||
+ (arraylength < length + offset))
+ throw new IndexOutOfBoundsException ();
+ }
}
diff --git a/libjava/java/nio/ByteBuffer.java b/libjava/java/nio/ByteBuffer.java
index 8b43da5..34e3db9 100644
--- a/libjava/java/nio/ByteBuffer.java
+++ b/libjava/java/nio/ByteBuffer.java
@@ -100,8 +100,9 @@ public abstract class ByteBuffer extends Buffer
}
/**
- * This method transfers <code>bytes<code> from this buffer into the given
- * destination array.
+ * This method transfers <code>byte</code>s from this buffer into the given
+ * destination array. Before the transfer, it checks if there are fewer than
+ * length <code>byte</code>s remaining in this buffer.
*
* @param dst The destination array
* @param offset The offset within the array of the first <code>byte</code>
@@ -110,16 +111,14 @@ public abstract class ByteBuffer extends Buffer
* must be non-negative and no larger than dst.length - offset.
*
* @exception BufferUnderflowException If there are fewer than length
- * <code>bytes</code> remaining in this buffer.
+ * <code>byte</code>s remaining in this buffer.
* @exception IndexOutOfBoundsException If the preconditions on the offset
* and length parameters do not hold.
*/
public ByteBuffer get (byte[] dst, int offset, int length)
{
- if (offset < 0 || length < 0 || offset + length > dst.length)
- throw new IndexOutOfBoundsException ();
- if (length > remaining())
- throw new BufferUnderflowException();
+ checkArraySize(dst.length, offset, length);
+ checkForUnderflow(length);
for (int i = offset; i < offset + length; i++)
{
@@ -130,13 +129,13 @@ public abstract class ByteBuffer extends Buffer
}
/**
- * This method transfers <code>bytes<code> from this buffer into the given
+ * This method transfers <code>byte</code>s from this buffer into the given
* destination array.
*
* @param dst The byte array to write into.
*
* @exception BufferUnderflowException If there are fewer than dst.length
- * <code>bytes</code> remaining in this buffer.
+ * <code>byte</code>s remaining in this buffer.
*/
public ByteBuffer get (byte[] dst)
{
@@ -145,12 +144,13 @@ public abstract class ByteBuffer extends Buffer
/**
* Writes the content of the the <code>ByteBUFFER</code> src
- * into the buffer.
+ * into the buffer. Before the transfer, it checks if there is fewer than
+ * <code>src.remaining()</code> space remaining in this buffer.
*
* @param src The source data.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>bytes<code> in the source buffer.
+ * buffer for the remaining <code>byte</code>s in the source buffer.
* @exception IllegalArgumentException If the source buffer is this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
@@ -159,8 +159,7 @@ public abstract class ByteBuffer extends Buffer
if (src == this)
throw new IllegalArgumentException ();
- if (src.remaining () > remaining ())
- throw new BufferOverflowException ();
+ checkForOverflow(src.remaining());
if (src.remaining () > 0)
{
@@ -174,7 +173,8 @@ public abstract class ByteBuffer extends Buffer
/**
* Writes the content of the the <code>byte array</code> src
- * into the buffer.
+ * into the buffer. Before the transfer, it checks if there is fewer than
+ * length space remaining in this buffer.
*
* @param src The array to copy into the buffer.
* @param offset The offset within the array of the first byte to be read;
@@ -183,18 +183,15 @@ public abstract class ByteBuffer extends Buffer
* must be non-negative and no larger than src.length - offset.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>bytes<code> in the source array.
+ * buffer for the remaining <code>byte</code>s in the source array.
* @exception IndexOutOfBoundsException If the preconditions on the offset
* and length parameters do not hold
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public ByteBuffer put (byte[] src, int offset, int length)
{
- if ((offset < 0) ||
- (offset > src.length) ||
- (length < 0) ||
- (length > src.length - offset))
- throw new IndexOutOfBoundsException ();
+ checkArraySize(src.length, offset, length);
+ checkForOverflow(length);
for (int i = offset; i < offset + length; i++)
put (src [i]);
@@ -209,7 +206,7 @@ public abstract class ByteBuffer extends Buffer
* @param src The array to copy into the buffer.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>bytes<code> in the source array.
+ * buffer for the remaining <code>byte</code>s in the source array.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public final ByteBuffer put (byte[] src)
@@ -239,8 +236,7 @@ public abstract class ByteBuffer extends Buffer
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return backing_buffer;
}
@@ -257,8 +253,7 @@ public abstract class ByteBuffer extends Buffer
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return array_offset;
}
@@ -338,7 +333,7 @@ public abstract class ByteBuffer extends Buffer
* and then increments the position.
*
* @exception BufferUnderflowException If there are no remaining
- * <code>bytes</code> in this buffer.
+ * <code>byte</code>s in this buffer.
*/
public abstract byte get ();
@@ -347,7 +342,7 @@ public abstract class ByteBuffer extends Buffer
* and then increments the position.
*
* @exception BufferOverflowException If there no remaining
- * <code>bytes</code> in this buffer.
+ * <code>byte</code>s in this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public abstract ByteBuffer put (byte b);
diff --git a/libjava/java/nio/ByteBufferHelper.java b/libjava/java/nio/ByteBufferHelper.java
index c3dcfbe..e5c522a 100644
--- a/libjava/java/nio/ByteBufferHelper.java
+++ b/libjava/java/nio/ByteBufferHelper.java
@@ -42,32 +42,6 @@ package java.nio;
*/
final class ByteBufferHelper
{
- private static void checkRemainingForRead (ByteBuffer buffer, int bytes)
- {
- if (buffer.remaining() < bytes)
- throw new BufferUnderflowException();
- }
-
- private static void checkRemainingForWrite (ByteBuffer buffer, int bytes)
- {
- if (buffer.remaining() < bytes)
- throw new BufferOverflowException();
- }
-
- private static void checkAvailableForRead (ByteBuffer buffer,
- int index, int bytes)
- {
- if (buffer.limit() < (index + bytes))
- throw new BufferUnderflowException();
- }
-
- private static void checkAvailableForWrite (ByteBuffer buffer,
- int index, int bytes)
- {
- if (buffer.limit() < (index + bytes))
- throw new BufferOverflowException();
- }
-
public static char getChar (ByteBuffer buffer, ByteOrder order)
{
return (char) getShort (buffer, order);
@@ -91,7 +65,7 @@ final class ByteBufferHelper
public static short getShort (ByteBuffer buffer, ByteOrder order)
{
- checkRemainingForRead (buffer, 2);
+ buffer.checkForUnderflow(2);
if (order == ByteOrder.LITTLE_ENDIAN)
{
@@ -105,7 +79,7 @@ final class ByteBufferHelper
public static void putShort (ByteBuffer buffer, short value, ByteOrder order)
{
- checkRemainingForWrite (buffer, 2);
+ buffer.checkForOverflow(2);
if (order == ByteOrder.LITTLE_ENDIAN)
{
@@ -122,8 +96,6 @@ final class ByteBufferHelper
public static short getShort (ByteBuffer buffer,
int index, ByteOrder order)
{
- checkAvailableForRead (buffer, index, 2);
-
if (order == ByteOrder.LITTLE_ENDIAN)
{
return (short) ((buffer.get (index) & 0xff)
@@ -137,8 +109,6 @@ final class ByteBufferHelper
public static void putShort (ByteBuffer buffer, int index,
short value, ByteOrder order)
{
- checkAvailableForWrite (buffer, index, 2);
-
if (order == ByteOrder.LITTLE_ENDIAN)
{
buffer.put (index, (byte) value);
@@ -153,7 +123,7 @@ final class ByteBufferHelper
public static int getInt (ByteBuffer buffer, ByteOrder order)
{
- checkRemainingForRead (buffer, 4);
+ buffer.checkForUnderflow(4);
if (order == ByteOrder.LITTLE_ENDIAN)
{
@@ -171,7 +141,7 @@ final class ByteBufferHelper
public static void putInt (ByteBuffer buffer, int value, ByteOrder order)
{
- checkRemainingForWrite (buffer, 4);
+ buffer.checkForOverflow(4);
if (order == ByteOrder.LITTLE_ENDIAN)
{
@@ -191,8 +161,6 @@ final class ByteBufferHelper
public static int getInt (ByteBuffer buffer, int index, ByteOrder order)
{
- checkAvailableForRead (buffer, index, 4);
-
if (order == ByteOrder.LITTLE_ENDIAN)
{
return ((buffer.get (index) & 0xff)
@@ -210,8 +178,6 @@ final class ByteBufferHelper
public static void putInt (ByteBuffer buffer, int index,
int value, ByteOrder order)
{
- checkAvailableForWrite (buffer, index, 4);
-
if (order == ByteOrder.LITTLE_ENDIAN)
{
buffer.put (index, (byte) value);
@@ -230,7 +196,7 @@ final class ByteBufferHelper
public static long getLong (ByteBuffer buffer, ByteOrder order)
{
- checkRemainingForRead (buffer, 8);
+ buffer.checkForUnderflow(8);
if (order == ByteOrder.LITTLE_ENDIAN)
{
@@ -256,7 +222,7 @@ final class ByteBufferHelper
public static void putLong (ByteBuffer buffer, long value, ByteOrder order)
{
- checkRemainingForWrite (buffer, 8);
+ buffer.checkForOverflow(8);
if (order == ByteOrder.LITTLE_ENDIAN)
{
@@ -284,8 +250,6 @@ final class ByteBufferHelper
public static long getLong (ByteBuffer buffer, int index, ByteOrder order)
{
- checkAvailableForRead (buffer, index, 8);
-
if (order == ByteOrder.LITTLE_ENDIAN)
{
return ((buffer.get (index) & 0xff)
@@ -311,8 +275,6 @@ final class ByteBufferHelper
public static void putLong (ByteBuffer buffer, int index,
long value, ByteOrder order)
{
- checkAvailableForWrite (buffer, index, 8);
-
if (order == ByteOrder.LITTLE_ENDIAN)
{
buffer.put (index, (byte) value);
diff --git a/libjava/java/nio/ByteBufferImpl.java b/libjava/java/nio/ByteBufferImpl.java
index f79ae63..7734dbf 100644
--- a/libjava/java/nio/ByteBufferImpl.java
+++ b/libjava/java/nio/ByteBufferImpl.java
@@ -129,10 +129,16 @@ final class ByteBufferImpl extends ByteBuffer
}
/**
- * Relative get method. Reads the next <code>byte</code> from the buffer.
+ * Reads the <code>byte</code> at this buffer's current position,
+ * and then increments the position.
+ *
+ * @exception BufferUnderflowException If there are no remaining
+ * <code>bytes</code> in this buffer.
*/
public byte get ()
{
+ checkForUnderflow();
+
byte result = backing_buffer [position () + array_offset];
position (position () + 1);
return result;
@@ -141,13 +147,15 @@ final class ByteBufferImpl extends ByteBuffer
/**
* Relative put method. Writes <code>value</code> to the next position
* in the buffer.
- *
+ *
+ * @exception BufferOverflowException If there is no remaining
+ * space in this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public ByteBuffer put (byte value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
+ checkForOverflow();
int pos = position();
backing_buffer [pos + array_offset] = value;
@@ -164,6 +172,8 @@ final class ByteBufferImpl extends ByteBuffer
*/
public byte get (int index)
{
+ checkIndex(index);
+
return backing_buffer [index + array_offset];
}
@@ -177,9 +187,9 @@ final class ByteBufferImpl extends ByteBuffer
*/
public ByteBuffer put (int index, byte value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+ checkIndex(index);
+
backing_buffer [index + array_offset] = value;
return this;
}
diff --git a/libjava/java/nio/CharBuffer.java b/libjava/java/nio/CharBuffer.java
index 5116c25..e33c565 100644
--- a/libjava/java/nio/CharBuffer.java
+++ b/libjava/java/nio/CharBuffer.java
@@ -137,8 +137,9 @@ public abstract class CharBuffer extends Buffer
}
/**
- * This method transfers <code>chars<code> from this buffer into the given
- * destination array.
+ * This method transfers <code>char</code>s from this buffer into the given
+ * destination array. Before the transfer, it checks if there are fewer than
+ * length <code>char</code>s remaining in this buffer.
*
* @param dst The destination array
* @param offset The offset within the array of the first <code>char</code>
@@ -147,12 +148,15 @@ public abstract class CharBuffer extends Buffer
* must be non-negative and no larger than dst.length - offset.
*
* @exception BufferUnderflowException If there are fewer than length
- * <code>chars</code> remaining in this buffer.
+ * <code>char</code>s remaining in this buffer.
* @exception IndexOutOfBoundsException If the preconditions on the offset
* and length parameters do not hold.
*/
public CharBuffer get (char[] dst, int offset, int length)
{
+ checkArraySize(dst.length, offset, length);
+ checkForUnderflow(length);
+
for (int i = offset; i < offset + length; i++)
{
dst [i] = get ();
@@ -162,13 +166,13 @@ public abstract class CharBuffer extends Buffer
}
/**
- * This method transfers <code>chars<code> from this buffer into the given
+ * This method transfers <code>char</code>s from this buffer into the given
* destination array.
*
* @param dst The byte array to write into.
*
* @exception BufferUnderflowException If there are fewer than dst.length
- * <code>chars</code> remaining in this buffer.
+ * <code>char</code>s remaining in this buffer.
*/
public CharBuffer get (char[] dst)
{
@@ -177,12 +181,13 @@ public abstract class CharBuffer extends Buffer
/**
* Writes the content of the the <code>CharBUFFER</code> src
- * into the buffer.
+ * into the buffer. Before the transfer, it checks if there is fewer than
+ * <code>src.remaining()</code> space remaining in this buffer.
*
* @param src The source data.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>chars<code> in the source buffer.
+ * buffer for the remaining <code>char</code>s in the source buffer.
* @exception IllegalArgumentException If the source buffer is this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
@@ -191,8 +196,7 @@ public abstract class CharBuffer extends Buffer
if (src == this)
throw new IllegalArgumentException ();
- if (src.remaining () > remaining ())
- throw new BufferOverflowException ();
+ checkForOverflow(src.remaining());
if (src.remaining () > 0)
{
@@ -206,7 +210,8 @@ public abstract class CharBuffer extends Buffer
/**
* Writes the content of the the <code>char array</code> src
- * into the buffer.
+ * into the buffer. Before the transfer, it checks if there is fewer than
+ * length space remaining in this buffer.
*
* @param src The array to copy into the buffer.
* @param offset The offset within the array of the first byte to be read;
@@ -215,22 +220,15 @@ public abstract class CharBuffer extends Buffer
* must be non-negative and no larger than src.length - offset.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>chars<code> in the source array.
+ * buffer for the remaining <code>char</code>s in the source array.
* @exception IndexOutOfBoundsException If the preconditions on the offset
* and length parameters do not hold
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public CharBuffer put (char[] src, int offset, int length)
{
- if (offset < 0
- || offset >= src.length
- || length < 0
- || length > (src.length - offset))
- throw new IndexOutOfBoundsException ();
-
- // Put nothing into this buffer when not enough space left.
- if (length > remaining ())
- throw new BufferOverflowException ();
+ checkArraySize(src.length, offset, length);
+ checkForOverflow(length);
for (int i = offset; i < offset + length; i++)
put (src [i]);
@@ -245,7 +243,7 @@ public abstract class CharBuffer extends Buffer
* @param src The array to copy into the buffer.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>chars<code> in the source array.
+ * buffer for the remaining <code>char</code>s in the source array.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public final CharBuffer put (char[] src)
@@ -275,9 +273,8 @@ public abstract class CharBuffer extends Buffer
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+
return backing_buffer;
}
@@ -293,8 +290,7 @@ public abstract class CharBuffer extends Buffer
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return array_offset;
}
@@ -362,7 +358,7 @@ public abstract class CharBuffer extends Buffer
* and then increments the position.
*
* @exception BufferUnderflowException If there are no remaining
- * <code>chars</code> in this buffer.
+ * <code>char</code>s in this buffer.
*/
public abstract char get ();
@@ -371,7 +367,7 @@ public abstract class CharBuffer extends Buffer
* and then increments the position.
*
* @exception BufferOverflowException If there no remaining
- * <code>chars</code> in this buffer.
+ * <code>char</code>s in this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public abstract CharBuffer put (char b);
diff --git a/libjava/java/nio/CharBufferImpl.java b/libjava/java/nio/CharBufferImpl.java
index 1a8dff1..2ca44d9 100644
--- a/libjava/java/nio/CharBufferImpl.java
+++ b/libjava/java/nio/CharBufferImpl.java
@@ -1,5 +1,5 @@
/* CharBufferImpl.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.
@@ -116,10 +116,16 @@ final class CharBufferImpl extends CharBuffer
}
/**
- * Relative get method. Reads the next <code>char</code> from the buffer.
+ * Reads the <code>char</code> at this buffer's current position,
+ * and then increments the position.
+ *
+ * @exception BufferUnderflowException If there are no remaining
+ * <code>char</code>s in this buffer.
*/
public char get ()
{
+ checkForUnderflow();
+
char result = backing_buffer [position ()];
position (position () + 1);
return result;
@@ -133,8 +139,7 @@ final class CharBufferImpl extends CharBuffer
*/
public CharBuffer put (char value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
backing_buffer [position ()] = value;
position (position () + 1);
@@ -145,20 +150,20 @@ final class CharBufferImpl extends CharBuffer
* Absolute get method. Reads the <code>char</code> at position
* <code>index</code>.
*
+ * @param index Position to read the <code>char</code> from.
+ *
* @exception IndexOutOfBoundsException If index is negative or not smaller
* than the buffer's limit.
*/
public char get (int index)
{
- if (index < 0
- || index >= limit ())
- throw new IndexOutOfBoundsException ();
+ checkIndex(index);
return backing_buffer [index];
}
/**
- * Absolute put method. Writes <code>value</value> to position
+ * Absolute put method. Writes <code>value</code> to position
* <code>index</code> in the buffer.
*
* @exception IndexOutOfBoundsException If index is negative or not smaller
@@ -167,12 +172,8 @@ final class CharBufferImpl extends CharBuffer
*/
public CharBuffer put (int index, char value)
{
- if (index < 0
- || index >= limit ())
- throw new IndexOutOfBoundsException ();
-
- if (readOnly)
- throw new ReadOnlyBufferException ();
+ checkIndex(index);
+ checkIfReadOnly();
backing_buffer [index] = value;
return this;
diff --git a/libjava/java/nio/CharViewBufferImpl.java b/libjava/java/nio/CharViewBufferImpl.java
index ee99cfb..3c02108 100644
--- a/libjava/java/nio/CharViewBufferImpl.java
+++ b/libjava/java/nio/CharViewBufferImpl.java
@@ -66,6 +66,13 @@ class CharViewBufferImpl extends CharBuffer
this.endian = endian;
}
+ /**
+ * Reads the <code>char</code> at this buffer's current position,
+ * and then increments the position.
+ *
+ * @exception BufferUnderflowException If there are no remaining
+ * <code>char</code>s in this buffer.
+ */
public char get ()
{
int p = position();
@@ -74,6 +81,15 @@ class CharViewBufferImpl extends CharBuffer
return result;
}
+ /**
+ * Absolute get method. Reads the <code>char</code> at position
+ * <code>index</code>.
+ *
+ * @param index Position to read the <code>char</code> from.
+ *
+ * @exception IndexOutOfBoundsException If index is negative or not smaller
+ * than the buffer's limit.
+ */
public char get (int index)
{
return ByteBufferHelper.getChar(bb, (index << 1) + offset, endian);
diff --git a/libjava/java/nio/DirectByteBufferImpl.java b/libjava/java/nio/DirectByteBufferImpl.java
index be0fc52..aad5dca 100644
--- a/libjava/java/nio/DirectByteBufferImpl.java
+++ b/libjava/java/nio/DirectByteBufferImpl.java
@@ -86,9 +86,9 @@ final class DirectByteBufferImpl extends ByteBuffer
public byte get ()
{
+ checkForUnderflow();
+
int pos = position();
- if (pos >= limit())
- throw new BufferUnderflowException();
byte result = getImpl (address, pos);
position (pos + 1);
return result;
@@ -96,8 +96,8 @@ final class DirectByteBufferImpl extends ByteBuffer
public byte get (int index)
{
- if (index >= limit())
- throw new BufferUnderflowException();
+ checkIndex(index);
+
return getImpl (address, index);
}
@@ -106,10 +106,8 @@ final class DirectByteBufferImpl extends ByteBuffer
public ByteBuffer get (byte[] dst, int offset, int length)
{
- if (offset < 0 || length < 0 || offset + length > dst.length)
- throw new IndexOutOfBoundsException ();
- if (length > remaining())
- throw new BufferUnderflowException();
+ checkArraySize(dst.length, offset, length);
+ checkForUnderflow(length);
int index = position();
getImpl(address, index, dst, offset, length);
@@ -120,9 +118,10 @@ final class DirectByteBufferImpl extends ByteBuffer
public ByteBuffer put (byte value)
{
+ checkIfReadOnly();
+ checkForOverflow();
+
int pos = position();
- if (pos >= limit())
- throw new BufferUnderflowException();
putImpl (address, pos, value);
position (pos + 1);
return this;
@@ -130,8 +129,9 @@ final class DirectByteBufferImpl extends ByteBuffer
public ByteBuffer put (int index, byte value)
{
- if (index >= limit())
- throw new BufferUnderflowException();
+ checkIfReadOnly();
+ checkIndex(index);
+
putImpl (address, index, value);
return this;
}
diff --git a/libjava/java/nio/DoubleBuffer.java b/libjava/java/nio/DoubleBuffer.java
index 1ad8bae..820016b 100644
--- a/libjava/java/nio/DoubleBuffer.java
+++ b/libjava/java/nio/DoubleBuffer.java
@@ -83,8 +83,9 @@ public abstract class DoubleBuffer extends Buffer
}
/**
- * This method transfers <code>doubles<code> from this buffer into the given
- * destination array.
+ * This method transfers <code>double</code>s from this buffer into the given
+ * destination array. Before the transfer, it checks if there are fewer than
+ * length <code>double</code>s remaining in this buffer.
*
* @param dst The destination array
* @param offset The offset within the array of the first <code>double</code>
@@ -93,12 +94,15 @@ public abstract class DoubleBuffer extends Buffer
* must be non-negative and no larger than dst.length - offset.
*
* @exception BufferUnderflowException If there are fewer than length
- * <code>doubles</code> remaining in this buffer.
+ * <code>double</code>s remaining in this buffer.
* @exception IndexOutOfBoundsException If the preconditions on the offset
* and length parameters do not hold.
*/
public DoubleBuffer get (double[] dst, int offset, int length)
{
+ checkArraySize(dst.length, offset, length);
+ checkForUnderflow(length);
+
for (int i = offset; i < offset + length; i++)
{
dst [i] = get ();
@@ -108,13 +112,13 @@ public abstract class DoubleBuffer extends Buffer
}
/**
- * This method transfers <code>doubles<code> from this buffer into the given
+ * This method transfers <code>double</code>s from this buffer into the given
* destination array.
*
* @param dst The byte array to write into.
*
* @exception BufferUnderflowException If there are fewer than dst.length
- * <code>doubles</code> remaining in this buffer.
+ * <code>double</code>s remaining in this buffer.
*/
public DoubleBuffer get (double[] dst)
{
@@ -123,12 +127,13 @@ public abstract class DoubleBuffer extends Buffer
/**
* Writes the content of the the <code>DoubleBUFFER</code> src
- * into the buffer.
+ * into the buffer. Before the transfer, it checks if there is fewer than
+ * <code>src.remaining()</code> space remaining in this buffer.
*
* @param src The source data.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>doubles<code> in the source buffer.
+ * buffer for the remaining <code>double</code>s in the source buffer.
* @exception IllegalArgumentException If the source buffer is this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
@@ -137,8 +142,7 @@ public abstract class DoubleBuffer extends Buffer
if (src == this)
throw new IllegalArgumentException ();
- if (src.remaining () > remaining ())
- throw new BufferOverflowException ();
+ checkForOverflow(src.remaining ());
if (src.remaining () > 0)
{
@@ -152,7 +156,8 @@ public abstract class DoubleBuffer extends Buffer
/**
* Writes the content of the the <code>double array</code> src
- * into the buffer.
+ * into the buffer. Before the transfer, it checks if there is fewer than
+ * length space remaining in this buffer.
*
* @param src The array to copy into the buffer.
* @param offset The offset within the array of the first byte to be read;
@@ -161,13 +166,16 @@ public abstract class DoubleBuffer extends Buffer
* must be non-negative and no larger than src.length - offset.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>doubles<code> in the source array.
+ * buffer for the remaining <code>double</code>s in the source array.
* @exception IndexOutOfBoundsException If the preconditions on the offset
* and length parameters do not hold
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public DoubleBuffer put (double[] src, int offset, int length)
{
+ checkArraySize(src.length, offset, length);
+ checkForOverflow(length);
+
for (int i = offset; i < offset + length; i++)
put (src [i]);
@@ -181,7 +189,7 @@ public abstract class DoubleBuffer extends Buffer
* @param src The array to copy into the buffer.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>doubles<code> in the source array.
+ * buffer for the remaining <code>double</code>s in the source array.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public final DoubleBuffer put (double[] src)
@@ -211,8 +219,7 @@ public abstract class DoubleBuffer extends Buffer
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return backing_buffer;
}
@@ -229,8 +236,7 @@ public abstract class DoubleBuffer extends Buffer
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return array_offset;
}
@@ -298,7 +304,7 @@ public abstract class DoubleBuffer extends Buffer
* and then increments the position.
*
* @exception BufferUnderflowException If there are no remaining
- * <code>doubles</code> in this buffer.
+ * <code>double</code>s in this buffer.
*/
public abstract double get ();
@@ -307,7 +313,7 @@ public abstract class DoubleBuffer extends Buffer
* and then increments the position.
*
* @exception BufferOverflowException If there no remaining
- * <code>doubles</code> in this buffer.
+ * <code>double</code>s in this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public abstract DoubleBuffer put (double b);
diff --git a/libjava/java/nio/DoubleBufferImpl.java b/libjava/java/nio/DoubleBufferImpl.java
index 81fde6d..504ee8d 100644
--- a/libjava/java/nio/DoubleBufferImpl.java
+++ b/libjava/java/nio/DoubleBufferImpl.java
@@ -1,5 +1,5 @@
/* DoubleBufferImpl.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.
@@ -98,10 +98,16 @@ final class DoubleBufferImpl extends DoubleBuffer
}
/**
- * Relative get method. Reads the next <code>double</code> from the buffer.
+ * Reads the <code>double</code> at this buffer's current position,
+ * and then increments the position.
+ *
+ * @exception BufferUnderflowException If there are no remaining
+ * <code>double</code>s in this buffer.
*/
public double get ()
{
+ checkForUnderflow();
+
double result = backing_buffer [position ()];
position (position () + 1);
return result;
@@ -110,13 +116,15 @@ final class DoubleBufferImpl extends DoubleBuffer
/**
* Relative put method. Writes <code>value</code> to the next position
* in the buffer.
- *
+ *
+ * @exception BufferOverflowException If there no remaining
+ * space in this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public DoubleBuffer put (double value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
+ checkForOverflow();
backing_buffer [position ()] = value;
position (position () + 1);
@@ -132,6 +140,8 @@ final class DoubleBufferImpl extends DoubleBuffer
*/
public double get (int index)
{
+ checkIndex(index);
+
return backing_buffer [index];
}
@@ -145,9 +155,9 @@ final class DoubleBufferImpl extends DoubleBuffer
*/
public DoubleBuffer put (int index, double value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+ checkIndex(index);
+
backing_buffer [index] = value;
return this;
}
diff --git a/libjava/java/nio/DoubleViewBufferImpl.java b/libjava/java/nio/DoubleViewBufferImpl.java
index 7b04e4c..d23b14a 100644
--- a/libjava/java/nio/DoubleViewBufferImpl.java
+++ b/libjava/java/nio/DoubleViewBufferImpl.java
@@ -66,6 +66,13 @@ final class DoubleViewBufferImpl extends DoubleBuffer
this.endian = endian;
}
+ /**
+ * Reads the <code>double</code> at this buffer's current position,
+ * and then increments the position.
+ *
+ * @exception BufferUnderflowException If there are no remaining
+ * <code>double</code>s in this buffer.
+ */
public double get ()
{
int p = position();
@@ -74,6 +81,13 @@ final class DoubleViewBufferImpl extends DoubleBuffer
return result;
}
+ /**
+ * Absolute get method. Reads the <code>double</code> at position
+ * <code>index</code>.
+ *
+ * @exception IndexOutOfBoundsException If index is negative or not smaller
+ * than the buffer's limit.
+ */
public double get (int index)
{
return ByteBufferHelper.getDouble(bb, (index << 3) + offset, endian);
diff --git a/libjava/java/nio/FloatBuffer.java b/libjava/java/nio/FloatBuffer.java
index ab87b7f..2425f0c 100644
--- a/libjava/java/nio/FloatBuffer.java
+++ b/libjava/java/nio/FloatBuffer.java
@@ -83,8 +83,9 @@ public abstract class FloatBuffer extends Buffer
}
/**
- * This method transfers <code>floats<code> from this buffer into the given
- * destination array.
+ * This method transfers <code>float</code>s from this buffer into the given
+ * destination array. Before the transfer, it checks if there are fewer than
+ * length <code>float</code>s remaining in this buffer.
*
* @param dst The destination array
* @param offset The offset within the array of the first <code>float</code>
@@ -93,12 +94,15 @@ public abstract class FloatBuffer extends Buffer
* must be non-negative and no larger than dst.length - offset.
*
* @exception BufferUnderflowException If there are fewer than length
- * <code>floats</code> remaining in this buffer.
+ * <code>float</code>s remaining in this buffer.
* @exception IndexOutOfBoundsException If the preconditions on the offset
* and length parameters do not hold.
*/
public FloatBuffer get (float[] dst, int offset, int length)
{
+ checkArraySize(dst.length, offset, length);
+ checkForUnderflow(length);
+
for (int i = offset; i < offset + length; i++)
{
dst [i] = get ();
@@ -108,13 +112,13 @@ public abstract class FloatBuffer extends Buffer
}
/**
- * This method transfers <code>floats<code> from this buffer into the given
+ * This method transfers <code>float</code>s from this buffer into the given
* destination array.
*
* @param dst The byte array to write into.
*
* @exception BufferUnderflowException If there are fewer than dst.length
- * <code>floats</code> remaining in this buffer.
+ * <code>float</code>s remaining in this buffer.
*/
public FloatBuffer get (float[] dst)
{
@@ -123,12 +127,13 @@ public abstract class FloatBuffer extends Buffer
/**
* Writes the content of the the <code>FloatBUFFER</code> src
- * into the buffer.
+ * into the buffer. Before the transfer, it checks if there is fewer than
+ * <code>src.remaining()</code> space remaining in this buffer.
*
* @param src The source data.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>floats<code> in the source buffer.
+ * buffer for the remaining <code>float</code>s in the source buffer.
* @exception IllegalArgumentException If the source buffer is this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
@@ -137,8 +142,7 @@ public abstract class FloatBuffer extends Buffer
if (src == this)
throw new IllegalArgumentException ();
- if (src.remaining () > remaining ())
- throw new BufferOverflowException ();
+ checkForOverflow(src.remaining());
if (src.remaining () > 0)
{
@@ -152,7 +156,8 @@ public abstract class FloatBuffer extends Buffer
/**
* Writes the content of the the <code>float array</code> src
- * into the buffer.
+ * into the buffer. Before the transfer, it checks if there is fewer than
+ * length space remaining in this buffer.
*
* @param src The array to copy into the buffer.
* @param offset The offset within the array of the first byte to be read;
@@ -161,13 +166,16 @@ public abstract class FloatBuffer extends Buffer
* must be non-negative and no larger than src.length - offset.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>floats<code> in the source array.
+ * buffer for the remaining <code>float</code>s in the source array.
* @exception IndexOutOfBoundsException If the preconditions on the offset
* and length parameters do not hold
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public FloatBuffer put (float[] src, int offset, int length)
{
+ checkArraySize(src.length, offset, length);
+ checkForOverflow(length);
+
for (int i = offset; i < offset + length; i++)
put (src [i]);
@@ -181,7 +189,7 @@ public abstract class FloatBuffer extends Buffer
* @param src The array to copy into the buffer.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>floats<code> in the source array.
+ * buffer for the remaining <code>float</code>s in the source array.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public final FloatBuffer put (float[] src)
@@ -211,8 +219,7 @@ public abstract class FloatBuffer extends Buffer
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return backing_buffer;
}
@@ -229,8 +236,7 @@ public abstract class FloatBuffer extends Buffer
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return array_offset;
}
@@ -298,7 +304,7 @@ public abstract class FloatBuffer extends Buffer
* and then increments the position.
*
* @exception BufferUnderflowException If there are no remaining
- * <code>floats</code> in this buffer.
+ * <code>float</code>s in this buffer.
*/
public abstract float get ();
@@ -307,7 +313,7 @@ public abstract class FloatBuffer extends Buffer
* and then increments the position.
*
* @exception BufferOverflowException If there no remaining
- * <code>floats</code> in this buffer.
+ * <code>float</code>s in this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public abstract FloatBuffer put (float b);
diff --git a/libjava/java/nio/FloatBufferImpl.java b/libjava/java/nio/FloatBufferImpl.java
index 4747984..a9eb7c1 100644
--- a/libjava/java/nio/FloatBufferImpl.java
+++ b/libjava/java/nio/FloatBufferImpl.java
@@ -1,5 +1,5 @@
/* FloatBufferImpl.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.
@@ -98,10 +98,16 @@ final class FloatBufferImpl extends FloatBuffer
}
/**
- * Relative get method. Reads the next <code>float</code> from the buffer.
+ * Reads the <code>float</code> at this buffer's current position,
+ * and then increments the position.
+ *
+ * @exception BufferUnderflowException If there are no remaining
+ * <code>floats</code> in this buffer.
*/
public float get ()
{
+ checkForUnderflow();
+
float result = backing_buffer [position ()];
position (position () + 1);
return result;
@@ -111,13 +117,15 @@ final class FloatBufferImpl extends FloatBuffer
* Relative put method. Writes <code>value</code> to the next position
* in the buffer.
*
+ * @exception BufferOverflowException If there no remaining
+ * space in this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public FloatBuffer put (float value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+ checkForOverflow();
+
backing_buffer [position ()] = value;
position (position () + 1);
return this;
@@ -132,6 +140,8 @@ final class FloatBufferImpl extends FloatBuffer
*/
public float get (int index)
{
+ checkIndex(index);
+
return backing_buffer [index];
}
@@ -145,9 +155,9 @@ final class FloatBufferImpl extends FloatBuffer
*/
public FloatBuffer put (int index, float value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+ checkIndex(index);
+
backing_buffer [index] = value;
return this;
}
diff --git a/libjava/java/nio/FloatViewBufferImpl.java b/libjava/java/nio/FloatViewBufferImpl.java
index 08c5909..40b7339 100644
--- a/libjava/java/nio/FloatViewBufferImpl.java
+++ b/libjava/java/nio/FloatViewBufferImpl.java
@@ -66,6 +66,13 @@ final class FloatViewBufferImpl extends FloatBuffer
this.endian = endian;
}
+ /**
+ * Reads the <code>float</code> at this buffer's current position,
+ * and then increments the position.
+ *
+ * @exception BufferUnderflowException If there are no remaining
+ * <code>floats</code> in this buffer.
+ */
public float get ()
{
int p = position();
@@ -74,6 +81,13 @@ final class FloatViewBufferImpl extends FloatBuffer
return result;
}
+ /**
+ * Absolute get method. Reads the <code>float</code> at position
+ * <code>index</code>.
+ *
+ * @exception IndexOutOfBoundsException If index is negative or not smaller
+ * than the buffer's limit.
+ */
public float get (int index)
{
return ByteBufferHelper.getFloat(bb, (index << 2) + offset, endian);
diff --git a/libjava/java/nio/IntBuffer.java b/libjava/java/nio/IntBuffer.java
index 52d822a..8251324 100644
--- a/libjava/java/nio/IntBuffer.java
+++ b/libjava/java/nio/IntBuffer.java
@@ -83,8 +83,9 @@ public abstract class IntBuffer extends Buffer
}
/**
- * This method transfers <code>ints<code> from this buffer into the given
- * destination array.
+ * This method transfers <code>int</code>s from this buffer into the given
+ * destination array. Before the transfer, it checks if there are fewer than
+ * length <code>int</code>s remaining in this buffer.
*
* @param dst The destination array
* @param offset The offset within the array of the first <code>int</code>
@@ -93,12 +94,15 @@ public abstract class IntBuffer extends Buffer
* must be non-negative and no larger than dst.length - offset.
*
* @exception BufferUnderflowException If there are fewer than length
- * <code>ints</code> remaining in this buffer.
+ * <code>int</code>s remaining in this buffer.
* @exception IndexOutOfBoundsException If the preconditions on the offset
* and length parameters do not hold.
*/
public IntBuffer get (int[] dst, int offset, int length)
{
+ checkArraySize(dst.length, offset, length);
+ checkForUnderflow(length);
+
for (int i = offset; i < offset + length; i++)
{
dst [i] = get ();
@@ -108,13 +112,13 @@ public abstract class IntBuffer extends Buffer
}
/**
- * This method transfers <code>ints<code> from this buffer into the given
+ * This method transfers <code>int</code>s from this buffer into the given
* destination array.
*
* @param dst The byte array to write into.
*
* @exception BufferUnderflowException If there are fewer than dst.length
- * <code>ints</code> remaining in this buffer.
+ * <code>int</code>s remaining in this buffer.
*/
public IntBuffer get (int[] dst)
{
@@ -123,12 +127,13 @@ public abstract class IntBuffer extends Buffer
/**
* Writes the content of the the <code>IntBUFFER</code> src
- * into the buffer.
+ * into the buffer. Before the transfer, it checks if there is fewer than
+ * <code>src.remaining()</code> space remaining in this buffer.
*
* @param src The source data.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>ints<code> in the source buffer.
+ * buffer for the remaining <code>int</code>s in the source buffer.
* @exception IllegalArgumentException If the source buffer is this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
@@ -137,8 +142,7 @@ public abstract class IntBuffer extends Buffer
if (src == this)
throw new IllegalArgumentException ();
- if (src.remaining () > remaining ())
- throw new BufferOverflowException ();
+ checkForOverflow(src.remaining ());
if (src.remaining () > 0)
{
@@ -152,7 +156,8 @@ public abstract class IntBuffer extends Buffer
/**
* Writes the content of the the <code>int array</code> src
- * into the buffer.
+ * into the buffer. Before the transfer, it checks if there is fewer than
+ * length space remaining in this buffer.
*
* @param src The array to copy into the buffer.
* @param offset The offset within the array of the first byte to be read;
@@ -161,13 +166,16 @@ public abstract class IntBuffer extends Buffer
* must be non-negative and no larger than src.length - offset.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>ints<code> in the source array.
+ * buffer for the remaining <code>int</code>s in the source array.
* @exception IndexOutOfBoundsException If the preconditions on the offset
* and length parameters do not hold
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public IntBuffer put (int[] src, int offset, int length)
{
+ checkArraySize(src.length, offset, length);
+ checkForOverflow(length);
+
for (int i = offset; i < offset + length; i++)
put (src [i]);
@@ -181,7 +189,7 @@ public abstract class IntBuffer extends Buffer
* @param src The array to copy into the buffer.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>ints<code> in the source array.
+ * buffer for the remaining <code>int</code>s in the source array.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public final IntBuffer put (int[] src)
@@ -211,8 +219,7 @@ public abstract class IntBuffer extends Buffer
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return backing_buffer;
}
@@ -229,8 +236,7 @@ public abstract class IntBuffer extends Buffer
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return array_offset;
}
@@ -298,7 +304,7 @@ public abstract class IntBuffer extends Buffer
* and then increments the position.
*
* @exception BufferUnderflowException If there are no remaining
- * <code>ints</code> in this buffer.
+ * <code>int</code>s in this buffer.
*/
public abstract int get ();
@@ -307,7 +313,7 @@ public abstract class IntBuffer extends Buffer
* and then increments the position.
*
* @exception BufferOverflowException If there no remaining
- * <code>ints</code> in this buffer.
+ * <code>int</code>s in this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public abstract IntBuffer put (int b);
diff --git a/libjava/java/nio/IntBufferImpl.java b/libjava/java/nio/IntBufferImpl.java
index a491c11..f68dd92 100644
--- a/libjava/java/nio/IntBufferImpl.java
+++ b/libjava/java/nio/IntBufferImpl.java
@@ -1,5 +1,5 @@
/* IntBufferImpl.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.
@@ -98,10 +98,16 @@ final class IntBufferImpl extends IntBuffer
}
/**
- * Relative get method. Reads the next <code>int</code> from the buffer.
+ * Reads the <code>int</code> at this buffer's current position,
+ * and then increments the position.
+ *
+ * @exception BufferUnderflowException If there are no remaining
+ * <code>ints</code> in this buffer.
*/
public int get ()
{
+ checkForUnderflow();
+
int result = backing_buffer [position ()];
position (position () + 1);
return result;
@@ -110,14 +116,16 @@ final class IntBufferImpl extends IntBuffer
/**
* Relative put method. Writes <code>value</code> to the next position
* in the buffer.
- *
+ *
+ * @exception BufferOverflowException If there no remaining
+ * space in this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public IntBuffer put (int value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+ checkForOverflow();
+
backing_buffer [position ()] = value;
position (position () + 1);
return this;
@@ -132,6 +140,8 @@ final class IntBufferImpl extends IntBuffer
*/
public int get (int index)
{
+ checkIndex(index);
+
return backing_buffer [index];
}
@@ -145,9 +155,9 @@ final class IntBufferImpl extends IntBuffer
*/
public IntBuffer put (int index, int value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+ checkIndex(index);
+
backing_buffer [index] = value;
return this;
}
diff --git a/libjava/java/nio/IntViewBufferImpl.java b/libjava/java/nio/IntViewBufferImpl.java
index 0749537..1f3f934 100644
--- a/libjava/java/nio/IntViewBufferImpl.java
+++ b/libjava/java/nio/IntViewBufferImpl.java
@@ -66,6 +66,13 @@ final class IntViewBufferImpl extends IntBuffer
this.endian = endian;
}
+ /**
+ * Reads the <code>int</code> at this buffer's current position,
+ * and then increments the position.
+ *
+ * @exception BufferUnderflowException If there are no remaining
+ * <code>ints</code> in this buffer.
+ */
public int get ()
{
int p = position();
@@ -74,6 +81,13 @@ final class IntViewBufferImpl extends IntBuffer
return result;
}
+ /**
+ * Absolute get method. Reads the <code>int</code> at position
+ * <code>index</code>.
+ *
+ * @exception IndexOutOfBoundsException If index is negative or not smaller
+ * than the buffer's limit.
+ */
public int get (int index)
{
return ByteBufferHelper.getInt(bb, (index << 2) + offset, endian);
diff --git a/libjava/java/nio/LongBuffer.java b/libjava/java/nio/LongBuffer.java
index 1b420eb..f22ab14 100644
--- a/libjava/java/nio/LongBuffer.java
+++ b/libjava/java/nio/LongBuffer.java
@@ -83,8 +83,9 @@ public abstract class LongBuffer extends Buffer
}
/**
- * This method transfers <code>longs<code> from this buffer into the given
- * destination array.
+ * This method transfers <code>long</code>s from this buffer into the given
+ * destination array. Before the transfer, it checks if there are fewer than
+ * length <code>long</code>s remaining in this buffer.
*
* @param dst The destination array
* @param offset The offset within the array of the first <code>long</code>
@@ -93,12 +94,15 @@ public abstract class LongBuffer extends Buffer
* must be non-negative and no larger than dst.length - offset.
*
* @exception BufferUnderflowException If there are fewer than length
- * <code>longs</code> remaining in this buffer.
+ * <code>long</code>s remaining in this buffer.
* @exception IndexOutOfBoundsException If the preconditions on the offset
* and length parameters do not hold.
*/
public LongBuffer get (long[] dst, int offset, int length)
{
+ checkArraySize(dst.length, offset, length);
+ checkForUnderflow(length);
+
for (int i = offset; i < offset + length; i++)
{
dst [i] = get ();
@@ -108,13 +112,13 @@ public abstract class LongBuffer extends Buffer
}
/**
- * This method transfers <code>longs<code> from this buffer into the given
+ * This method transfers <code>long</code>s from this buffer into the given
* destination array.
*
* @param dst The byte array to write into.
*
* @exception BufferUnderflowException If there are fewer than dst.length
- * <code>longs</code> remaining in this buffer.
+ * <code>long</code>s remaining in this buffer.
*/
public LongBuffer get (long[] dst)
{
@@ -123,12 +127,13 @@ public abstract class LongBuffer extends Buffer
/**
* Writes the content of the the <code>LongBUFFER</code> src
- * into the buffer.
+ * into the buffer. Before the transfer, it checks if there is fewer than
+ * <code>src.remaining()</code> space remaining in this buffer.
*
* @param src The source data.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>longs<code> in the source buffer.
+ * buffer for the remaining <code>long</code>s in the source buffer.
* @exception IllegalArgumentException If the source buffer is this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
@@ -137,8 +142,7 @@ public abstract class LongBuffer extends Buffer
if (src == this)
throw new IllegalArgumentException ();
- if (src.remaining () > remaining ())
- throw new BufferOverflowException ();
+ checkForOverflow(src.remaining ());
if (src.remaining () > 0)
{
@@ -152,7 +156,8 @@ public abstract class LongBuffer extends Buffer
/**
* Writes the content of the the <code>long array</code> src
- * into the buffer.
+ * into the buffer. Before the transfer, it checks if there is fewer than
+ * length space remaining in this buffer.
*
* @param src The array to copy into the buffer.
* @param offset The offset within the array of the first byte to be read;
@@ -161,13 +166,16 @@ public abstract class LongBuffer extends Buffer
* must be non-negative and no larger than src.length - offset.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>longs<code> in the source array.
+ * buffer for the remaining <code>long</code>s in the source array.
* @exception IndexOutOfBoundsException If the preconditions on the offset
* and length parameters do not hold
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public LongBuffer put (long[] src, int offset, int length)
{
+ checkArraySize(src.length, offset, length);
+ checkForOverflow(length);
+
for (int i = offset; i < offset + length; i++)
put (src [i]);
@@ -181,7 +189,7 @@ public abstract class LongBuffer extends Buffer
* @param src The array to copy into the buffer.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>longs<code> in the source array.
+ * buffer for the remaining <code>long</code>s in the source array.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public final LongBuffer put (long[] src)
@@ -211,8 +219,7 @@ public abstract class LongBuffer extends Buffer
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return backing_buffer;
}
@@ -229,8 +236,7 @@ public abstract class LongBuffer extends Buffer
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return array_offset;
}
@@ -298,7 +304,7 @@ public abstract class LongBuffer extends Buffer
* and then increments the position.
*
* @exception BufferUnderflowException If there are no remaining
- * <code>longs</code> in this buffer.
+ * <code>long</code>s in this buffer.
*/
public abstract long get ();
@@ -307,7 +313,7 @@ public abstract class LongBuffer extends Buffer
* and then increments the position.
*
* @exception BufferOverflowException If there no remaining
- * <code>longs</code> in this buffer.
+ * <code>long</code>s in this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public abstract LongBuffer put (long b);
diff --git a/libjava/java/nio/LongBufferImpl.java b/libjava/java/nio/LongBufferImpl.java
index 88a9d8c..df720ee 100644
--- a/libjava/java/nio/LongBufferImpl.java
+++ b/libjava/java/nio/LongBufferImpl.java
@@ -1,5 +1,5 @@
/* LongBufferImpl.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.
@@ -98,10 +98,16 @@ final class LongBufferImpl extends LongBuffer
}
/**
- * Relative get method. Reads the next <code>long</code> from the buffer.
+ * Reads the <code>long</code> at this buffer's current position,
+ * and then increments the position.
+ *
+ * @exception BufferUnderflowException If there are no remaining
+ * <code>longs</code> in this buffer.
*/
public long get ()
{
+ checkForUnderflow();
+
long result = backing_buffer [position ()];
position (position () + 1);
return result;
@@ -110,14 +116,16 @@ final class LongBufferImpl extends LongBuffer
/**
* Relative put method. Writes <code>value</code> to the next position
* in the buffer.
- *
+ *
+ * @exception BufferOverflowException If there is insufficient space in this
+ * buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public LongBuffer put (long value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+ checkForOverflow();
+
backing_buffer [position ()] = value;
position (position () + 1);
return this;
@@ -132,6 +140,8 @@ final class LongBufferImpl extends LongBuffer
*/
public long get (int index)
{
+ checkIndex(index);
+
return backing_buffer [index];
}
@@ -145,9 +155,9 @@ final class LongBufferImpl extends LongBuffer
*/
public LongBuffer put (int index, long value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+ checkIndex(index);
+
backing_buffer [index] = value;
return this;
}
diff --git a/libjava/java/nio/LongViewBufferImpl.java b/libjava/java/nio/LongViewBufferImpl.java
index d1dd060..8762578 100644
--- a/libjava/java/nio/LongViewBufferImpl.java
+++ b/libjava/java/nio/LongViewBufferImpl.java
@@ -66,6 +66,13 @@ final class LongViewBufferImpl extends LongBuffer
this.endian = endian;
}
+ /**
+ * Reads the <code>long</code> at this buffer's current position,
+ * and then increments the position.
+ *
+ * @exception BufferUnderflowException If there are no remaining
+ * <code>longs</code> in this buffer.
+ */
public long get ()
{
int p = position();
@@ -74,6 +81,13 @@ final class LongViewBufferImpl extends LongBuffer
return result;
}
+ /**
+ * Absolute get method. Reads the <code>long</code> at position
+ * <code>index</code>.
+ *
+ * @exception IndexOutOfBoundsException If index is negative or not smaller
+ * than the buffer's limit.
+ */
public long get (int index)
{
return ByteBufferHelper.getLong(bb, (index << 3) + offset, endian);
diff --git a/libjava/java/nio/MappedByteBufferImpl.java b/libjava/java/nio/MappedByteBufferImpl.java
index 5932c99..5ed579b 100644
--- a/libjava/java/nio/MappedByteBufferImpl.java
+++ b/libjava/java/nio/MappedByteBufferImpl.java
@@ -68,9 +68,9 @@ final class MappedByteBufferImpl extends MappedByteBuffer
public byte get ()
{
+ checkForUnderflow();
+
int pos = position();
- if (pos >= limit())
- throw new BufferUnderflowException();
byte result = DirectByteBufferImpl.getImpl(address, pos);
position (pos + 1);
return result;
@@ -78,9 +78,10 @@ final class MappedByteBufferImpl extends MappedByteBuffer
public ByteBuffer put (byte value)
{
+ checkIfReadOnly();
+ checkForOverflow();
+
int pos = position();
- if (pos >= limit())
- throw new BufferUnderflowException();
DirectByteBufferImpl.putImpl(address, pos, value);
position(pos + 1);
return this;
@@ -88,17 +89,15 @@ final class MappedByteBufferImpl extends MappedByteBuffer
public byte get (int index)
{
- if (index >= limit())
- throw new BufferUnderflowException();
+ checkIndex(index);
+
return DirectByteBufferImpl.getImpl(address, index);
}
public ByteBuffer get (byte[] dst, int offset, int length)
{
- if (offset < 0 || length < 0 || offset + length > dst.length)
- throw new IndexOutOfBoundsException ();
- if (length > remaining())
- throw new BufferUnderflowException();
+ checkArraySize(dst.length, offset, length);
+ checkForUnderflow(length);
int index = position();
DirectByteBufferImpl.getImpl(address, index, dst, offset, length);
@@ -109,8 +108,9 @@ final class MappedByteBufferImpl extends MappedByteBuffer
public ByteBuffer put (int index, byte value)
{
- if (index >= limit())
- throw new BufferUnderflowException();
+ checkIfReadOnly();
+ checkIndex(index);
+
DirectByteBufferImpl.putImpl(address, index, value);
return this;
}
diff --git a/libjava/java/nio/ShortBuffer.java b/libjava/java/nio/ShortBuffer.java
index 9f54276..03ddb73 100644
--- a/libjava/java/nio/ShortBuffer.java
+++ b/libjava/java/nio/ShortBuffer.java
@@ -83,8 +83,9 @@ public abstract class ShortBuffer extends Buffer
}
/**
- * This method transfers <code>shorts<code> from this buffer into the given
- * destination array.
+ * This method transfers <code>short</code>s from this buffer into the given
+ * destination array. Before the transfer, it checks if there are fewer than
+ * length <code>short</code>s remaining in this buffer.
*
* @param dst The destination array
* @param offset The offset within the array of the first <code>short</code>
@@ -93,12 +94,15 @@ public abstract class ShortBuffer extends Buffer
* must be non-negative and no larger than dst.length - offset.
*
* @exception BufferUnderflowException If there are fewer than length
- * <code>shorts</code> remaining in this buffer.
+ * <code>short</code>s remaining in this buffer.
* @exception IndexOutOfBoundsException If the preconditions on the offset
* and length parameters do not hold.
*/
public ShortBuffer get (short[] dst, int offset, int length)
{
+ checkArraySize(dst.length, offset, length);
+ checkForUnderflow(length);
+
for (int i = offset; i < offset + length; i++)
{
dst [i] = get ();
@@ -108,13 +112,13 @@ public abstract class ShortBuffer extends Buffer
}
/**
- * This method transfers <code>shorts<code> from this buffer into the given
+ * This method transfers <code>short</code>s from this buffer into the given
* destination array.
*
* @param dst The byte array to write into.
*
* @exception BufferUnderflowException If there are fewer than dst.length
- * <code>shorts</code> remaining in this buffer.
+ * <code>short</code>s remaining in this buffer.
*/
public ShortBuffer get (short[] dst)
{
@@ -123,12 +127,13 @@ public abstract class ShortBuffer extends Buffer
/**
* Writes the content of the the <code>ShortBUFFER</code> src
- * into the buffer.
+ * into the buffer. Before the transfer, it checks if there is fewer than
+ * <code>src.remaining()</code> space remaining in this buffer.
*
* @param src The source data.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>shorts<code> in the source buffer.
+ * buffer for the remaining <code>short</code>s in the source buffer.
* @exception IllegalArgumentException If the source buffer is this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
@@ -137,8 +142,7 @@ public abstract class ShortBuffer extends Buffer
if (src == this)
throw new IllegalArgumentException ();
- if (src.remaining () > remaining ())
- throw new BufferOverflowException ();
+ checkForOverflow(src.remaining ());
if (src.remaining () > 0)
{
@@ -152,7 +156,8 @@ public abstract class ShortBuffer extends Buffer
/**
* Writes the content of the the <code>short array</code> src
- * into the buffer.
+ * into the buffer. Before the transfer, it checks if there is fewer than
+ * length space remaining in this buffer.
*
* @param src The array to copy into the buffer.
* @param offset The offset within the array of the first byte to be read;
@@ -161,13 +166,16 @@ public abstract class ShortBuffer extends Buffer
* must be non-negative and no larger than src.length - offset.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>shorts<code> in the source array.
+ * buffer for the remaining <code>short</code>s in the source array.
* @exception IndexOutOfBoundsException If the preconditions on the offset
* and length parameters do not hold
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public ShortBuffer put (short[] src, int offset, int length)
{
+ checkArraySize(src.length, offset, length);
+ checkForOverflow(length);
+
for (int i = offset; i < offset + length; i++)
put (src [i]);
@@ -181,7 +189,7 @@ public abstract class ShortBuffer extends Buffer
* @param src The array to copy into the buffer.
*
* @exception BufferOverflowException If there is insufficient space in this
- * buffer for the remaining <code>shorts<code> in the source array.
+ * buffer for the remaining <code>short</code>s in the source array.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public final ShortBuffer put (short[] src)
@@ -211,8 +219,7 @@ public abstract class ShortBuffer extends Buffer
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return backing_buffer;
}
@@ -229,8 +236,7 @@ public abstract class ShortBuffer extends Buffer
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return array_offset;
}
@@ -298,7 +304,7 @@ public abstract class ShortBuffer extends Buffer
* and then increments the position.
*
* @exception BufferUnderflowException If there are no remaining
- * <code>shorts</code> in this buffer.
+ * <code>short</code>s in this buffer.
*/
public abstract short get ();
@@ -307,7 +313,7 @@ public abstract class ShortBuffer extends Buffer
* and then increments the position.
*
* @exception BufferOverflowException If there no remaining
- * <code>shorts</code> in this buffer.
+ * <code>short</code>s in this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public abstract ShortBuffer put (short b);
diff --git a/libjava/java/nio/ShortBufferImpl.java b/libjava/java/nio/ShortBufferImpl.java
index 6871f09..28f6efb 100644
--- a/libjava/java/nio/ShortBufferImpl.java
+++ b/libjava/java/nio/ShortBufferImpl.java
@@ -1,5 +1,5 @@
/* ShortBufferImpl.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.
@@ -98,10 +98,16 @@ final class ShortBufferImpl extends ShortBuffer
}
/**
- * Relative get method. Reads the next <code>short</code> from the buffer.
+ * Reads the <code>short</code> at this buffer's current position,
+ * and then increments the position.
+ *
+ * @exception BufferUnderflowException If there are no remaining
+ * <code>short</code>s in this buffer.
*/
public short get ()
{
+ checkForUnderflow();
+
short result = backing_buffer [position ()];
position (position () + 1);
return result;
@@ -110,14 +116,16 @@ final class ShortBufferImpl extends ShortBuffer
/**
* Relative put method. Writes <code>value</code> to the next position
* in the buffer.
- *
+ *
+ * @exception BufferOverflowException If there no remaining
+ * space in this buffer.
* @exception ReadOnlyBufferException If this buffer is read-only.
*/
public ShortBuffer put (short value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+ checkForOverflow();
+
backing_buffer [position ()] = value;
position (position () + 1);
return this;
@@ -132,6 +140,8 @@ final class ShortBufferImpl extends ShortBuffer
*/
public short get (int index)
{
+ checkIndex(index);
+
return backing_buffer [index];
}
@@ -145,9 +155,9 @@ final class ShortBufferImpl extends ShortBuffer
*/
public ShortBuffer put (int index, short value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+ checkIndex(index);
+
backing_buffer [index] = value;
return this;
}
diff --git a/libjava/java/nio/ShortViewBufferImpl.java b/libjava/java/nio/ShortViewBufferImpl.java
index 26aabad..a9d086d2 100644
--- a/libjava/java/nio/ShortViewBufferImpl.java
+++ b/libjava/java/nio/ShortViewBufferImpl.java
@@ -66,6 +66,13 @@ final class ShortViewBufferImpl extends ShortBuffer
this.endian = endian;
}
+ /**
+ * Reads the <code>short</code> at this buffer's current position,
+ * and then increments the position.
+ *
+ * @exception BufferUnderflowException If there are no remaining
+ * <code>short</code>s in this buffer.
+ */
public short get ()
{
int p = position();
@@ -74,6 +81,13 @@ final class ShortViewBufferImpl extends ShortBuffer
return result;
}
+ /**
+ * Absolute get method. Reads the <code>short</code> at position
+ * <code>index</code>.
+ *
+ * @exception IndexOutOfBoundsException If index is negative or not smaller
+ * than the buffer's limit.
+ */
public short get (int index)
{
return ByteBufferHelper.getShort(bb, (index << 1) + offset, endian);