From 23c41c08339da4bdf677ade01e17d940b7ce6201 Mon Sep 17 00:00:00 2001 From: Dalibor Topic Date: Fri, 9 Jul 2004 13:40:29 +0000 Subject: Buffer.java, [...]: Fixed javadocs all over. 2004-07-09 Dalibor Topic * 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 --- libjava/java/nio/ByteBuffer.java | 49 ++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 27 deletions(-) (limited to 'libjava/java/nio/ByteBuffer.java') diff --git a/libjava/java/nio/ByteBuffer.java b/libjava/java/nio/ByteBuffer.java index 8b43da57910..34e3db9b7c7 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 bytes from this buffer into the given - * destination array. + * This method transfers bytes from this buffer into the given + * destination array. Before the transfer, it checks if there are fewer than + * length bytes remaining in this buffer. * * @param dst The destination array * @param offset The offset within the array of the first byte @@ -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 - * bytes remaining in this buffer. + * bytes 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 bytes from this buffer into the given + * This method transfers bytes 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 - * bytes remaining in this buffer. + * bytes 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 ByteBUFFER src - * into the buffer. + * into the buffer. Before the transfer, it checks if there is fewer than + * src.remaining() space remaining in this buffer. * * @param src The source data. * * @exception BufferOverflowException If there is insufficient space in this - * buffer for the remaining bytes in the source buffer. + * buffer for the remaining bytes 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 byte array 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 bytes in the source array. + * buffer for the remaining bytes 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 bytes in the source array. + * buffer for the remaining bytes 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 - * bytes in this buffer. + * bytes 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 - * bytes in this buffer. + * bytes in this buffer. * @exception ReadOnlyBufferException If this buffer is read-only. */ public abstract ByteBuffer put (byte b); -- cgit v1.2.3