2003-02-11 Michael Koch <konqueror@gmx.de>
* java/nio/Buffer.java (cap, lim, pos, mark): Made private (Buffer): Added package private constructor. * java/nio/ByteBuffer.java (ByteBuffer): Implements Cloneable. (offset): New member variable. (readOnly): New member variable. (backing_buffer): New member variable. (allocateDirect): Throw exception and tell that direct buffers are not supported yet, documentation added. (allocate): Documentation added. (wrap): Documentation added. (ByteBuffer): New constructor. (hasArray): New method. (array): New method. (arrayOffset): New method. (get): Documentation added. (put): Documentation added. * java/nio/CharBuffer.java (CharBuffer): New constructor. (compareTo): Don't access member variables of Buffer directly. * java/nio/DoubleBuffer.java (allocateDirect): Throw exception and tell that direct buffers are not supported yet. * java/nio/FloatBuffer.java (allocateDirect): Throw exception and tell that direct buffers are not supported yet. * java/nio/IntBuffer.java (allocateDirect): Throw exception and tell that direct buffers are not supported yet. * java/nio/LongBuffer.java (allocateDirect): Throw exception and tell that direct buffers are not supported yet. * java/nio/MappedByteBuffer.java (MappedByteBuffer): New method. (force): New method. (isLoaded): New method. (load): New method. * java/nio/ShortBuffer.java (allocateDirect): Throw exception and tell that direct buffers are not supported yet. From-SVN: r62685
This commit is contained in:
parent
c0da264129
commit
d19e783c45
9 changed files with 201 additions and 16 deletions
|
@ -37,43 +37,178 @@ exception statement from your version. */
|
|||
|
||||
package java.nio;
|
||||
|
||||
public abstract class ByteBuffer extends Buffer
|
||||
/**
|
||||
* @since 1.4
|
||||
*/
|
||||
public abstract class ByteBuffer extends Buffer implements Comparable
|
||||
{
|
||||
int offset;
|
||||
boolean readOnly;
|
||||
byte[] backing_buffer;
|
||||
|
||||
/**
|
||||
* Allocates a new direct byte buffer.
|
||||
*/
|
||||
public static ByteBuffer allocateDirect (int capacity)
|
||||
{
|
||||
throw new Error ("direct buffers are not implemented");
|
||||
}
|
||||
|
||||
/**
|
||||
* Allocates a new byte buffer.
|
||||
*/
|
||||
public static ByteBuffer allocate (int capacity)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a byte array into a buffer.
|
||||
*
|
||||
* @exception IndexOutOfBoundsException If the preconditions on the offset
|
||||
* and length parameters do not hold
|
||||
*/
|
||||
final public static ByteBuffer wrap (byte[] array, int offset, int length)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wraps a byte array into a buffer.
|
||||
*/
|
||||
final public static ByteBuffer wrap (byte[] array)
|
||||
{
|
||||
return wrap (array, 0, array.length);
|
||||
}
|
||||
|
||||
final public ByteBuffer put (ByteBuffer src)
|
||||
|
||||
ByteBuffer (int capacity, int limit, int position, int mark)
|
||||
{
|
||||
super (capacity, limit, position, mark);
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of src into the buffer.
|
||||
*
|
||||
* @param src The source data.
|
||||
*
|
||||
* @exception BufferOverflowException If there is insufficient space in this
|
||||
* 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.
|
||||
*/
|
||||
public ByteBuffer put (ByteBuffer src)
|
||||
{
|
||||
if (src == this)
|
||||
throw new IllegalArgumentException ();
|
||||
|
||||
while (src.hasRemaining ())
|
||||
put (src.get ());
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
final public ByteBuffer put (byte[] src, int offset, int length)
|
||||
|
||||
/**
|
||||
* Writes the content of the the array src into the 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.
|
||||
* @param length The number of bytes to be read from the given array;
|
||||
* 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 buffer.
|
||||
* @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 ();
|
||||
|
||||
for (int i = offset; i < offset + length; i++)
|
||||
put (src [i]);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes the content of the the array src into the 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 buffer.
|
||||
* @exception ReadOnlyBufferException If this buffer is read only.
|
||||
*/
|
||||
public final ByteBuffer put (byte[] src)
|
||||
{
|
||||
return put (src, 0, src.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tells whether or not this buffer is backed by an accessible byte array.
|
||||
*/
|
||||
public final boolean hasArray ()
|
||||
{
|
||||
return (backing_buffer != null
|
||||
&& !readOnly);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the byte array that backs this buffer.
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is backed by an array
|
||||
* but is read-only.
|
||||
* @exception UnsupportedOperationException If this buffer is not backed
|
||||
* by an accessible array.
|
||||
*/
|
||||
public final byte[] array ()
|
||||
{
|
||||
if (backing_buffer == null)
|
||||
throw new UnsupportedOperationException ();
|
||||
|
||||
if (readOnly)
|
||||
throw new ReadOnlyBufferException ();
|
||||
|
||||
return backing_buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the offset within this buffer's backing array of the first element
|
||||
* of the buffer
|
||||
*
|
||||
* @exception ReadOnlyBufferException If this buffer is backed by an array
|
||||
* but is read-only.
|
||||
* @exception UnsupportedOperationException If this buffer is not backed
|
||||
* by an accessible array.
|
||||
*/
|
||||
public final int arrayOffset ()
|
||||
{
|
||||
if (backing_buffer == null)
|
||||
throw new UnsupportedOperationException ();
|
||||
|
||||
if (readOnly)
|
||||
throw new ReadOnlyBufferException ();
|
||||
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Relative get method.
|
||||
*/
|
||||
public abstract byte get ();
|
||||
|
||||
/**
|
||||
* Relative put method.
|
||||
*
|
||||
* @exception BufferOverflowException If this buffer's current position is
|
||||
* not smaller than its limit.
|
||||
* @exception ReadOnlyBufferException If this buffer is read-only.
|
||||
*/
|
||||
public abstract ByteBuffer put (byte b);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue