+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.
+
2004-07-09 Michael Koch <konqueror@gmx.de>
* gnu/regexp/CharIndexedInputStream.java:
* Rewinds this buffer. The position is set to zero and the mark
* is discarded.
*
- * @this buffer
+ * @return this buffer
*/
public final Buffer rewind()
{
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 ();
+ }
}
}
/**
- * 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>
* 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++)
{
}
/**
- * 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)
{
/**
* 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.
*/
if (src == this)
throw new IllegalArgumentException ();
- if (src.remaining () > remaining ())
- throw new BufferOverflowException ();
+ checkForOverflow(src.remaining());
if (src.remaining () > 0)
{
/**
* 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;
* 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]);
* @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)
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return backing_buffer;
}
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return array_offset;
}
* 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 ();
* 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);
*/
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);
public static short getShort (ByteBuffer buffer, ByteOrder order)
{
- checkRemainingForRead (buffer, 2);
+ buffer.checkForUnderflow(2);
if (order == ByteOrder.LITTLE_ENDIAN)
{
public static void putShort (ByteBuffer buffer, short value, ByteOrder order)
{
- checkRemainingForWrite (buffer, 2);
+ buffer.checkForOverflow(2);
if (order == ByteOrder.LITTLE_ENDIAN)
{
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)
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);
public static int getInt (ByteBuffer buffer, ByteOrder order)
{
- checkRemainingForRead (buffer, 4);
+ buffer.checkForUnderflow(4);
if (order == ByteOrder.LITTLE_ENDIAN)
{
public static void putInt (ByteBuffer buffer, int value, ByteOrder order)
{
- checkRemainingForWrite (buffer, 4);
+ buffer.checkForOverflow(4);
if (order == ByteOrder.LITTLE_ENDIAN)
{
public static int getInt (ByteBuffer buffer, int index, ByteOrder order)
{
- checkAvailableForRead (buffer, index, 4);
-
if (order == ByteOrder.LITTLE_ENDIAN)
{
return ((buffer.get (index) & 0xff)
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);
public static long getLong (ByteBuffer buffer, ByteOrder order)
{
- checkRemainingForRead (buffer, 8);
+ buffer.checkForUnderflow(8);
if (order == ByteOrder.LITTLE_ENDIAN)
{
public static void putLong (ByteBuffer buffer, long value, ByteOrder order)
{
- checkRemainingForWrite (buffer, 8);
+ buffer.checkForOverflow(8);
if (order == ByteOrder.LITTLE_ENDIAN)
{
public static long getLong (ByteBuffer buffer, int index, ByteOrder order)
{
- checkAvailableForRead (buffer, index, 8);
-
if (order == ByteOrder.LITTLE_ENDIAN)
{
return ((buffer.get (index) & 0xff)
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);
}
/**
- * 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;
/**
* 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;
*/
public byte get (int index)
{
+ checkIndex(index);
+
return backing_buffer [index + array_offset];
}
*/
public ByteBuffer put (int index, byte value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+ checkIndex(index);
+
backing_buffer [index + array_offset] = value;
return this;
}
}
/**
- * 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>
* 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 ();
}
/**
- * 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)
{
/**
* 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.
*/
if (src == this)
throw new IllegalArgumentException ();
- if (src.remaining () > remaining ())
- throw new BufferOverflowException ();
+ checkForOverflow(src.remaining());
if (src.remaining () > 0)
{
/**
* 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;
* 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]);
* @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)
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+
return backing_buffer;
}
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return array_offset;
}
* 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 ();
* 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);
/* 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.
}
/**
- * 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;
*/
public CharBuffer put (char value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
backing_buffer [position ()] = value;
position (position () + 1);
* 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
*/
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;
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();
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);
public byte get ()
{
+ checkForUnderflow();
+
int pos = position();
- if (pos >= limit())
- throw new BufferUnderflowException();
byte result = getImpl (address, pos);
position (pos + 1);
return result;
public byte get (int index)
{
- if (index >= limit())
- throw new BufferUnderflowException();
+ checkIndex(index);
+
return 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();
getImpl(address, index, dst, offset, length);
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;
public ByteBuffer put (int index, byte value)
{
- if (index >= limit())
- throw new BufferUnderflowException();
+ checkIfReadOnly();
+ checkIndex(index);
+
putImpl (address, index, value);
return this;
}
}
/**
- * 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>
* 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 ();
}
/**
- * 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)
{
/**
* 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.
*/
if (src == this)
throw new IllegalArgumentException ();
- if (src.remaining () > remaining ())
- throw new BufferOverflowException ();
+ checkForOverflow(src.remaining ());
if (src.remaining () > 0)
{
/**
* 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;
* 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]);
* @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)
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return backing_buffer;
}
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return array_offset;
}
* 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 ();
* 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);
/* 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.
}
/**
- * 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;
/**
* 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);
*/
public double get (int index)
{
+ checkIndex(index);
+
return backing_buffer [index];
}
*/
public DoubleBuffer put (int index, double value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+ checkIndex(index);
+
backing_buffer [index] = value;
return this;
}
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();
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);
}
/**
- * 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>
* 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 ();
}
/**
- * 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)
{
/**
* 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.
*/
if (src == this)
throw new IllegalArgumentException ();
- if (src.remaining () > remaining ())
- throw new BufferOverflowException ();
+ checkForOverflow(src.remaining());
if (src.remaining () > 0)
{
/**
* 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;
* 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]);
* @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)
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return backing_buffer;
}
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return array_offset;
}
* 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 ();
* 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);
/* 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.
}
/**
- * 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;
* 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;
*/
public float get (int index)
{
+ checkIndex(index);
+
return backing_buffer [index];
}
*/
public FloatBuffer put (int index, float value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+ checkIndex(index);
+
backing_buffer [index] = value;
return this;
}
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();
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);
}
/**
- * 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>
* 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 ();
}
/**
- * 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)
{
/**
* 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.
*/
if (src == this)
throw new IllegalArgumentException ();
- if (src.remaining () > remaining ())
- throw new BufferOverflowException ();
+ checkForOverflow(src.remaining ());
if (src.remaining () > 0)
{
/**
* 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;
* 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]);
* @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)
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return backing_buffer;
}
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return array_offset;
}
* 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 ();
* 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);
/* 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.
}
/**
- * 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;
/**
* 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;
*/
public int get (int index)
{
+ checkIndex(index);
+
return backing_buffer [index];
}
*/
public IntBuffer put (int index, int value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+ checkIndex(index);
+
backing_buffer [index] = value;
return this;
}
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();
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);
}
/**
- * 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>
* 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 ();
}
/**
- * 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)
{
/**
* 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.
*/
if (src == this)
throw new IllegalArgumentException ();
- if (src.remaining () > remaining ())
- throw new BufferOverflowException ();
+ checkForOverflow(src.remaining ());
if (src.remaining () > 0)
{
/**
* 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;
* 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]);
* @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)
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return backing_buffer;
}
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return array_offset;
}
* 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 ();
* 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);
/* 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.
}
/**
- * 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;
/**
* 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;
*/
public long get (int index)
{
+ checkIndex(index);
+
return backing_buffer [index];
}
*/
public LongBuffer put (int index, long value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+ checkIndex(index);
+
backing_buffer [index] = value;
return this;
}
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();
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);
public byte get ()
{
+ checkForUnderflow();
+
int pos = position();
- if (pos >= limit())
- throw new BufferUnderflowException();
byte result = DirectByteBufferImpl.getImpl(address, pos);
position (pos + 1);
return result;
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;
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);
public ByteBuffer put (int index, byte value)
{
- if (index >= limit())
- throw new BufferUnderflowException();
+ checkIfReadOnly();
+ checkIndex(index);
+
DirectByteBufferImpl.putImpl(address, index, value);
return this;
}
}
/**
- * 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>
* 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 ();
}
/**
- * 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)
{
/**
* 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.
*/
if (src == this)
throw new IllegalArgumentException ();
- if (src.remaining () > remaining ())
- throw new BufferOverflowException ();
+ checkForOverflow(src.remaining ());
if (src.remaining () > 0)
{
/**
* 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;
* 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]);
* @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)
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return backing_buffer;
}
if (backing_buffer == null)
throw new UnsupportedOperationException ();
- if (isReadOnly ())
- throw new ReadOnlyBufferException ();
+ checkIfReadOnly();
return array_offset;
}
* 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 ();
* 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);
/* 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.
}
/**
- * 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;
/**
* 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;
*/
public short get (int index)
{
+ checkIndex(index);
+
return backing_buffer [index];
}
*/
public ShortBuffer put (int index, short value)
{
- if (readOnly)
- throw new ReadOnlyBufferException ();
-
+ checkIfReadOnly();
+ checkIndex(index);
+
backing_buffer [index] = value;
return this;
}
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();
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);