From 36d4669b735c0e6f665e9a83bdd0848e23fc6662 Mon Sep 17 00:00:00 2001 From: Michael Koch Date: Mon, 12 May 2003 20:45:20 +0000 Subject: [PATCH] ByteBufferImpl.java: Reformatted. 2003-05-12 Michael Koch * gnu/java/nio/ByteBufferImpl.java: Reformatted. (nio_get_*): Removed. (nio_put_*): Removed. (as*Buffer): Implemented. (compact): Implemented. (get): Documentation added. (put): Documentation added. (get*): Newly implemented. (put*): Newly implemented. * gnu/java/nio/CharBufferImpl.java: Reformatted. (CharBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * gnu/java/nio/DirectByteBufferImpl.java (allocateDirect): objects can be null not 0. * gnu/java/nio/DoubleBufferImpl.java: Reformatted. (DoubleBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * gnu/java/nio/FloatBufferImpl.java: Reformatted. (FloatBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * gnu/java/nio/IntBufferImpl.java: Reformatted. (IntBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * gnu/java/nio/LongBufferImpl.java: Reformatted. (LongBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * gnu/java/nio/ShortBufferImpl.java: Reformatted. (ShortBufferImpl): Revised. (slice): New implementation. (duplicate): New implementation. (compact): New implementation. (asReadOnlyBuffer): New implementation. (get): Documentation revised. (order): Return native byte order. * java/nio/CharBuffer.java: Reformatted, much documentation rewritten. (CharBuffer): Revised. (order): Removed. * java/nio/DoubleBuffer.java: Reformatted, much documentation rewritten. (DoubleBuffer): Revised. (allocateDirect): Removed. (order): Removed. * java/nio/FloatBuffer.java: Reformatted, much documentation rewritten. (FloatBuffer): Revised. (allocateDirect): Removed. (order): Removed. * java/nio/IntBuffer.java: Reformatted, much documentation rewritten. (IntBuffer): Revised. (allocateDirect): Removed. (order): Removed. * java/nio/LongBuffer.java: Reformatted, much documentation rewritten. (LongBuffer): Revised. (allocateDirect): Removed. (order): Removed. * java/nio/ShortBuffer.java: Reformatted, much documentation rewritten. (ShortBuffer): Revised. (allocateDirect): Removed. (order): Removed. * gnu/java/nio/natByteBufferImpl.cc: Removed. * gnu/java/nio/natCharBufferImpl.cc: Removed. * Makefile.am (ordinary_java_source_files): Added the following files: gnu/java/nio/CharViewBufferImpl.java, gnu/java/nio/DoubleViewBufferImpl.java, gnu/java/nio/FloatViewBufferImpl.java, gnu/java/nio/IntViewBufferImpl.java, gnu/java/nio/LongViewBufferImpl.java, gnu/java/nio/ShortViewBufferImpl.java (nat_source_files): Removed the following files: gnu/java/nio/natByteBufferImpl.cc, gnu/java/nio/natCharBufferImpl.cc * Makefile.in: Regenerated. From-SVN: r66733 --- libjava/ChangeLog | 99 +++++ libjava/Makefile.am | 8 +- libjava/Makefile.in | 22 +- libjava/gnu/java/nio/ByteBufferImpl.java | 343 ++++++++++-------- libjava/gnu/java/nio/CharBufferImpl.java | 93 +++-- .../gnu/java/nio/DirectByteBufferImpl.java | 2 +- libjava/gnu/java/nio/DoubleBufferImpl.java | 122 ++++--- libjava/gnu/java/nio/FloatBufferImpl.java | 106 +++--- libjava/gnu/java/nio/IntBufferImpl.java | 128 ++++--- libjava/gnu/java/nio/LongBufferImpl.java | 126 ++++--- libjava/gnu/java/nio/ShortBufferImpl.java | 124 ++++--- libjava/gnu/java/nio/natByteBufferImpl.cc | 82 ----- libjava/gnu/java/nio/natCharBufferImpl.cc | 22 -- libjava/java/nio/CharBuffer.java | 242 +++++++----- libjava/java/nio/DoubleBuffer.java | 299 +++++++++++---- libjava/java/nio/FloatBuffer.java | 304 ++++++++++++---- libjava/java/nio/IntBuffer.java | 306 ++++++++++++---- libjava/java/nio/LongBuffer.java | 303 ++++++++++++---- libjava/java/nio/ShortBuffer.java | 301 +++++++++++---- 19 files changed, 2056 insertions(+), 976 deletions(-) delete mode 100644 libjava/gnu/java/nio/natByteBufferImpl.cc delete mode 100644 libjava/gnu/java/nio/natCharBufferImpl.cc diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 584defb5b30..0aed87438e7 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,102 @@ +2003-05-12 Michael Koch + + * gnu/java/nio/ByteBufferImpl.java: Reformatted. + (nio_get_*): Removed. + (nio_put_*): Removed. + (as*Buffer): Implemented. + (compact): Implemented. + (get): Documentation added. + (put): Documentation added. + (get*): Newly implemented. + (put*): Newly implemented. + * gnu/java/nio/CharBufferImpl.java: Reformatted. + (CharBufferImpl): Revised. + (slice): New implementation. + (duplicate): New implementation. + (compact): New implementation. + (asReadOnlyBuffer): New implementation. + (get): Documentation revised. + (order): Return native byte order. + * gnu/java/nio/DirectByteBufferImpl.java + (allocateDirect): objects can be null not 0. + * gnu/java/nio/DoubleBufferImpl.java: Reformatted. + (DoubleBufferImpl): Revised. + (slice): New implementation. + (duplicate): New implementation. + (compact): New implementation. + (asReadOnlyBuffer): New implementation. + (get): Documentation revised. + (order): Return native byte order. + * gnu/java/nio/FloatBufferImpl.java: Reformatted. + (FloatBufferImpl): Revised. + (slice): New implementation. + (duplicate): New implementation. + (compact): New implementation. + (asReadOnlyBuffer): New implementation. + (get): Documentation revised. + (order): Return native byte order. + * gnu/java/nio/IntBufferImpl.java: Reformatted. + (IntBufferImpl): Revised. + (slice): New implementation. + (duplicate): New implementation. + (compact): New implementation. + (asReadOnlyBuffer): New implementation. + (get): Documentation revised. + (order): Return native byte order. + * gnu/java/nio/LongBufferImpl.java: Reformatted. + (LongBufferImpl): Revised. + (slice): New implementation. + (duplicate): New implementation. + (compact): New implementation. + (asReadOnlyBuffer): New implementation. + (get): Documentation revised. + (order): Return native byte order. + * gnu/java/nio/ShortBufferImpl.java: Reformatted. + (ShortBufferImpl): Revised. + (slice): New implementation. + (duplicate): New implementation. + (compact): New implementation. + (asReadOnlyBuffer): New implementation. + (get): Documentation revised. + (order): Return native byte order. + * java/nio/CharBuffer.java: Reformatted, much documentation rewritten. + (CharBuffer): Revised. + (order): Removed. + * java/nio/DoubleBuffer.java: Reformatted, much documentation rewritten. + (DoubleBuffer): Revised. + (allocateDirect): Removed. + (order): Removed. + * java/nio/FloatBuffer.java: Reformatted, much documentation rewritten. + (FloatBuffer): Revised. + (allocateDirect): Removed. + (order): Removed. + * java/nio/IntBuffer.java: Reformatted, much documentation rewritten. + (IntBuffer): Revised. + (allocateDirect): Removed. + (order): Removed. + * java/nio/LongBuffer.java: Reformatted, much documentation rewritten. + (LongBuffer): Revised. + (allocateDirect): Removed. + (order): Removed. + * java/nio/ShortBuffer.java: Reformatted, much documentation rewritten. + (ShortBuffer): Revised. + (allocateDirect): Removed. + (order): Removed. + * gnu/java/nio/natByteBufferImpl.cc: Removed. + * gnu/java/nio/natCharBufferImpl.cc: Removed. + * Makefile.am + (ordinary_java_source_files): Added the following files: + gnu/java/nio/CharViewBufferImpl.java, + gnu/java/nio/DoubleViewBufferImpl.java, + gnu/java/nio/FloatViewBufferImpl.java, + gnu/java/nio/IntViewBufferImpl.java, + gnu/java/nio/LongViewBufferImpl.java, + gnu/java/nio/ShortViewBufferImpl.java + (nat_source_files): Removed the following files: + gnu/java/nio/natByteBufferImpl.cc, + gnu/java/nio/natCharBufferImpl.cc + * Makefile.in: Regenerated. + 2003-05-12 Michael Koch * gnu/java/nio/CharViewBufferImpl.java, diff --git a/libjava/Makefile.am b/libjava/Makefile.am index 71858819c54..e745528242a 100644 --- a/libjava/Makefile.am +++ b/libjava/Makefile.am @@ -2098,12 +2098,17 @@ gnu/java/locale/LocaleInformation_zh_TW.java \ gnu/java/math/MPN.java \ gnu/java/nio/ByteBufferImpl.java \ gnu/java/nio/CharBufferImpl.java \ +gnu/java/nio/CharViewBufferImpl.java \ gnu/java/nio/DatagramChannelImpl.java \ gnu/java/nio/DoubleBufferImpl.java \ +gnu/java/nio/DoubleViewBufferImpl.java \ gnu/java/nio/FileChannelImpl.java \ gnu/java/nio/FloatBufferImpl.java \ +gnu/java/nio/FloatViewBufferImpl.java \ gnu/java/nio/IntBufferImpl.java \ +gnu/java/nio/IntViewBufferImpl.java \ gnu/java/nio/LongBufferImpl.java \ +gnu/java/nio/LongViewBufferImpl.java \ gnu/java/nio/MappedByteFileBuffer.java \ gnu/java/nio/PipeImpl.java \ gnu/java/nio/SelectionKeyImpl.java \ @@ -2111,6 +2116,7 @@ gnu/java/nio/SelectorImpl.java \ gnu/java/nio/SelectorProviderImpl.java \ gnu/java/nio/ServerSocketChannelImpl.java \ gnu/java/nio/ShortBufferImpl.java \ +gnu/java/nio/ShortViewBufferImpl.java \ gnu/java/nio/SocketChannelImpl.java \ gnu/java/nio/charset/ISO_8859_1.java \ gnu/java/nio/charset/Provider.java \ @@ -2555,8 +2561,6 @@ gnu/gcj/runtime/natSharedLibLoader.cc \ gnu/gcj/runtime/natStackTrace.cc \ gnu/gcj/runtime/natStringBuffer.cc \ gnu/gcj/runtime/natVMClassLoader.cc \ -gnu/java/nio/natByteBufferImpl.cc \ -gnu/java/nio/natCharBufferImpl.cc \ gnu/java/nio/natFileChannelImpl.cc \ gnu/java/nio/natMappedByteFileBuffer.cc \ gnu/java/nio/natSelectorImpl.cc \ diff --git a/libjava/Makefile.in b/libjava/Makefile.in index cbe0cc02d47..6aa88cc8cd4 100644 --- a/libjava/Makefile.in +++ b/libjava/Makefile.in @@ -1860,12 +1860,17 @@ gnu/java/locale/LocaleInformation_zh_TW.java \ gnu/java/math/MPN.java \ gnu/java/nio/ByteBufferImpl.java \ gnu/java/nio/CharBufferImpl.java \ +gnu/java/nio/CharViewBufferImpl.java \ gnu/java/nio/DatagramChannelImpl.java \ gnu/java/nio/DoubleBufferImpl.java \ +gnu/java/nio/DoubleViewBufferImpl.java \ gnu/java/nio/FileChannelImpl.java \ gnu/java/nio/FloatBufferImpl.java \ +gnu/java/nio/FloatViewBufferImpl.java \ gnu/java/nio/IntBufferImpl.java \ +gnu/java/nio/IntViewBufferImpl.java \ gnu/java/nio/LongBufferImpl.java \ +gnu/java/nio/LongViewBufferImpl.java \ gnu/java/nio/MappedByteFileBuffer.java \ gnu/java/nio/PipeImpl.java \ gnu/java/nio/SelectionKeyImpl.java \ @@ -1873,6 +1878,7 @@ gnu/java/nio/SelectorImpl.java \ gnu/java/nio/SelectorProviderImpl.java \ gnu/java/nio/ServerSocketChannelImpl.java \ gnu/java/nio/ShortBufferImpl.java \ +gnu/java/nio/ShortViewBufferImpl.java \ gnu/java/nio/SocketChannelImpl.java \ gnu/java/nio/charset/ISO_8859_1.java \ gnu/java/nio/charset/Provider.java \ @@ -2316,8 +2322,6 @@ gnu/gcj/runtime/natSharedLibLoader.cc \ gnu/gcj/runtime/natStackTrace.cc \ gnu/gcj/runtime/natStringBuffer.cc \ gnu/gcj/runtime/natVMClassLoader.cc \ -gnu/java/nio/natByteBufferImpl.cc \ -gnu/java/nio/natCharBufferImpl.cc \ gnu/java/nio/natFileChannelImpl.cc \ gnu/java/nio/natMappedByteFileBuffer.cc \ gnu/java/nio/natSelectorImpl.cc \ @@ -2492,8 +2496,7 @@ gnu/gcj/io/shs.lo gnu/gcj/protocol/core/natCoreInputStream.lo \ gnu/gcj/runtime/natFinalizerThread.lo gnu/gcj/runtime/natFirstThread.lo \ gnu/gcj/runtime/natNameFinder.lo gnu/gcj/runtime/natSharedLibLoader.lo \ gnu/gcj/runtime/natStackTrace.lo gnu/gcj/runtime/natStringBuffer.lo \ -gnu/gcj/runtime/natVMClassLoader.lo gnu/java/nio/natByteBufferImpl.lo \ -gnu/java/nio/natCharBufferImpl.lo gnu/java/nio/natFileChannelImpl.lo \ +gnu/gcj/runtime/natVMClassLoader.lo gnu/java/nio/natFileChannelImpl.lo \ gnu/java/nio/natMappedByteFileBuffer.lo gnu/java/nio/natSelectorImpl.lo \ gnu/java/nio/natSocketChannelImpl.lo java/io/natFile.lo \ java/io/natFileDescriptor.lo java/io/natObjectInputStream.lo \ @@ -2958,16 +2961,23 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ .deps/gnu/java/locale/LocaleInformation_zh_TW.P \ .deps/gnu/java/math/MPN.P .deps/gnu/java/nio/ByteBufferImpl.P \ .deps/gnu/java/nio/CharBufferImpl.P \ +.deps/gnu/java/nio/CharViewBufferImpl.P \ .deps/gnu/java/nio/DatagramChannelImpl.P \ .deps/gnu/java/nio/DoubleBufferImpl.P \ +.deps/gnu/java/nio/DoubleViewBufferImpl.P \ .deps/gnu/java/nio/FileChannelImpl.P \ -.deps/gnu/java/nio/FloatBufferImpl.P .deps/gnu/java/nio/IntBufferImpl.P \ +.deps/gnu/java/nio/FloatBufferImpl.P \ +.deps/gnu/java/nio/FloatViewBufferImpl.P \ +.deps/gnu/java/nio/IntBufferImpl.P \ +.deps/gnu/java/nio/IntViewBufferImpl.P \ .deps/gnu/java/nio/LongBufferImpl.P \ +.deps/gnu/java/nio/LongViewBufferImpl.P \ .deps/gnu/java/nio/MappedByteFileBuffer.P .deps/gnu/java/nio/PipeImpl.P \ .deps/gnu/java/nio/SelectionKeyImpl.P .deps/gnu/java/nio/SelectorImpl.P \ .deps/gnu/java/nio/SelectorProviderImpl.P \ .deps/gnu/java/nio/ServerSocketChannelImpl.P \ .deps/gnu/java/nio/ShortBufferImpl.P \ +.deps/gnu/java/nio/ShortViewBufferImpl.P \ .deps/gnu/java/nio/SocketChannelImpl.P \ .deps/gnu/java/nio/charset/ISO_8859_1.P \ .deps/gnu/java/nio/charset/Provider.P \ @@ -2978,8 +2988,6 @@ DEP_FILES = .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \ .deps/gnu/java/nio/charset/UTF_16Encoder.P \ .deps/gnu/java/nio/charset/UTF_16LE.P \ .deps/gnu/java/nio/charset/UTF_8.P \ -.deps/gnu/java/nio/natByteBufferImpl.P \ -.deps/gnu/java/nio/natCharBufferImpl.P \ .deps/gnu/java/nio/natFileChannelImpl.P \ .deps/gnu/java/nio/natMappedByteFileBuffer.P \ .deps/gnu/java/nio/natSelectorImpl.P \ diff --git a/libjava/gnu/java/nio/ByteBufferImpl.java b/libjava/gnu/java/nio/ByteBufferImpl.java index ede16aa2e25..7b7f72e5fb0 100644 --- a/libjava/gnu/java/nio/ByteBufferImpl.java +++ b/libjava/gnu/java/nio/ByteBufferImpl.java @@ -1,5 +1,5 @@ /* ByteBufferImpl.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,6 +35,7 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ + package gnu.java.nio; import java.nio.ByteBuffer; @@ -66,7 +67,7 @@ public final class ByteBufferImpl extends ByteBuffer this.backing_buffer = array; readOnly = false; } - + public ByteBufferImpl (ByteBufferImpl copy) { super (copy.capacity (), copy.limit (), copy.position (), 0); @@ -79,311 +80,369 @@ public final class ByteBufferImpl extends ByteBuffer position (position () + toAdd); } - private static native char nio_get_Char (ByteBufferImpl b, int index, int limit); - - private static native void nio_put_Char (ByteBufferImpl b, int index, int limit, char value); - public CharBuffer asCharBuffer () { - throw new Error ("Not implemented"); + return new CharViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly ()); } - private static native short nio_get_Short (ByteBufferImpl b, int index, int limit); - - private static native void nio_put_Short (ByteBufferImpl b, int index, int limit, short value); - public ShortBuffer asShortBuffer () { - throw new Error ("Not implemented"); + return new ShortViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly ()); } - private static native int nio_get_Int (ByteBufferImpl b, int index, int limit); - - private static native void nio_put_Int (ByteBufferImpl b, int index, int limit, int value); - public IntBuffer asIntBuffer () { - throw new Error ("Not implemented"); + return new IntViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly ()); } - private static native long nio_get_Long (ByteBufferImpl b, int index, int limit); - - private static native void nio_put_Long (ByteBufferImpl b, int index, int limit, long value); - public LongBuffer asLongBuffer () { - throw new Error ("Not implemented"); + return new LongViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly ()); } - private static native float nio_get_Float (ByteBufferImpl b, int index, int limit); - - private static native void nio_put_Float (ByteBufferImpl b, int index, int limit, float value); - public FloatBuffer asFloatBuffer () { - throw new Error ("Not implemented"); + return new FloatViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly ()); } - private static native double nio_get_Double (ByteBufferImpl b, int index, int limit); - - private static native void nio_put_Double (ByteBufferImpl b, int index, int limit, double value); - public DoubleBuffer asDoubleBuffer () { - throw new Error ("Not implemented"); + return new DoubleViewBufferImpl (this, position (), remaining(), remaining (), 0, -1, isReadOnly ()); } - public boolean isReadOnly() + public boolean isReadOnly () { return readOnly; } - public ByteBuffer slice() + public ByteBuffer slice () { - return new ByteBufferImpl(this); + return new ByteBufferImpl (this); } - - public ByteBuffer duplicate() + + public ByteBuffer duplicate () { - return new ByteBufferImpl(this); + return new ByteBufferImpl (this); } - - public ByteBuffer asReadOnlyBuffer() + + public ByteBuffer asReadOnlyBuffer () { - ByteBufferImpl a = new ByteBufferImpl(this); + ByteBufferImpl a = new ByteBufferImpl (this); a.readOnly = true; return a; } - - public ByteBuffer compact() + + public ByteBuffer compact () { + int copied = 0; + + while (remaining () > 0) + { + put (copied, get ()); + copied++; + } + + position (copied); return this; } - - public boolean isDirect() + + public boolean isDirect () { return false; } - - final public byte get() + + /** + * Relative get method. Reads the next byte from the buffer. + */ + final public byte get () { - byte e = backing_buffer[position()]; - position(position()+1); - return e; + byte result = backing_buffer [position ()]; + position (position () + 1); + return result; } - final public ByteBuffer put(byte b) + /** + * Relative put method. Writes value to the next position + * in the buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + final public ByteBuffer put (byte value) { if (readOnly) throw new ReadOnlyBufferException (); - - backing_buffer[position()] = b; - position(position()+1); + + backing_buffer [position ()] = value; + position (position () + 1); return this; } - final public byte get(int index) + /** + * Absolute get method. Reads the byte at position + * index. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + */ + final public byte get (int index) { - return backing_buffer[index]; + return backing_buffer [index]; } - final public ByteBuffer put(int index, byte b) + /** + * Absolute put method. Writes value to position + * index in the buffer. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + final public ByteBuffer put (int index, byte value) { if (readOnly) throw new ReadOnlyBufferException (); - - backing_buffer[index] = b; + + backing_buffer [index] = value; return this; } final public char getChar () { - char a = nio_get_Char (this, position (), limit ()); - inc_pos (2); - return a; + // FIXME: this handles big endian only + return (char) (((get () & 0xff) << 8) + (get () & 0xff)); } final public ByteBuffer putChar (char value) { - if (readOnly) - throw new ReadOnlyBufferException (); - - nio_put_Char (this, position (), limit (), value); - inc_pos (2); + // FIXME: this handles big endian only + put ((byte) ((((int) value) & 0xff00) >> 8)); + put ((byte) (((int) value) & 0x00ff)); return this; } final public char getChar (int index) { - char a = nio_get_Char (this, index, limit ()); - return a; + // FIXME: this handles big endian only + return (char) (((get (index) & 0xff) << 8) + (get (index + 1) & 0xff)); } final public ByteBuffer putChar (int index, char value) { - if (readOnly) - throw new ReadOnlyBufferException (); - - nio_put_Char (this, index, limit (), value); + // FIXME: this handles big endian only + put (index, (byte) ((((int) value) & 0xff00) >> 8)); + put (index + 1, (byte) (((int) value) & 0x00ff)); return this; } final public short getShort () { - short a = nio_get_Short (this, position (), limit ()); - inc_pos (2); - return a; + // FIXME: this handles big endian only + return (short) (((get () & 0xff) << 8) + (get () & 0xff)); } final public ByteBuffer putShort (short value) { - if (readOnly) - throw new ReadOnlyBufferException (); - - nio_put_Short (this, position (), limit (), value); - inc_pos (2); + // FIXME: this handles big endian only + put ((byte) ((((int) value) & 0xff00) >> 8)); + put ((byte) (((int) value) & 0x00ff)); return this; } final public short getShort (int index) { - short a = nio_get_Short (this, index, limit ()); - return a; + // FIXME: this handles big endian only + return (short) (((get (index) & 0xff) << 8) + (get (index + 1) & 0xff)); } final public ByteBuffer putShort (int index, short value) { - if (readOnly) - throw new ReadOnlyBufferException (); - - nio_put_Short (this, index, limit (), value); + // FIXME: this handles big endian only + put (index, (byte) ((((int) value) & 0xff00) >> 8)); + put (index + 1, (byte) (((int) value) & 0x00ff)); return this; } final public int getInt () { - int a = nio_get_Int (this, position (), limit ()); - inc_pos (4); - return a; + // FIXME: this handles big endian only + return (int) (((get () & 0xff) << 24) + + (get () & 0xff) << 16 + + (get () & 0xff) << 8 + + (get () & 0xff)); } final public ByteBuffer putInt (int value) { - if (readOnly) - throw new ReadOnlyBufferException (); - - nio_put_Int (this, position (), limit (), value); - inc_pos (4); + // FIXME: this handles big endian only + put ((byte) ((((int) value) & 0xff000000) >> 24)); + put ((byte) ((((int) value) & 0x00ff0000) >> 16)); + put ((byte) ((((int) value) & 0x0000ff00) >> 8)); + put ((byte) (((int) value) & 0x000000ff)); return this; } final public int getInt (int index) { - int a = nio_get_Int (this, index, limit ()); - return a; + // FIXME: this handles big endian only + return (int) (((get (index) & 0xff) << 24) + + (get (index + 1) & 0xff) << 16 + + (get (index + 2) & 0xff) << 8 + + (get (index + 3) & 0xff)); } final public ByteBuffer putInt (int index, int value) { - if (readOnly) - throw new ReadOnlyBufferException (); - - nio_put_Int(this, index, limit (), value); + // FIXME: this handles big endian only + put (index, (byte) ((((int) value) & 0xff000000) >> 24)); + put (index + 1, (byte) ((((int) value) & 0x00ff0000) >> 16)); + put (index + 2, (byte) ((((int) value) & 0x0000ff00) >> 8)); + put (index + 3, (byte) (((int) value) & 0x000000ff)); return this; } final public long getLong () { - long a = nio_get_Long (this, position (), limit ()); - inc_pos (8); - return a; + // FIXME: this handles big endian only + return (long) (((get () & 0xff) << 56) + + (get () & 0xff) << 48 + + (get () & 0xff) << 40 + + (get () & 0xff) << 32 + + (get () & 0xff) << 24 + + (get () & 0xff) << 16 + + (get () & 0xff) << 8 + + (get () & 0xff)); } final public ByteBuffer putLong (long value) { - if (readOnly) - throw new ReadOnlyBufferException (); - - nio_put_Long (this, position (), limit (), value); - inc_pos (8); + // FIXME: this handles big endian only + put ((byte) ((((int) value) & 0xff00000000000000) >> 56)); + put ((byte) ((((int) value) & 0x00ff000000000000) >> 48)); + put ((byte) ((((int) value) & 0x0000ff0000000000) >> 40)); + put ((byte) ((((int) value) & 0x000000ff00000000) >> 32)); + put ((byte) ((((int) value) & 0x00000000ff000000) >> 24)); + put ((byte) ((((int) value) & 0x0000000000ff0000) >> 16)); + put ((byte) ((((int) value) & 0x000000000000ff00) >> 8)); + put ((byte) (((int) value) & 0x00000000000000ff)); return this; } final public long getLong (int index) { - long a = nio_get_Long (this, index, limit ()); - return a; + // FIXME: this handles big endian only + return (long) (((get (index) & 0xff) << 56) + + (get (index + 1) & 0xff) << 48 + + (get (index + 2) & 0xff) << 40 + + (get (index + 3) & 0xff) << 32 + + (get (index + 4) & 0xff) << 24 + + (get (index + 5) & 0xff) << 16 + + (get (index + 6) & 0xff) << 8 + + (get (index + 7) & 0xff)); } final public ByteBuffer putLong (int index, long value) { - if (readOnly) - throw new ReadOnlyBufferException (); - - nio_put_Long (this, index, limit (), value); + // FIXME: this handles big endian only + put (index, (byte) ((((int) value) & 0xff00000000000000) >> 56)); + put (index + 1, (byte) ((((int) value) & 0x00ff000000000000) >> 48)); + put (index + 2, (byte) ((((int) value) & 0x0000ff0000000000) >> 40)); + put (index + 3, (byte) ((((int) value) & 0x000000ff00000000) >> 32)); + put (index + 4, (byte) ((((int) value) & 0x00000000ff000000) >> 24)); + put (index + 5, (byte) ((((int) value) & 0x0000000000ff0000) >> 16)); + put (index + 6, (byte) ((((int) value) & 0x000000000000ff00) >> 8)); + put (index + 7, (byte) (((int) value) & 0x00000000000000ff)); return this; } final public float getFloat () { - float a = nio_get_Float (this, position (), limit ()); - inc_pos (4); - return a; + // FIXME: this handles big endian only + return (float) (((get () & 0xff) << 24) + + (get () & 0xff) << 16 + + (get () & 0xff) << 8 + + (get () & 0xff)); } final public ByteBuffer putFloat (float value) { - if (readOnly) - throw new ReadOnlyBufferException (); - - nio_put_Float (this, position (), limit (), value); - inc_pos (4); + // FIXME: this handles big endian only + put ((byte) ((((int) value) & 0xff000000) >> 24)); + put ((byte) ((((int) value) & 0x00ff0000) >> 16)); + put ((byte) ((((int) value) & 0x0000ff00) >> 8)); + put ((byte) (((int) value) & 0x000000ff)); return this; } final public float getFloat (int index) { - float a = nio_get_Float (this, index, limit ()); - return a; + // FIXME: this handles big endian only + return (float) (((get (index) & 0xff) << 24) + + (get (index + 1) & 0xff) << 16 + + (get (index + 2) & 0xff) << 8 + + (get (index + 3) & 0xff)); } final public ByteBuffer putFloat (int index, float value) { - if (readOnly) - throw new ReadOnlyBufferException (); - - nio_put_Float (this, index, limit(), value); + // FIXME: this handles big endian only + put (index, (byte) ((((int) value) & 0xff000000) >> 24)); + put (index + 1, (byte) ((((int) value) & 0x00ff0000) >> 16)); + put (index + 2, (byte) ((((int) value) & 0x0000ff00) >> 8)); + put (index + 3, (byte) (((int) value) & 0x000000ff)); return this; } final public double getDouble () { - double a = nio_get_Double (this, position (), limit ()); - inc_pos (8); - return a; + // FIXME: this handles big endian only + return (double) (((get () & 0xff) << 56) + + (get () & 0xff) << 48 + + (get () & 0xff) << 40 + + (get () & 0xff) << 32 + + (get () & 0xff) << 24 + + (get () & 0xff) << 16 + + (get () & 0xff) << 8 + + (get () & 0xff)); } final public ByteBuffer putDouble (double value) { - if (readOnly) - throw new ReadOnlyBufferException (); - - nio_put_Double (this, position(), limit (), value); - inc_pos (8); + // FIXME: this handles big endian only + put ((byte) ((((int) value) & 0xff00000000000000) >> 56)); + put ((byte) ((((int) value) & 0x00ff000000000000) >> 48)); + put ((byte) ((((int) value) & 0x0000ff0000000000) >> 40)); + put ((byte) ((((int) value) & 0x000000ff00000000) >> 32)); + put ((byte) ((((int) value) & 0x00000000ff000000) >> 24)); + put ((byte) ((((int) value) & 0x0000000000ff0000) >> 16)); + put ((byte) ((((int) value) & 0x000000000000ff00) >> 8)); + put ((byte) (((int) value) & 0x00000000000000ff)); return this; } final public double getDouble (int index) { - return nio_get_Double (this, index, limit ()); + // FIXME: this handles big endian only + return (double) (((get (index) & 0xff) << 56) + + (get (index + 1) & 0xff) << 48 + + (get (index + 2) & 0xff) << 40 + + (get (index + 3) & 0xff) << 32 + + (get (index + 4) & 0xff) << 24 + + (get (index + 5) & 0xff) << 16 + + (get (index + 6) & 0xff) << 8 + + (get (index + 7) & 0xff)); } final public ByteBuffer putDouble (int index, double value) { - if (readOnly) - throw new ReadOnlyBufferException (); - - nio_put_Double (this, index, limit (), value); + // FIXME: this handles big endian only + put (index, (byte) ((((int) value) & 0xff00000000000000) >> 56)); + put (index + 1, (byte) ((((int) value) & 0x00ff000000000000) >> 48)); + put (index + 2, (byte) ((((int) value) & 0x0000ff0000000000) >> 40)); + put (index + 3, (byte) ((((int) value) & 0x000000ff00000000) >> 32)); + put (index + 4, (byte) ((((int) value) & 0x00000000ff000000) >> 24)); + put (index + 5, (byte) ((((int) value) & 0x0000000000ff0000) >> 16)); + put (index + 6, (byte) ((((int) value) & 0x000000000000ff00) >> 8)); + put (index + 7, (byte) (((int) value) & 0x00000000000000ff)); return this; } } diff --git a/libjava/gnu/java/nio/CharBufferImpl.java b/libjava/gnu/java/nio/CharBufferImpl.java index ca769742cca..fcf0e15e474 100644 --- a/libjava/gnu/java/nio/CharBufferImpl.java +++ b/libjava/gnu/java/nio/CharBufferImpl.java @@ -1,5 +1,5 @@ /* CharBufferImpl.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,6 +35,7 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ + package gnu.java.nio; import java.nio.ByteBuffer; @@ -49,18 +50,15 @@ public final class CharBufferImpl extends CharBuffer { private boolean readOnly; - public CharBufferImpl(int cap, int off, int lim) + CharBufferImpl (int capacity) { - super (cap, lim, off, 0); - this.backing_buffer = new char [cap]; - readOnly = false; + this (new char [capacity], 0, capacity, capacity, 0, -1, false); } - public CharBufferImpl(char[] array, int offset, int length) + CharBufferImpl (char[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly) { - super (array.length, length, offset, 0); - this.backing_buffer = array; - readOnly = false; + super (buffer, offset, capacity, limit, position, mark); + this.readOnly = readOnly; } public CharBufferImpl (CharBufferImpl copy) @@ -70,37 +68,41 @@ public final class CharBufferImpl extends CharBuffer readOnly = copy.isReadOnly (); } - private static native char[] nio_cast (byte[] copy); - - public boolean isReadOnly() + public boolean isReadOnly () { return readOnly; } - public CharBuffer slice() + public CharBuffer slice () { - return new CharBufferImpl (backing_buffer, arrayOffset () + position (), - remaining ()); + return new CharBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ()); } - public CharBuffer duplicate() + public CharBuffer duplicate () { - return new CharBufferImpl(this); + return new CharBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ()); } - public CharBuffer asReadOnlyBuffer() + public CharBuffer asReadOnlyBuffer () { - CharBufferImpl result = new CharBufferImpl (this); - result.readOnly = true; - return result; + return new CharBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true); } - public CharBuffer compact() + public CharBuffer compact () { + int copied = 0; + + while (remaining () > 0) + { + put (copied, get ()); + copied++; + } + + position (copied); return this; } - public boolean isDirect() + public boolean isDirect () { return false; } @@ -113,20 +115,17 @@ public final class CharBufferImpl extends CharBuffer || end > length ()) throw new IndexOutOfBoundsException (); - // No support for direct buffers yet. - // assert array () != null; - return new CharBufferImpl (array (), position () + start, - position () + end); + return new CharBufferImpl (backing_buffer, array_offset, capacity (), position () + end, position () + start, -1, isReadOnly ()); } /** - * Relative get method. Reads the next character from the buffer. + * Relative get method. Reads the next char from the buffer. */ - final public char get() + final public char get () { - char e = backing_buffer[position()]; - position(position()+1); - return e; + char result = backing_buffer [position ()]; + position (position () + 1); + return result; } /** @@ -135,29 +134,30 @@ public final class CharBufferImpl extends CharBuffer * * @exception ReadOnlyBufferException If this buffer is read-only. */ - final public CharBuffer put(char b) + final public CharBuffer put (char value) { if (readOnly) throw new ReadOnlyBufferException (); - - backing_buffer[position()] = b; - position(position()+1); + + backing_buffer [position ()] = value; + position (position () + 1); return this; } - + /** - * Absolute get method. Reads the character at position index. + * Absolute get method. Reads the char at position + * index. * * @exception IndexOutOfBoundsException If index is negative or not smaller * than the buffer's limit. */ - final public char get(int index) + final public char get (int index) { if (index < 0 || index >= limit ()) throw new IndexOutOfBoundsException (); - return backing_buffer[index]; + return backing_buffer [index]; } /** @@ -168,7 +168,7 @@ public final class CharBufferImpl extends CharBuffer * than the buffer's limit. * @exception ReadOnlyBufferException If this buffer is read-only. */ - final public CharBuffer put(int index, char b) + final public CharBuffer put (int index, char value) { if (index < 0 || index >= limit ()) @@ -176,14 +176,13 @@ public final class CharBufferImpl extends CharBuffer if (readOnly) throw new ReadOnlyBufferException (); - - backing_buffer[index] = b; + + backing_buffer [index] = value; return this; } - - - public final ByteOrder order() + + final public ByteOrder order () { - return ByteOrder.BIG_ENDIAN; + return ByteOrder.nativeOrder (); } } diff --git a/libjava/gnu/java/nio/DirectByteBufferImpl.java b/libjava/gnu/java/nio/DirectByteBufferImpl.java index 0c08ab489db..47b76bb8142 100644 --- a/libjava/gnu/java/nio/DirectByteBufferImpl.java +++ b/libjava/gnu/java/nio/DirectByteBufferImpl.java @@ -75,7 +75,7 @@ public class DirectByteBufferImpl extends ByteBuffer { RawData address = allocateImpl (capacity); - if (address == 0) + if (address == null) throw new InternalError ("Not enough memory to create direct buffer"); return new DirectByteBufferImpl (address, 0, capacity, capacity, 0, -1, false); diff --git a/libjava/gnu/java/nio/DoubleBufferImpl.java b/libjava/gnu/java/nio/DoubleBufferImpl.java index 7d4f69311d0..dc809598238 100644 --- a/libjava/gnu/java/nio/DoubleBufferImpl.java +++ b/libjava/gnu/java/nio/DoubleBufferImpl.java @@ -1,5 +1,5 @@ /* DoubleBufferImpl.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,6 +35,7 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ + package gnu.java.nio; import java.nio.ByteBuffer; @@ -48,93 +49,114 @@ import java.nio.ReadOnlyBufferException; public final class DoubleBufferImpl extends DoubleBuffer { private boolean readOnly; - - public DoubleBufferImpl(int cap, int off, int lim) - { - super (cap, lim, off, 0); - this.backing_buffer = new double[cap]; - readOnly = false; - } - - public DoubleBufferImpl(double[] array, int offset, int length) - { - super (array.length, length, offset, 0); - this.backing_buffer = array; - readOnly = false; - } - public DoubleBufferImpl(DoubleBufferImpl copy) + DoubleBufferImpl (int capacity) { - super (copy.capacity (), copy.limit (), copy.position (), 0); - backing_buffer = copy.backing_buffer; - readOnly = copy.isReadOnly (); + this (new double [capacity], 0, capacity, capacity, 0, -1, false); + } + + DoubleBufferImpl (double[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly) + { + super (buffer, offset, capacity, limit, position, mark); + this.readOnly = readOnly; } public boolean isReadOnly () { return readOnly; } - + public DoubleBuffer slice () { - return new DoubleBufferImpl (this); + return new DoubleBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ()); } - - public DoubleBuffer duplicate() + + public DoubleBuffer duplicate () { - return new DoubleBufferImpl(this); + return new DoubleBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ()); } - - public DoubleBuffer asReadOnlyBuffer() + + public DoubleBuffer asReadOnlyBuffer () { - DoubleBufferImpl result = new DoubleBufferImpl (this); - result.readOnly = true; - return result; + return new DoubleBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true); } - - public DoubleBuffer compact() + + public DoubleBuffer compact () { + int copied = 0; + + while (remaining () > 0) + { + put (copied, get ()); + copied++; + } + + position (copied); return this; } - - public boolean isDirect() + + public boolean isDirect () { return false; } - final public double get() + /** + * Relative get method. Reads the next double from the buffer. + */ + final public double get () { - double e = backing_buffer[position()]; - position(position()+1); - return e; + double result = backing_buffer [position ()]; + position (position () + 1); + return result; } - - final public DoubleBuffer put(double b) + + /** + * Relative put method. Writes value to the next position + * in the buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + final public DoubleBuffer put (double value) { if (readOnly) throw new ReadOnlyBufferException (); - - backing_buffer[position()] = b; - position(position()+1); + + backing_buffer [position ()] = value; + position (position () + 1); return this; } - - final public double get(int index) + + /** + * Absolute get method. Reads the double at position + * index. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + */ + final public double get (int index) { - return backing_buffer[index]; + return backing_buffer [index]; } - - final public DoubleBuffer put(int index, double b) + + /** + * Absolute put method. Writes value to position + * index in the buffer. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + final public DoubleBuffer put (int index, double value) { if (readOnly) throw new ReadOnlyBufferException (); - - backing_buffer[index] = b; + + backing_buffer [index] = value; return this; } final public ByteOrder order () { - return ByteOrder.BIG_ENDIAN; + return ByteOrder.nativeOrder (); } } diff --git a/libjava/gnu/java/nio/FloatBufferImpl.java b/libjava/gnu/java/nio/FloatBufferImpl.java index 4acde80b747..69acecf52fe 100644 --- a/libjava/gnu/java/nio/FloatBufferImpl.java +++ b/libjava/gnu/java/nio/FloatBufferImpl.java @@ -1,5 +1,5 @@ /* FloatBufferImpl.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,6 +35,7 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ + package gnu.java.nio; import java.nio.ByteBuffer; @@ -48,26 +49,16 @@ import java.nio.ReadOnlyBufferException; public final class FloatBufferImpl extends FloatBuffer { private boolean readOnly; - - public FloatBufferImpl(int cap, int off, int lim) + + FloatBufferImpl (int capacity) { - super (cap, lim, off, 0); - this.backing_buffer = new float [cap]; - readOnly = false; + this (new float [capacity], 0, capacity, capacity, 0, -1, false); } - public FloatBufferImpl(float[] array, int offset, int length) + FloatBufferImpl (float[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly) { - super (array.length, length, offset, 0); - this.backing_buffer = array; - readOnly = false; - } - - public FloatBufferImpl(FloatBufferImpl copy) - { - super (copy.capacity (), copy.limit (), copy.position (), 0); - backing_buffer = copy.backing_buffer; - readOnly = copy.isReadOnly (); + super (buffer, offset, capacity, limit, position, mark); + this.readOnly = readOnly; } public boolean isReadOnly () @@ -75,66 +66,97 @@ public final class FloatBufferImpl extends FloatBuffer return readOnly; } - public FloatBuffer slice() + public FloatBuffer slice () { - return new FloatBufferImpl (this); + return new FloatBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ()); } - public FloatBuffer duplicate() + public FloatBuffer duplicate () { - return new FloatBufferImpl(this); + return new FloatBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ()); } - public FloatBuffer asReadOnlyBuffer() + public FloatBuffer asReadOnlyBuffer () { - FloatBufferImpl result = new FloatBufferImpl (this); - result.readOnly = true; - return result; + return new FloatBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true); } - public FloatBuffer compact() + public FloatBuffer compact () { + int copied = 0; + + while (remaining () > 0) + { + put (copied, get ()); + copied++; + } + + position (copied); return this; } - public boolean isDirect() + public boolean isDirect () { return false; } - - final public float get() + + /** + * Relative get method. Reads the next float from the buffer. + */ + final public float get () { - float e = backing_buffer[position()]; - position(position()+1); - return e; + float result = backing_buffer [position ()]; + position (position () + 1); + return result; } - final public FloatBuffer put(float b) + /** + * Relative put method. Writes value to the next position + * in the buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + final public FloatBuffer put (float value) { if (readOnly) throw new ReadOnlyBufferException (); - - backing_buffer[position()] = b; - position(position()+1); + + backing_buffer [position ()] = value; + position (position () + 1); return this; } - final public float get(int index) + /** + * Absolute get method. Reads the float at position + * index. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + */ + final public float get (int index) { - return backing_buffer[index]; + return backing_buffer [index]; } - final public FloatBuffer put(int index, float b) + /** + * Absolute put method. Writes value to position + * index in the buffer. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + final public FloatBuffer put (int index, float value) { if (readOnly) throw new ReadOnlyBufferException (); - - backing_buffer[index] = b; + + backing_buffer [index] = value; return this; } final public ByteOrder order () { - return ByteOrder.BIG_ENDIAN; + return ByteOrder.nativeOrder (); } } diff --git a/libjava/gnu/java/nio/IntBufferImpl.java b/libjava/gnu/java/nio/IntBufferImpl.java index cfa3efe597a..573e5e0372b 100644 --- a/libjava/gnu/java/nio/IntBufferImpl.java +++ b/libjava/gnu/java/nio/IntBufferImpl.java @@ -1,5 +1,5 @@ /* IntBufferImpl.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,6 +35,7 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ + package gnu.java.nio; import java.nio.ByteBuffer; @@ -48,93 +49,114 @@ import java.nio.ReadOnlyBufferException; public final class IntBufferImpl extends IntBuffer { private boolean readOnly; + + IntBufferImpl (int capacity) + { + this (new int [capacity], 0, capacity, capacity, 0, -1, false); + } - public IntBufferImpl(int cap, int off, int lim) + IntBufferImpl (int[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly) { - super (cap, lim, off, 0); - this.backing_buffer = new int[cap]; - readOnly = false; + super (buffer, offset, capacity, limit, position, mark); + this.readOnly = readOnly; } - - public IntBufferImpl(int[] array, int offset, int length) - { - super (array.length, length, offset, 0); - this.backing_buffer = array; - readOnly = false; - } - - public IntBufferImpl(IntBufferImpl copy) - { - super (copy.capacity (), copy.limit (), copy.position (), 0); - backing_buffer = copy.backing_buffer; - readOnly = copy.isReadOnly (); - } - - public boolean isReadOnly() + + public boolean isReadOnly () { return readOnly; } - - public IntBuffer slice() + + public IntBuffer slice () { - return new IntBufferImpl (this); + return new IntBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ()); } - - public IntBuffer duplicate() + + public IntBuffer duplicate () { - return new IntBufferImpl(this); + return new IntBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ()); } - - public IntBuffer asReadOnlyBuffer() + + public IntBuffer asReadOnlyBuffer () { - IntBufferImpl result = new IntBufferImpl (this); - result.readOnly = true; - return result; + return new IntBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true); } - - public IntBuffer compact() + + public IntBuffer compact () { + int copied = 0; + + while (remaining () > 0) + { + put (copied, get ()); + copied++; + } + + position (copied); return this; } - - public boolean isDirect() + + public boolean isDirect () { return false; } - final public int get() + /** + * Relative get method. Reads the next int from the buffer. + */ + final public int get () { - int e = backing_buffer[position()]; - position(position()+1); - return e; + int result = backing_buffer [position ()]; + position (position () + 1); + return result; } - - final public IntBuffer put(int b) + + /** + * Relative put method. Writes value to the next position + * in the buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + final public IntBuffer put (int value) { if (readOnly) throw new ReadOnlyBufferException (); - - backing_buffer[position()] = b; - position(position()+1); + + backing_buffer [position ()] = value; + position (position () + 1); return this; } - - final public int get(int index) + + /** + * Absolute get method. Reads the int at position + * index. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + */ + final public int get (int index) { - return backing_buffer[index]; + return backing_buffer [index]; } - - final public IntBuffer put(int index, int b) + + /** + * Absolute put method. Writes value to position + * index in the buffer. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + final public IntBuffer put (int index, int value) { if (readOnly) throw new ReadOnlyBufferException (); - - backing_buffer[index] = b; + + backing_buffer [index] = value; return this; } final public ByteOrder order () { - return ByteOrder.BIG_ENDIAN; + return ByteOrder.nativeOrder (); } } diff --git a/libjava/gnu/java/nio/LongBufferImpl.java b/libjava/gnu/java/nio/LongBufferImpl.java index 8a295fa5a35..e37ac8e4b2c 100644 --- a/libjava/gnu/java/nio/LongBufferImpl.java +++ b/libjava/gnu/java/nio/LongBufferImpl.java @@ -1,5 +1,5 @@ /* LongBufferImpl.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,6 +35,7 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ + package gnu.java.nio; import java.nio.ByteBuffer; @@ -49,92 +50,113 @@ public final class LongBufferImpl extends LongBuffer { private boolean readOnly; - public LongBufferImpl(int cap, int off, int lim) + LongBufferImpl (int capacity) { - super (cap, lim, off, 0); - this.backing_buffer = new long[cap]; - readOnly = false; + this (new long [capacity], 0, capacity, capacity, 0, -1, false); } - - public LongBufferImpl(long[] array, int offset, int length) + + LongBufferImpl (long[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly) { - super (array.length, length, offset, 0); - this.backing_buffer = array; - readOnly = false; + super (buffer, offset, capacity, limit, position, mark); + this.readOnly = readOnly; } - - public LongBufferImpl(LongBufferImpl copy) - { - super (copy.capacity (), copy.limit (), copy.position (), 0); - backing_buffer = copy.backing_buffer; - readOnly = copy.isReadOnly (); - } - - public boolean isReadOnly() + + public boolean isReadOnly () { return readOnly; } - - public LongBuffer slice() + + public LongBuffer slice () { - return new LongBufferImpl (this); + return new LongBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ()); } - - public LongBuffer duplicate() + + public LongBuffer duplicate () { - return new LongBufferImpl(this); + return new LongBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ()); } - - public LongBuffer asReadOnlyBuffer() + + public LongBuffer asReadOnlyBuffer () { - LongBufferImpl result = new LongBufferImpl (this); - result.readOnly = true; - return result; + return new LongBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true); } - - public LongBuffer compact() + + public LongBuffer compact () { + int copied = 0; + + while (remaining () > 0) + { + put (copied, get ()); + copied++; + } + + position (copied); return this; } - - public boolean isDirect() + + public boolean isDirect () { return false; } - final public long get() + /** + * Relative get method. Reads the next long from the buffer. + */ + final public long get () { - long e = backing_buffer[position()]; - position(position()+1); - return e; + long result = backing_buffer [position ()]; + position (position () + 1); + return result; } - - final public LongBuffer put(long b) + + /** + * Relative put method. Writes value to the next position + * in the buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + final public LongBuffer put (long value) { if (readOnly) throw new ReadOnlyBufferException (); - - backing_buffer[position()] = b; - position(position()+1); + + backing_buffer [position ()] = value; + position (position () + 1); return this; } - - final public long get(int index) + + /** + * Absolute get method. Reads the long at position + * index. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + */ + final public long get (int index) { - return backing_buffer[index]; + return backing_buffer [index]; } - - final public LongBuffer put(int index, long b) + + /** + * Absolute put method. Writes value to position + * index in the buffer. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + final public LongBuffer put (int index, long value) { if (readOnly) throw new ReadOnlyBufferException (); - - backing_buffer[index] = b; + + backing_buffer [index] = value; return this; } - + final public ByteOrder order () { - return ByteOrder.BIG_ENDIAN; + return ByteOrder.nativeOrder (); } } diff --git a/libjava/gnu/java/nio/ShortBufferImpl.java b/libjava/gnu/java/nio/ShortBufferImpl.java index c4f679b7ce8..3dc625e1158 100644 --- a/libjava/gnu/java/nio/ShortBufferImpl.java +++ b/libjava/gnu/java/nio/ShortBufferImpl.java @@ -1,5 +1,5 @@ /* ShortBufferImpl.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -35,6 +35,7 @@ this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version. */ + package gnu.java.nio; import java.nio.ByteBuffer; @@ -49,92 +50,113 @@ public final class ShortBufferImpl extends ShortBuffer { private boolean readOnly; - public ShortBufferImpl(int cap, int off, int lim) + ShortBufferImpl (int capacity) { - super (cap, lim, off, 0); - this.backing_buffer = new short [cap]; - readOnly = false; + this (new short [capacity], 0, capacity, capacity, 0, -1, false); } - - public ShortBufferImpl(short[] array, int offset, int length) + + ShortBufferImpl (short[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly) { - super (array.length, length, offset, 0); - this.backing_buffer = array; - readOnly = false; + super (buffer, offset, capacity, limit, position, mark); + this.readOnly = readOnly; } - - public ShortBufferImpl(ShortBufferImpl copy) - { - super (copy.capacity (), copy.limit (), copy.position (), 0); - backing_buffer = copy.backing_buffer; - readOnly = copy.isReadOnly (); - } - - public boolean isReadOnly() + + public boolean isReadOnly () { return readOnly; } - - public ShortBuffer slice() + + public ShortBuffer slice () { - return new ShortBufferImpl (this); + return new ShortBufferImpl (backing_buffer, array_offset + position (), remaining (), remaining (), 0, -1, isReadOnly ()); } - - public ShortBuffer duplicate() + + public ShortBuffer duplicate () { - return new ShortBufferImpl(this); + return new ShortBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, isReadOnly ()); } - - public ShortBuffer asReadOnlyBuffer() + + public ShortBuffer asReadOnlyBuffer () { - ShortBufferImpl result = new ShortBufferImpl (this); - result.readOnly = true; - return result; + return new ShortBufferImpl (backing_buffer, array_offset, capacity (), limit (), position (), mark, true); } - - public ShortBuffer compact() + + public ShortBuffer compact () { + int copied = 0; + + while (remaining () > 0) + { + put (copied, get ()); + copied++; + } + + position (copied); return this; } - - public boolean isDirect() + + public boolean isDirect () { return false; } - final public short get() + /** + * Relative get method. Reads the next short from the buffer. + */ + final public short get () { - short e = backing_buffer[position()]; - position(position()+1); - return e; + short result = backing_buffer [position ()]; + position (position () + 1); + return result; } - - final public ShortBuffer put(short b) + + /** + * Relative put method. Writes value to the next position + * in the buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + final public ShortBuffer put (short value) { if (readOnly) throw new ReadOnlyBufferException (); - - backing_buffer[position()] = b; - position(position()+1); + + backing_buffer [position ()] = value; + position (position () + 1); return this; } - - final public short get(int index) + + /** + * Absolute get method. Reads the short at position + * index. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + */ + final public short get (int index) { - return backing_buffer[index]; + return backing_buffer [index]; } - - final public ShortBuffer put(int index, short b) + + /** + * Absolute put method. Writes value to position + * index in the buffer. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + final public ShortBuffer put (int index, short value) { if (readOnly) throw new ReadOnlyBufferException (); - - backing_buffer[index] = b; + + backing_buffer [index] = value; return this; } final public ByteOrder order () { - return ByteOrder.BIG_ENDIAN; + return ByteOrder.nativeOrder (); } } diff --git a/libjava/gnu/java/nio/natByteBufferImpl.cc b/libjava/gnu/java/nio/natByteBufferImpl.cc deleted file mode 100644 index c6ba45669ff..00000000000 --- a/libjava/gnu/java/nio/natByteBufferImpl.cc +++ /dev/null @@ -1,82 +0,0 @@ -// natByteBufferImpl.cc - -/* Copyright (C) 2002, 2003 Free Software Foundation - - This file is part of libgcj. - -This software is copyrighted work licensed under the terms of the -Libgcj License. Please consult the file "LIBGCJ_LICENSE" for -details. */ - -#include - -#include -#include - -#include - -void -gnu::java::nio::ByteBufferImpl::nio_put_Char(gnu::java::nio::ByteBufferImpl*, jint, jint, jchar) -{ -} - -void -gnu::java::nio::ByteBufferImpl::nio_put_Short(gnu::java::nio::ByteBufferImpl*, jint, jint, jshort) -{ -} - -void -gnu::java::nio::ByteBufferImpl::nio_put_Int(gnu::java::nio::ByteBufferImpl*, jint, jint, jint) -{ -} - -void -gnu::java::nio::ByteBufferImpl::nio_put_Long(gnu::java::nio::ByteBufferImpl*, jint, jint, jlong) -{ -} - -void -gnu::java::nio::ByteBufferImpl::nio_put_Float(gnu::java::nio::ByteBufferImpl*, jint, jint, jfloat) -{ -} - -void -gnu::java::nio::ByteBufferImpl::nio_put_Double(gnu::java::nio::ByteBufferImpl*, jint, jint, jdouble) -{ -} - -jchar -gnu::java::nio::ByteBufferImpl::nio_get_Char(gnu::java::nio::ByteBufferImpl*, jint, jint) -{ - return ' '; -} - -jshort -gnu::java::nio::ByteBufferImpl::nio_get_Short(gnu::java::nio::ByteBufferImpl*, jint, jint) -{ - return 0; -} - -jint -gnu::java::nio::ByteBufferImpl::nio_get_Int(gnu::java::nio::ByteBufferImpl*, jint, jint) -{ - return 0; -} - -jlong -gnu::java::nio::ByteBufferImpl::nio_get_Long(gnu::java::nio::ByteBufferImpl*, jint, jint) -{ - return 0; -} - -jfloat -gnu::java::nio::ByteBufferImpl::nio_get_Float(gnu::java::nio::ByteBufferImpl*, jint, jint) -{ - return 0.0; -} - -jdouble -gnu::java::nio::ByteBufferImpl::nio_get_Double(gnu::java::nio::ByteBufferImpl*, jint, jint) -{ - return 0.0; -} diff --git a/libjava/gnu/java/nio/natCharBufferImpl.cc b/libjava/gnu/java/nio/natCharBufferImpl.cc deleted file mode 100644 index eb729277d3a..00000000000 --- a/libjava/gnu/java/nio/natCharBufferImpl.cc +++ /dev/null @@ -1,22 +0,0 @@ -// natCharBufferImpl.cc - -/* Copyright (C) 2002, 2003 Free Software Foundation - - This file is part of libgcj. - -This software is copyrighted work licensed under the terms of the -Libgcj License. Please consult the file "LIBGCJ_LICENSE" for -details. */ - -#include - -#include -#include - -#include - -JArray* -gnu::java::nio::CharBufferImpl::nio_cast(JArray*) -{ - return NULL; -} diff --git a/libjava/java/nio/CharBuffer.java b/libjava/java/nio/CharBuffer.java index 2158af0160f..fbee6dfb9dd 100644 --- a/libjava/java/nio/CharBuffer.java +++ b/libjava/java/nio/CharBuffer.java @@ -1,5 +1,5 @@ /* CharBuffer.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -45,26 +45,40 @@ import gnu.java.nio.CharBufferImpl; public abstract class CharBuffer extends Buffer implements Comparable, CharSequence { - int array_offset = 0; + int array_offset; char[] backing_buffer; - + + CharBuffer (int capacity, int limit, int position, int mark) + { + super (capacity, limit, position, mark); + array_offset = 0; + } + + CharBuffer (char[] buffer, int offset, int capacity, int limit, int position, int mark) + { + super (capacity, limit, position, mark); + this.backing_buffer = buffer; + this.array_offset = offset; + } + /** * Allocates a new CharBuffer object with a given capacity. */ public static CharBuffer allocate (int capacity) { - return new CharBufferImpl (capacity, 0, capacity); + return new CharBufferImpl (capacity); } - + /** - * Wraps a character array into a CharBuffer object. - * + * Wraps a char array into a CharBuffer + * object. + * * @exception IndexOutOfBoundsException If the preconditions on the offset * and length parameters do not hold */ final public static CharBuffer wrap (char[] array, int offset, int length) { - return new CharBufferImpl (array, offset, length); + return new CharBufferImpl (array, 0, array.length, offset + length, offset, -1, false); } /** @@ -101,27 +115,30 @@ public abstract class CharBuffer extends Buffer return wrap (buffer, offset, length); } - + /** - * Wraps a character array into a CharBuffer object. + * Wraps a char array into a CharBuffer + * object. */ final public static CharBuffer wrap (char[] array) { return wrap (array, 0, array.length); } - - CharBuffer (int cap, int lim, int pos, int mark) - { - super (cap, lim, pos, mark); - } /** - * Relative get method. - * - * @exception BufferUnderflowException If the buffer's current position is - * not smaller than its limit. + * This method transfers chars from this buffer into the given + * destination array. + * + * @param dst The destination array + * @param offset The offset within the array of the first char + * to be written; must be non-negative and no larger than dst.length. + * @param length The maximum number of bytes to be written to the given array; + * must be non-negative and no larger than dst.length - offset. + * + * @exception BufferUnderflowException If there are fewer than length + * chars remaining in this buffer. * @exception IndexOutOfBoundsException If the preconditions on the offset - * and length parameters do not hold + * and length parameters do not hold. */ public CharBuffer get (char[] dst, int offset, int length) { @@ -129,24 +146,32 @@ public abstract class CharBuffer extends Buffer { dst [i] = get (); } - + return this; } - + /** - * Relative get method. - * - * @exception BufferUnderflowException If there are fewer than length - * characters remaining in this buffer. + * This method transfers chars 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 + * chars remaining in this buffer. */ public CharBuffer get (char[] dst) { return get (dst, 0, dst.length); } - + /** - * @exception BufferOverflowException If there are fewer than length of - * source buffer characters remaining in this buffer. + * Writes the content of the the CharBUFFER src + * into the buffer. + * + * @param src The source data. + * + * @exception BufferOverflowException If there is insufficient space in this + * buffer for the remaining chars in the source buffer. * @exception IllegalArgumentException If the source buffer is this buffer. * @exception ReadOnlyBufferException If this buffer is read-only. */ @@ -155,19 +180,31 @@ public abstract class CharBuffer extends Buffer if (src == this) throw new IllegalArgumentException (); - if (src.length () > 0) + if (src.remaining () > remaining ()) + throw new BufferOverflowException (); + + if (src.remaining () > 0) { - char [] toPut = new char [src.length ()]; + char[] toPut = new char [src.remaining ()]; src.get (toPut); src.put (toPut); } return this; } - + /** - * @exception BufferOverflowException If there are fewer then length - * characters remaining in this buffer. + * Writes the content of the the char 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 chars 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. @@ -185,18 +222,19 @@ public abstract class CharBuffer extends Buffer throw new BufferOverflowException (); for (int i = offset; i < offset + length; i++) - { - put (src [i]); - } + put (src [i]); return this; } /** - * Relative put method. + * Writes the content of the the char array src + * into the buffer. + * + * @param src The array to copy into the buffer. * - * @exception BufferOverflowException If there are fewer then length of the - * array characters remaining in this buffer. + * @exception BufferOverflowException If there is insufficient space in this + * buffer for the remaining chars in the source array. * @exception ReadOnlyBufferException If this buffer is read-only. */ public final CharBuffer put (char[] src) @@ -205,17 +243,18 @@ public abstract class CharBuffer extends Buffer } /** - * Tells wether this is buffer is backed by an accessible array or not. + * Tells whether ot not this buffer is backed by an accessible + * char array. */ public final boolean hasArray () { return (backing_buffer != null - && ! isReadOnly ()); + && !isReadOnly ()); } /** - * Returns the array that backs this buffer. - * + * Returns the char array that backs this buffer. + * * @exception ReadOnlyBufferException If this buffer is read-only. * @exception UnsupportedOperationException If this buffer is not backed * by an accessible array. @@ -230,10 +269,10 @@ public abstract class CharBuffer extends Buffer return backing_buffer; } - + /** - * Returns the offset to the position of a character in this buffer. - * + * Returns the offset within this buffer's backing array of the first element. + * * @exception ReadOnlyBufferException If this buffer is read-only. * @exception UnsupportedOperationException If this buffer is not backed * by an accessible array. @@ -248,78 +287,92 @@ public abstract class CharBuffer extends Buffer return array_offset; } - + /** - * Calculates a hash code for this buffer- + * Calculates a hash code for this buffer. */ public int hashCode () { // FIXME: Check what SUN calculates here. return super.hashCode (); } - + /** * Checks if this buffer is equal to obj. */ public boolean equals (Object obj) { if (obj instanceof CharBuffer) - return compareTo (obj) == 0; - + { + return compareTo (obj) == 0; + } + return false; } - + /** - * Compares two character buffer objects. - * + * Compares two CharBuffer objects. + * * @exception ClassCastException If obj is not an object derived from * CharBuffer. */ - public int compareTo(Object obj) + public int compareTo (Object obj) { CharBuffer a = (CharBuffer) obj; - + if (a.remaining () != remaining ()) return 1; - - if (! hasArray () || ! a.hasArray ()) - return 1; - + + if (! hasArray () || + ! a.hasArray ()) + { + return 1; + } + int r = remaining (); int i1 = position (); int i2 = a.position (); - + for (int i = 0; i < r; i++) { - int t = (int) (get (i1)- a.get (i2)); - + int t = (int) (get (i1) - a.get (i2)); + if (t != 0) - return (int) t; + { + return (int) t; + } } - + return 0; } - + /** - * Relative get method. - * - * @exception BufferUnderflowException If there are no remaining characters - * in this buffer. + * Returns the byte order of this buffer. + */ + public abstract ByteOrder order (); + + /** + * Reads the char at this buffer's current position, + * and then increments the position. + * + * @exception BufferUnderflowException If there are no remaining + * chars in this buffer. */ public abstract char get (); - + /** - * Relative put method. - * - * @exception BufferOverflowException If there no remaining characters in - * this buffer. + * Writes the char at this buffer's current position, + * and then increments the position. + * + * @exception BufferOverflowException If there no remaining + * chars in this buffer. * @exception ReadOnlyBufferException If this buffer is read-only. */ public abstract CharBuffer put (char b); - + /** * Absolute get method. - * + * * @exception IndexOutOfBoundsException If index is negative or not smaller * than the buffer's limit. */ @@ -327,32 +380,40 @@ public abstract class CharBuffer extends Buffer /** * Absolute put method. - * + * * @exception IndexOutOfBoundsException If index is negative or not smaller * than the buffer's limit. * @exception ReadOnlyBufferException If this buffer is read-only. */ public abstract CharBuffer put (int index, char b); - + /** + * Compacts this buffer. + * * @exception ReadOnlyBufferException If this buffer is read-only. */ public abstract CharBuffer compact (); - + /** - * Tells wether this buffer is direct or not. + * Tells wether or not this buffer is direct. */ public abstract boolean isDirect (); - - public abstract CharBuffer slice (); - + /** - * Duplicates this buffer. + * Creates a new CharBuffer whose content is a shared + * subsequence of this buffer's content. + */ + public abstract CharBuffer slice (); + + /** + * Creates a new CharBuffer that shares this buffer's + * content. */ public abstract CharBuffer duplicate (); - + /** - * Returns this buffer made read-only. + * Creates a new read-only CharBuffer that shares this + * buffer's content. */ public abstract CharBuffer asReadOnlyBuffer (); @@ -377,11 +438,6 @@ public abstract class CharBuffer extends Buffer return remaining (); } - /** - * Returns the byte order of this buffer. - */ - public abstract ByteOrder order (); - /** * Creates a new character buffer that represents the specified subsequence * of this buffer, relative to the current position. diff --git a/libjava/java/nio/DoubleBuffer.java b/libjava/java/nio/DoubleBuffer.java index ef39ac10048..f212566111c 100644 --- a/libjava/java/nio/DoubleBuffer.java +++ b/libjava/java/nio/DoubleBuffer.java @@ -1,5 +1,5 @@ /* DoubleBuffer.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,72 +39,141 @@ package java.nio; import gnu.java.nio.DoubleBufferImpl; -public abstract class DoubleBuffer extends Buffer implements Comparable +/** + * @since 1.4 + */ +public abstract class DoubleBuffer extends Buffer + implements Comparable { int array_offset; double[] backing_buffer; - public static DoubleBuffer allocateDirect(int capacity) - { - throw new Error ("direct buffers are not implemented"); - } - - public static DoubleBuffer allocate(int capacity) - { - return new DoubleBufferImpl(capacity, 0, capacity); - } - - final public static DoubleBuffer wrap (double[] array, int offset, int length) - { - return new DoubleBufferImpl(array, offset, length); - } - - final public static DoubleBuffer wrap(String a) - { - int len = a.length(); - double[] buffer = new double[len]; - - for (int i=0;iDoubleBuffer object with a given capacity. + */ + public static DoubleBuffer allocate (int capacity) + { + return new DoubleBufferImpl (capacity); + } + + /** + * Wraps a double array into a DoubleBuffer + * object. + * + * @exception IndexOutOfBoundsException If the preconditions on the offset + * and length parameters do not hold + */ + final public static DoubleBuffer wrap (double[] array, int offset, int length) + { + return new DoubleBufferImpl (array, 0, array.length, offset + length, offset, -1, false); + } + + /** + * Wraps a double array into a DoubleBuffer + * object. + */ + final public static DoubleBuffer wrap (double[] array) + { + return wrap (array, 0, array.length); } + /** + * This method transfers doubles from this buffer into the given + * destination array. + * + * @param dst The destination array + * @param offset The offset within the array of the first double + * to be written; must be non-negative and no larger than dst.length. + * @param length The maximum number of bytes to be written to the given array; + * must be non-negative and no larger than dst.length - offset. + * + * @exception BufferUnderflowException If there are fewer than length + * doubles 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) { for (int i = offset; i < offset + length; i++) { - dst[i] = get(); + dst [i] = get (); } return this; } + /** + * This method transfers doubles 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 + * doubles remaining in this buffer. + */ public DoubleBuffer get (double[] dst) { - return get(dst, 0, dst.length); + return get (dst, 0, dst.length); } + /** + * Writes the content of the the DoubleBUFFER src + * into the buffer. + * + * @param src The source data. + * + * @exception BufferOverflowException If there is insufficient space in this + * buffer for the remaining doubles in the source buffer. + * @exception IllegalArgumentException If the source buffer is this buffer. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ public DoubleBuffer put (DoubleBuffer src) { - while (src.hasRemaining()) - put(src.get()); + if (src == this) + throw new IllegalArgumentException (); + + if (src.remaining () > remaining ()) + throw new BufferOverflowException (); + + if (src.remaining () > 0) + { + double[] toPut = new double [src.remaining ()]; + src.get (toPut); + src.put (toPut); + } return this; } + /** + * Writes the content of the the double 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 doubles 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) { for (int i = offset; i < offset + length; i++) @@ -113,18 +182,39 @@ public abstract class DoubleBuffer extends Buffer implements Comparable return this; } - public final DoubleBuffer put(double[] src) + /** + * Writes the content of the the double 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 doubles in the source array. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public final DoubleBuffer put (double[] src) { - return put(src, 0, src.length); + return put (src, 0, src.length); } - public final boolean hasArray() + /** + * Tells whether ot not this buffer is backed by an accessible + * double array. + */ + public final boolean hasArray () { return (backing_buffer != null && !isReadOnly ()); } - public final double[] array() + /** + * Returns the double array that backs this buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + * @exception UnsupportedOperationException If this buffer is not backed + * by an accessible array. + */ + public final double[] array () { if (backing_buffer == null) throw new UnsupportedOperationException (); @@ -135,7 +225,14 @@ public abstract class DoubleBuffer extends Buffer implements Comparable return backing_buffer; } - public final int arrayOffset() + /** + * Returns the offset within this buffer's backing array of the first element. + * + * @exception ReadOnlyBufferException If this buffer 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 (); @@ -146,41 +243,55 @@ public abstract class DoubleBuffer extends Buffer implements Comparable return array_offset; } - public int hashCode() + /** + * Calculates a hash code for this buffer. + */ + public int hashCode () { - return super.hashCode(); + // FIXME: Check what SUN calculates here. + return super.hashCode (); } - public boolean equals(Object obj) + /** + * Checks if this buffer is equal to obj. + */ + public boolean equals (Object obj) { if (obj instanceof DoubleBuffer) { - return compareTo(obj) == 0; + return compareTo (obj) == 0; } return false; } - public int compareTo(Object ob) + /** + * Compares two DoubleBuffer objects. + * + * @exception ClassCastException If obj is not an object derived from + * DoubleBuffer. + */ + public int compareTo (Object obj) { - DoubleBuffer a = (DoubleBuffer) ob; + DoubleBuffer a = (DoubleBuffer) obj; - if (a.remaining() != remaining()) + if (a.remaining () != remaining ()) return 1; - if (! hasArray() || - ! a.hasArray()) + if (! hasArray () || + ! a.hasArray ()) { return 1; } - int r = remaining(); + int r = remaining (); int i1 = position (); int i2 = a.position (); - for (int i=0;idouble at this buffer's current position, + * and then increments the position. + * + * @exception BufferUnderflowException If there are no remaining + * doubles in this buffer. + */ + public abstract double get (); + + /** + * Writes the double at this buffer's current position, + * and then increments the position. + * + * @exception BufferOverflowException If there no remaining + * doubles in this buffer. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ public abstract DoubleBuffer put (double b); - public abstract double get(int index); - public abstract DoubleBuffer put(int index, double b); - public abstract DoubleBuffer compact(); - public abstract boolean isDirect(); - public abstract DoubleBuffer slice(); - public abstract DoubleBuffer duplicate(); - public abstract DoubleBuffer asReadOnlyBuffer(); + + /** + * Absolute get method. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + */ + public abstract double get (int index); + + /** + * Absolute put method. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public abstract DoubleBuffer put (int index, double b); + + /** + * Compacts this buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public abstract DoubleBuffer compact (); + + /** + * Tells wether or not this buffer is direct. + */ + public abstract boolean isDirect (); + + /** + * Creates a new DoubleBuffer whose content is a shared + * subsequence of this buffer's content. + */ + public abstract DoubleBuffer slice (); + + /** + * Creates a new DoubleBuffer that shares this buffer's + * content. + */ + public abstract DoubleBuffer duplicate (); + + /** + * Creates a new read-only DoubleBuffer that shares this + * buffer's content. + */ + public abstract DoubleBuffer asReadOnlyBuffer (); } diff --git a/libjava/java/nio/FloatBuffer.java b/libjava/java/nio/FloatBuffer.java index 81feb456e15..65d680bb108 100644 --- a/libjava/java/nio/FloatBuffer.java +++ b/libjava/java/nio/FloatBuffer.java @@ -1,5 +1,5 @@ /* FloatBuffer.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,93 +39,182 @@ package java.nio; import gnu.java.nio.FloatBufferImpl; -public abstract class FloatBuffer extends Buffer implements Comparable +/** + * @since 1.4 + */ +public abstract class FloatBuffer extends Buffer + implements Comparable { int array_offset; float[] backing_buffer; - public static FloatBuffer allocateDirect(int capacity) - { - throw new Error ("direct buffers not implemented"); - } - - public static FloatBuffer allocate(int capacity) - { - return new FloatBufferImpl (capacity, 0, capacity); - } - - final public static FloatBuffer wrap(float[] array, int offset, int length) - { - return new FloatBufferImpl(array, offset, length); - } - - final public static FloatBuffer wrap(String a) - { - int len = a.length(); - float[] buffer = new float[len]; - - for (int i=0;iFloatBuffer object with a given capacity. + */ + public static FloatBuffer allocate (int capacity) + { + return new FloatBufferImpl (capacity); + } + + /** + * Wraps a float array into a FloatBuffer + * object. + * + * @exception IndexOutOfBoundsException If the preconditions on the offset + * and length parameters do not hold + */ + final public static FloatBuffer wrap (float[] array, int offset, int length) + { + return new FloatBufferImpl (array, 0, array.length, offset + length, offset, -1, false); + } + + /** + * Wraps a float array into a FloatBuffer + * object. + */ + final public static FloatBuffer wrap (float[] array) + { + return wrap (array, 0, array.length); } + /** + * This method transfers floats from this buffer into the given + * destination array. + * + * @param dst The destination array + * @param offset The offset within the array of the first float + * to be written; must be non-negative and no larger than dst.length. + * @param length The maximum number of bytes to be written to the given array; + * must be non-negative and no larger than dst.length - offset. + * + * @exception BufferUnderflowException If there are fewer than length + * floats 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) { for (int i = offset; i < offset + length; i++) { - dst[i] = get(); + dst [i] = get (); } return this; } + /** + * This method transfers floats 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 + * floats remaining in this buffer. + */ public FloatBuffer get (float[] dst) { - return get(dst, 0, dst.length); + return get (dst, 0, dst.length); } + /** + * Writes the content of the the FloatBUFFER src + * into the buffer. + * + * @param src The source data. + * + * @exception BufferOverflowException If there is insufficient space in this + * buffer for the remaining floats in the source buffer. + * @exception IllegalArgumentException If the source buffer is this buffer. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ public FloatBuffer put (FloatBuffer src) { - while (src.hasRemaining()) - put(src.get()); + if (src == this) + throw new IllegalArgumentException (); + + if (src.remaining () > remaining ()) + throw new BufferOverflowException (); + + if (src.remaining () > 0) + { + float[] toPut = new float [src.remaining ()]; + src.get (toPut); + src.put (toPut); + } return this; } + /** + * Writes the content of the the float 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 floats 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) { for (int i = offset; i < offset + length; i++) - put(src[i]); + put (src [i]); return this; } - public final FloatBuffer put(float[] src) + /** + * Writes the content of the the float 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 floats in the source array. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public final FloatBuffer put (float[] src) { - return put(src, 0, src.length); + return put (src, 0, src.length); } - public final boolean hasArray() + /** + * Tells whether ot not this buffer is backed by an accessible + * float array. + */ + public final boolean hasArray () { return (backing_buffer != null && !isReadOnly ()); } - public final float[] array() + /** + * Returns the float array that backs this buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + * @exception UnsupportedOperationException If this buffer is not backed + * by an accessible array. + */ + public final float[] array () { if (backing_buffer == null) throw new UnsupportedOperationException (); @@ -136,7 +225,14 @@ public abstract class FloatBuffer extends Buffer implements Comparable return backing_buffer; } - public final int arrayOffset() + /** + * Returns the offset within this buffer's backing array of the first element. + * + * @exception ReadOnlyBufferException If this buffer 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 (); @@ -147,41 +243,55 @@ public abstract class FloatBuffer extends Buffer implements Comparable return array_offset; } - public int hashCode() + /** + * Calculates a hash code for this buffer. + */ + public int hashCode () { - return super.hashCode(); + // FIXME: Check what SUN calculates here. + return super.hashCode (); } - public boolean equals(Object obj) + /** + * Checks if this buffer is equal to obj. + */ + public boolean equals (Object obj) { if (obj instanceof FloatBuffer) { - return compareTo(obj) == 0; + return compareTo (obj) == 0; } return false; } - public int compareTo(Object ob) + /** + * Compares two FloatBuffer objects. + * + * @exception ClassCastException If obj is not an object derived from + * FloatBuffer. + */ + public int compareTo (Object obj) { - FloatBuffer a = (FloatBuffer) ob; + FloatBuffer a = (FloatBuffer) obj; - if (a.remaining() != remaining()) + if (a.remaining () != remaining ()) return 1; - if (! hasArray() || - ! a.hasArray()) + if (! hasArray () || + ! a.hasArray ()) { return 1; } - int r = remaining(); + int r = remaining (); int i1 = position (); int i2 = a.position (); - for (int i=0;ifloat at this buffer's current position, + * and then increments the position. + * + * @exception BufferUnderflowException If there are no remaining + * floats in this buffer. + */ + public abstract float get (); + + /** + * Writes the float at this buffer's current position, + * and then increments the position. + * + * @exception BufferOverflowException If there no remaining + * floats in this buffer. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public abstract FloatBuffer put (float b); + + /** + * Absolute get method. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + */ + public abstract float get (int index); + + /** + * Absolute put method. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public abstract FloatBuffer put (int index, float b); + + /** + * Compacts this buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public abstract FloatBuffer compact (); + + /** + * Tells wether or not this buffer is direct. + */ + public abstract boolean isDirect (); + + /** + * Creates a new FloatBuffer whose content is a shared + * subsequence of this buffer's content. + */ + public abstract FloatBuffer slice (); + + /** + * Creates a new FloatBuffer that shares this buffer's + * content. + */ + public abstract FloatBuffer duplicate (); + + /** + * Creates a new read-only FloatBuffer that shares this + * buffer's content. + */ + public abstract FloatBuffer asReadOnlyBuffer (); } diff --git a/libjava/java/nio/IntBuffer.java b/libjava/java/nio/IntBuffer.java index 295ad6a1d8b..c8e0d0f4b9c 100644 --- a/libjava/java/nio/IntBuffer.java +++ b/libjava/java/nio/IntBuffer.java @@ -1,5 +1,5 @@ /* IntBuffer.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,93 +39,182 @@ package java.nio; import gnu.java.nio.IntBufferImpl; -public abstract class IntBuffer extends Buffer implements Comparable +/** + * @since 1.4 + */ +public abstract class IntBuffer extends Buffer + implements Comparable { int array_offset; int[] backing_buffer; - public static IntBuffer allocateDirect(int capacity) - { - throw new Error ("direct buffers not implemented"); - } - - public static IntBuffer allocate(int capacity) - { - return new IntBufferImpl (capacity, 0, capacity); - } - - final public static IntBuffer wrap(int[] array, int offset, int length) - { - return new IntBufferImpl(array, offset, length); - } - - final public static IntBuffer wrap(String a) - { - int len = a.length(); - int[] buffer = new int[len]; - - for (int i=0;iIntBuffer object with a given capacity. + */ + public static IntBuffer allocate (int capacity) + { + return new IntBufferImpl (capacity); + } + + /** + * Wraps a int array into a IntBuffer + * object. + * + * @exception IndexOutOfBoundsException If the preconditions on the offset + * and length parameters do not hold + */ + final public static IntBuffer wrap (int[] array, int offset, int length) + { + return new IntBufferImpl (array, 0, array.length, offset + length, offset, -1, false); + } + + /** + * Wraps a int array into a IntBuffer + * object. + */ + final public static IntBuffer wrap (int[] array) + { + return wrap (array, 0, array.length); + } - public IntBuffer get(int[] dst, int offset, int length) + /** + * This method transfers ints from this buffer into the given + * destination array. + * + * @param dst The destination array + * @param offset The offset within the array of the first int + * to be written; must be non-negative and no larger than dst.length. + * @param length The maximum number of bytes to be written to the given array; + * must be non-negative and no larger than dst.length - offset. + * + * @exception BufferUnderflowException If there are fewer than length + * ints 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) { for (int i = offset; i < offset + length; i++) { - dst[i] = get(); + dst [i] = get (); } return this; } + /** + * This method transfers ints 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 + * ints remaining in this buffer. + */ public IntBuffer get (int[] dst) { - return get(dst, 0, dst.length); + return get (dst, 0, dst.length); } + /** + * Writes the content of the the IntBUFFER src + * into the buffer. + * + * @param src The source data. + * + * @exception BufferOverflowException If there is insufficient space in this + * buffer for the remaining ints in the source buffer. + * @exception IllegalArgumentException If the source buffer is this buffer. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ public IntBuffer put (IntBuffer src) { - while (src.hasRemaining()) - put(src.get()); + if (src == this) + throw new IllegalArgumentException (); + + if (src.remaining () > remaining ()) + throw new BufferOverflowException (); + + if (src.remaining () > 0) + { + int[] toPut = new int [src.remaining ()]; + src.get (toPut); + src.put (toPut); + } return this; } + /** + * Writes the content of the the int 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 ints 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) { for (int i = offset; i < offset + length; i++) - put(src[i]); + put (src [i]); return this; } - public final IntBuffer put(int[] src) + /** + * Writes the content of the the int 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 ints in the source array. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public final IntBuffer put (int[] src) { - return put(src, 0, src.length); + return put (src, 0, src.length); } - public final boolean hasArray() + /** + * Tells whether ot not this buffer is backed by an accessible + * int array. + */ + public final boolean hasArray () { return (backing_buffer != null && !isReadOnly ()); } - public final int[] array() + /** + * Returns the int array that backs this buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + * @exception UnsupportedOperationException If this buffer is not backed + * by an accessible array. + */ + public final int[] array () { if (backing_buffer == null) throw new UnsupportedOperationException (); @@ -136,7 +225,14 @@ public abstract class IntBuffer extends Buffer implements Comparable return backing_buffer; } - public final int arrayOffset() + /** + * Returns the offset within this buffer's backing array of the first element. + * + * @exception ReadOnlyBufferException If this buffer 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 (); @@ -147,41 +243,55 @@ public abstract class IntBuffer extends Buffer implements Comparable return array_offset; } - public int hashCode() + /** + * Calculates a hash code for this buffer. + */ + public int hashCode () { - return super.hashCode(); + // FIXME: Check what SUN calculates here. + return super.hashCode (); } - public boolean equals(Object obj) + /** + * Checks if this buffer is equal to obj. + */ + public boolean equals (Object obj) { if (obj instanceof IntBuffer) { - return compareTo(obj) == 0; + return compareTo (obj) == 0; } return false; } - public int compareTo(Object ob) + /** + * Compares two IntBuffer objects. + * + * @exception ClassCastException If obj is not an object derived from + * IntBuffer. + */ + public int compareTo (Object obj) { - IntBuffer a = (IntBuffer) ob; + IntBuffer a = (IntBuffer) obj; - if (a.remaining() != remaining()) + if (a.remaining () != remaining ()) return 1; - if (! hasArray() || - ! a.hasArray()) + if (! hasArray () || + ! a.hasArray ()) { return 1; } - int r = remaining(); + int r = remaining (); int i1 = position (); int i2 = a.position (); - for (int i=0;iint at this buffer's current position, + * and then increments the position. + * + * @exception BufferUnderflowException If there are no remaining + * ints in this buffer. + */ + public abstract int get (); + + /** + * Writes the int at this buffer's current position, + * and then increments the position. + * + * @exception BufferOverflowException If there no remaining + * ints in this buffer. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public abstract IntBuffer put (int b); + + /** + * Absolute get method. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + */ + public abstract int get (int index); + + /** + * Absolute put method. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public abstract IntBuffer put (int index, int b); + + /** + * Compacts this buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public abstract IntBuffer compact (); + + /** + * Tells wether or not this buffer is direct. + */ + public abstract boolean isDirect (); + + /** + * Creates a new IntBuffer whose content is a shared + * subsequence of this buffer's content. + */ + public abstract IntBuffer slice (); + + /** + * Creates a new IntBuffer that shares this buffer's + * content. + */ + public abstract IntBuffer duplicate (); + + /** + * Creates a new read-only IntBuffer that shares this + * buffer's content. + */ + public abstract IntBuffer asReadOnlyBuffer (); } diff --git a/libjava/java/nio/LongBuffer.java b/libjava/java/nio/LongBuffer.java index 35978544832..8808fd5f507 100644 --- a/libjava/java/nio/LongBuffer.java +++ b/libjava/java/nio/LongBuffer.java @@ -1,5 +1,5 @@ /* LongBuffer.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,93 +39,182 @@ package java.nio; import gnu.java.nio.LongBufferImpl; -public abstract class LongBuffer extends Buffer implements Comparable +/** + * @since 1.4 + */ +public abstract class LongBuffer extends Buffer + implements Comparable { int array_offset; long[] backing_buffer; - public static LongBuffer allocateDirect(int capacity) - { - throw new Error ("direct buffers not implemented"); - } - - public static LongBuffer allocate(int capacity) - { - return new LongBufferImpl(capacity, 0, capacity); - } - - final public static LongBuffer wrap(long[] array, int offset, int length) - { - return new LongBufferImpl (array, offset, length); - } - - final public static LongBuffer wrap(String a) - { - int len = a.length(); - long[] buffer = new long[len]; - - for (int i=0;iLongBuffer object with a given capacity. + */ + public static LongBuffer allocate (int capacity) + { + return new LongBufferImpl (capacity); + } + + /** + * Wraps a long array into a LongBuffer + * object. + * + * @exception IndexOutOfBoundsException If the preconditions on the offset + * and length parameters do not hold + */ + final public static LongBuffer wrap (long[] array, int offset, int length) + { + return new LongBufferImpl (array, 0, array.length, offset + length, offset, -1, false); + } + + /** + * Wraps a long array into a LongBuffer + * object. + */ + final public static LongBuffer wrap (long[] array) + { + return wrap (array, 0, array.length); + } + /** + * This method transfers longs from this buffer into the given + * destination array. + * + * @param dst The destination array + * @param offset The offset within the array of the first long + * to be written; must be non-negative and no larger than dst.length. + * @param length The maximum number of bytes to be written to the given array; + * must be non-negative and no larger than dst.length - offset. + * + * @exception BufferUnderflowException If there are fewer than length + * longs 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) { for (int i = offset; i < offset + length; i++) { - dst[i] = get(); + dst [i] = get (); } return this; } + /** + * This method transfers longs 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 + * longs remaining in this buffer. + */ public LongBuffer get (long[] dst) { - return get(dst, 0, dst.length); + return get (dst, 0, dst.length); } + /** + * Writes the content of the the LongBUFFER src + * into the buffer. + * + * @param src The source data. + * + * @exception BufferOverflowException If there is insufficient space in this + * buffer for the remaining longs in the source buffer. + * @exception IllegalArgumentException If the source buffer is this buffer. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ public LongBuffer put (LongBuffer src) { - while (src.hasRemaining()) - put(src.get()); + if (src == this) + throw new IllegalArgumentException (); + + if (src.remaining () > remaining ()) + throw new BufferOverflowException (); + + if (src.remaining () > 0) + { + long[] toPut = new long [src.remaining ()]; + src.get (toPut); + src.put (toPut); + } return this; } + /** + * Writes the content of the the long 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 longs 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) { for (int i = offset; i < offset + length; i++) - put(src[i]); + put (src [i]); return this; } - public final LongBuffer put(long[] src) + /** + * Writes the content of the the long 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 longs in the source array. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public final LongBuffer put (long[] src) { - return put(src, 0, src.length); + return put (src, 0, src.length); } - public final boolean hasArray() + /** + * Tells whether ot not this buffer is backed by an accessible + * long array. + */ + public final boolean hasArray () { return (backing_buffer != null && !isReadOnly ()); } - public final long[] array() + /** + * Returns the long array that backs this buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + * @exception UnsupportedOperationException If this buffer is not backed + * by an accessible array. + */ + public final long[] array () { if (backing_buffer == null) throw new UnsupportedOperationException (); @@ -136,7 +225,14 @@ public abstract class LongBuffer extends Buffer implements Comparable return backing_buffer; } - public final int arrayOffset() + /** + * Returns the offset within this buffer's backing array of the first element. + * + * @exception ReadOnlyBufferException If this buffer 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 (); @@ -147,41 +243,54 @@ public abstract class LongBuffer extends Buffer implements Comparable return array_offset; } - public int hashCode() + /** + * Calculates a hash code for this buffer. + */ + public int hashCode () { - return super.hashCode(); + // FIXME: Check what SUN calculates here. + return super.hashCode (); } - public boolean equals(Object obj) + /** + * Checks if this buffer is equal to obj. + */ + public boolean equals (Object obj) { if (obj instanceof LongBuffer) { - return compareTo(obj) == 0; + return compareTo (obj) == 0; } return false; } - public int compareTo(Object ob) + /** + * Compares two LongBuffer objects. + * + * @exception ClassCastException If obj is not an object derived from + * LongBuffer. + */ + public int compareTo (Object obj) { - LongBuffer a = (LongBuffer) ob; + LongBuffer a = (LongBuffer) obj; - if (a.remaining() != remaining()) + if (a.remaining () != remaining ()) return 1; - if (! hasArray() || - ! a.hasArray()) + if (! hasArray () || + ! a.hasArray ()) { return 1; } - int r = remaining(); + int r = remaining (); int i1 = position (); int i2 = a.position (); - for (int i=0;ilong at this buffer's current position, + * and then increments the position. + * + * @exception BufferUnderflowException If there are no remaining + * longs in this buffer. + */ + public abstract long get (); + + /** + * Writes the long at this buffer's current position, + * and then increments the position. + * + * @exception BufferOverflowException If there no remaining + * longs in this buffer. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public abstract LongBuffer put (long b); + + /** + * Absolute get method. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + */ + public abstract long get (int index); + + /** + * Absolute put method. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public abstract LongBuffer put (int index, long b); + + /** + * Compacts this buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public abstract LongBuffer compact (); + + /** + * Tells wether or not this buffer is direct. + */ + public abstract boolean isDirect (); + + /** + * Creates a new LongBuffer whose content is a shared + * subsequence of this buffer's content. + */ + public abstract LongBuffer slice (); + + /** + * Creates a new LongBuffer that shares this buffer's + * content. + */ + public abstract LongBuffer duplicate (); + + /** + * Creates a new read-only LongBuffer that shares this + * buffer's content. + */ + public abstract LongBuffer asReadOnlyBuffer (); } diff --git a/libjava/java/nio/ShortBuffer.java b/libjava/java/nio/ShortBuffer.java index 5e449f8308d..db14b483b66 100644 --- a/libjava/java/nio/ShortBuffer.java +++ b/libjava/java/nio/ShortBuffer.java @@ -1,5 +1,5 @@ /* ShortBuffer.java -- - Copyright (C) 2002 Free Software Foundation, Inc. + Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -39,93 +39,182 @@ package java.nio; import gnu.java.nio.ShortBufferImpl; -public abstract class ShortBuffer extends Buffer implements Comparable +/** + * @since 1.4 + */ +public abstract class ShortBuffer extends Buffer + implements Comparable { int array_offset; short[] backing_buffer; - public static ShortBuffer allocateDirect(int capacity) - { - throw new Error ("direct buffers not implemented"); - } - - public static ShortBuffer allocate(int capacity) - { - return new ShortBufferImpl(capacity, 0, capacity); - } - - final public static ShortBuffer wrap(short[] array, int offset, int length) - { - return new ShortBufferImpl(array, offset, length); - } - - final public static ShortBuffer wrap(String a) - { - int len = a.length(); - short[] buffer = new short[len]; - - for (int i=0;iShortBuffer object with a given capacity. + */ + public static ShortBuffer allocate (int capacity) + { + return new ShortBufferImpl (capacity); + } + + /** + * Wraps a short array into a ShortBuffer + * object. + * + * @exception IndexOutOfBoundsException If the preconditions on the offset + * and length parameters do not hold + */ + final public static ShortBuffer wrap (short[] array, int offset, int length) + { + return new ShortBufferImpl (array, 0, array.length, offset + length, offset, -1, false); + } + + /** + * Wraps a short array into a ShortBuffer + * object. + */ + final public static ShortBuffer wrap (short[] array) + { + return wrap (array, 0, array.length); + } + /** + * This method transfers shorts from this buffer into the given + * destination array. + * + * @param dst The destination array + * @param offset The offset within the array of the first short + * to be written; must be non-negative and no larger than dst.length. + * @param length The maximum number of bytes to be written to the given array; + * must be non-negative and no larger than dst.length - offset. + * + * @exception BufferUnderflowException If there are fewer than length + * shorts 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) { for (int i = offset; i < offset + length; i++) { - dst[i] = get(); + dst [i] = get (); } return this; } + /** + * This method transfers shorts 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 + * shorts remaining in this buffer. + */ public ShortBuffer get (short[] dst) { - return get(dst, 0, dst.length); + return get (dst, 0, dst.length); } + /** + * Writes the content of the the ShortBUFFER src + * into the buffer. + * + * @param src The source data. + * + * @exception BufferOverflowException If there is insufficient space in this + * buffer for the remaining shorts in the source buffer. + * @exception IllegalArgumentException If the source buffer is this buffer. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ public ShortBuffer put (ShortBuffer src) { - while (src.hasRemaining()) - put(src.get()); + if (src == this) + throw new IllegalArgumentException (); + + if (src.remaining () > remaining ()) + throw new BufferOverflowException (); + + if (src.remaining () > 0) + { + short[] toPut = new short [src.remaining ()]; + src.get (toPut); + src.put (toPut); + } return this; } + /** + * Writes the content of the the short 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 shorts 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) { for (int i = offset; i < offset + length; i++) - put(src[i]); + put (src [i]); return this; } - public final ShortBuffer put(short[] src) + /** + * Writes the content of the the short 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 shorts in the source array. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public final ShortBuffer put (short[] src) { - return put(src, 0, src.length); + return put (src, 0, src.length); } - public final boolean hasArray() + /** + * Tells whether ot not this buffer is backed by an accessible + * short array. + */ + public final boolean hasArray () { return (backing_buffer != null && !isReadOnly ()); } - public final short[] array() + /** + * Returns the short array that backs this buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + * @exception UnsupportedOperationException If this buffer is not backed + * by an accessible array. + */ + public final short[] array () { if (backing_buffer == null) throw new UnsupportedOperationException (); @@ -136,7 +225,14 @@ public abstract class ShortBuffer extends Buffer implements Comparable return backing_buffer; } - public final int arrayOffset() + /** + * Returns the offset within this buffer's backing array of the first element. + * + * @exception ReadOnlyBufferException If this buffer 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 (); @@ -147,41 +243,54 @@ public abstract class ShortBuffer extends Buffer implements Comparable return array_offset; } - public int hashCode() + /** + * Calculates a hash code for this buffer. + */ + public int hashCode () { - return super.hashCode(); + // FIXME: Check what SUN calculates here. + return super.hashCode (); } - public boolean equals(Object obj) + /** + * Checks if this buffer is equal to obj. + */ + public boolean equals (Object obj) { if (obj instanceof ShortBuffer) { - return compareTo(obj) == 0; + return compareTo (obj) == 0; } return false; } - public int compareTo(Object ob) + /** + * Compares two ShortBuffer objects. + * + * @exception ClassCastException If obj is not an object derived from + * ShortBuffer. + */ + public int compareTo (Object obj) { - ShortBuffer a = (ShortBuffer) ob; + ShortBuffer a = (ShortBuffer) obj; - if (a.remaining() != remaining()) + if (a.remaining () != remaining ()) return 1; - if (! hasArray() || - ! a.hasArray()) + if (! hasArray () || + ! a.hasArray ()) { return 1; } - int r = remaining(); + int r = remaining (); int i1 = position (); int i2 = a.position (); - for (int i=0;ishort at this buffer's current position, + * and then increments the position. + * + * @exception BufferUnderflowException If there are no remaining + * shorts in this buffer. + */ + public abstract short get (); + + /** + * Writes the short at this buffer's current position, + * and then increments the position. + * + * @exception BufferOverflowException If there no remaining + * shorts in this buffer. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public abstract ShortBuffer put (short b); + + /** + * Absolute get method. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + */ + public abstract short get (int index); + + /** + * Absolute put method. + * + * @exception IndexOutOfBoundsException If index is negative or not smaller + * than the buffer's limit. + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public abstract ShortBuffer put (int index, short b); + + /** + * Compacts this buffer. + * + * @exception ReadOnlyBufferException If this buffer is read-only. + */ + public abstract ShortBuffer compact (); + + /** + * Tells wether or not this buffer is direct. + */ + public abstract boolean isDirect (); + + /** + * Creates a new ShortBuffer whose content is a shared + * subsequence of this buffer's content. + */ + public abstract ShortBuffer slice (); + + /** + * Creates a new ShortBuffer that shares this buffer's + * content. + */ + public abstract ShortBuffer duplicate (); + + /** + * Creates a new read-only ShortBuffer that shares this + * buffer's content. + */ + public abstract ShortBuffer asReadOnlyBuffer (); }