OSDN Git Service

2003-05-12 Michael Koch <konqueror@gmx.de>
authormkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 12 May 2003 20:45:20 +0000 (20:45 +0000)
committermkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 12 May 2003 20:45:20 +0000 (20:45 +0000)
* 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.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@66733 138bc75d-0d04-0410-961f-82ee72b054a4

19 files changed:
libjava/ChangeLog
libjava/Makefile.am
libjava/Makefile.in
libjava/gnu/java/nio/ByteBufferImpl.java
libjava/gnu/java/nio/CharBufferImpl.java
libjava/gnu/java/nio/DirectByteBufferImpl.java
libjava/gnu/java/nio/DoubleBufferImpl.java
libjava/gnu/java/nio/FloatBufferImpl.java
libjava/gnu/java/nio/IntBufferImpl.java
libjava/gnu/java/nio/LongBufferImpl.java
libjava/gnu/java/nio/ShortBufferImpl.java
libjava/gnu/java/nio/natByteBufferImpl.cc [deleted file]
libjava/gnu/java/nio/natCharBufferImpl.cc [deleted file]
libjava/java/nio/CharBuffer.java
libjava/java/nio/DoubleBuffer.java
libjava/java/nio/FloatBuffer.java
libjava/java/nio/IntBuffer.java
libjava/java/nio/LongBuffer.java
libjava/java/nio/ShortBuffer.java

index 584defb..0aed874 100644 (file)
@@ -1,5 +1,104 @@
 2003-05-12  Michael Koch  <konqueror@gmx.de>
 
+       * 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  <konqueror@gmx.de>
+
        * gnu/java/nio/CharViewBufferImpl.java,
        gnu/java/nio/DirectByteBufferImpl.java,
        gnu/java/nio/DoubleViewBufferImpl.java,
index 7185881..e745528 100644 (file)
@@ -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 \
index cbe0cc0..6aa88cc 100644 (file)
@@ -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 \
index ede16aa..7b7f72e 100644 (file)
@@ -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 <code>byte</code> 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 <code>value</code> 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 <code>byte</code> at position
+   * <code>index</code>.
+   *
+   * @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 <code>value</value> to position
+   * <code>index</code> 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;
   }
 }
index ca76974..fcf0e15 100644 (file)
@@ -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 <code>char</code> 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 <code>index</code>.
+   * Absolute get method. Reads the <code>char</code> at position
+   * <code>index</code>.
    *
    * @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 ();
   }
 }
index 0c08ab4..47b76bb 100644 (file)
@@ -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);
index 7d4f693..dc80959 100644 (file)
@@ -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)
+
+  DoubleBufferImpl (int capacity)
   {
-    super (cap, lim, off, 0);
-    this.backing_buffer = new double[cap];
-    readOnly = false;
+    this (new double [capacity], 0, capacity, capacity, 0, -1, false);
   }
   
-  public DoubleBufferImpl(double[] array, int offset, int length)
+  DoubleBufferImpl (double[] 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 DoubleBufferImpl(DoubleBufferImpl 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 ()
   {
     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 <code>double</code> 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 <code>value</code> 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 <code>double</code> at position
+   * <code>index</code>.
+   *
+   * @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 <code>value</value> to position
+   * <code>index</code> 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 ();
   }
 }
index 4acde80..69acecf 100644 (file)
@@ -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)
-  {
-    super (cap, lim, off, 0);
-    this.backing_buffer = new float [cap];
-    readOnly = false;
-  }
-  
-  public FloatBufferImpl(float[] array, int offset, int length)
+
+  FloatBufferImpl (int capacity)
   {
-    super (array.length, length, offset, 0);
-    this.backing_buffer = array;
-    readOnly = false;
+    this (new float [capacity], 0, capacity, capacity, 0, -1, false);
   }
   
-  public FloatBufferImpl(FloatBufferImpl copy)
+  FloatBufferImpl (float[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly)
   {
-    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 <code>float</code> 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 <code>value</code> 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 <code>float</code> at position
+   * <code>index</code>.
+   *
+   * @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 <code>value</value> to position
+   * <code>index</code> 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 ();
   }
 }
index cfa3efe..573e5e0 100644 (file)
@@ -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;
-  
-  public IntBufferImpl(int cap, int off, int lim)
-  {
-    super (cap, lim, off, 0);
-    this.backing_buffer = new int[cap];
-    readOnly = false;
-  }
 
-  public IntBufferImpl(int[] array, int offset, int length)
+  IntBufferImpl (int capacity)
   {
-    super (array.length, length, offset, 0);
-    this.backing_buffer = array;
-    readOnly = false;
+    this (new int [capacity], 0, capacity, capacity, 0, -1, false);
   }
-
-  public IntBufferImpl(IntBufferImpl copy)
+  
+  IntBufferImpl (int[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly)
   {
-    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()
+  
+  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 <code>int</code> 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 <code>value</code> 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 <code>int</code> at position
+   * <code>index</code>.
+   *
+   * @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 <code>value</value> to position
+   * <code>index</code> 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 ();
   }
 }
index 8a295fa..e37ac8e 100644 (file)
@@ -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)
-  {
-    super (cap, lim, off, 0);
-    this.backing_buffer = new long[cap];
-    readOnly = false;
-  }
-
-  public LongBufferImpl(long[] array, int offset, int length)
+  LongBufferImpl (int capacity)
   {
-    super (array.length, length, offset, 0);
-    this.backing_buffer = array;
-    readOnly = false;
+    this (new long [capacity], 0, capacity, capacity, 0, -1, false);
   }
-
-  public LongBufferImpl(LongBufferImpl copy)
+  
+  LongBufferImpl (long[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly)
   {
-    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()
+  
+  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 <code>long</code> 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 <code>value</code> 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 <code>long</code> at position
+   * <code>index</code>.
+   *
+   * @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 <code>value</value> to position
+   * <code>index</code> 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 ();
   }
 }
index c4f679b..3dc625e 100644 (file)
@@ -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)
-  {
-    super (cap, lim, off, 0);
-    this.backing_buffer = new short [cap];
-    readOnly = false;
-  }
-
-  public ShortBufferImpl(short[] array, int offset, int length)
+  ShortBufferImpl (int capacity)
   {
-    super (array.length, length, offset, 0);
-    this.backing_buffer = array;
-    readOnly = false;
+    this (new short [capacity], 0, capacity, capacity, 0, -1, false);
   }
-
-  public ShortBufferImpl(ShortBufferImpl copy)
+  
+  ShortBufferImpl (short[] buffer, int offset, int capacity, int limit, int position, int mark, boolean readOnly)
   {
-    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()
+  
+  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 <code>short</code> 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 <code>value</code> 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 <code>short</code> at position
+   * <code>index</code>.
+   *
+   * @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 <code>value</value> to position
+   * <code>index</code> 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 (file)
index c6ba456..0000000
+++ /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 <config.h>
-
-#include <gcj/cni.h>
-#include <jvm.h>
-
-#include <gnu/java/nio/ByteBufferImpl.h>
-
-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 (file)
index eb72927..0000000
+++ /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 <config.h>
-
-#include <gcj/cni.h>
-#include <jvm.h>
-
-#include <gnu/java/nio/CharBufferImpl.h>
-
-JArray<jchar>*
-gnu::java::nio::CharBufferImpl::nio_cast(JArray<jbyte>*)
-{
-  return NULL;
-}
index 2158af0..fbee6df 100644 (file)
@@ -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 <code>CharBuffer</code> 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 <code>CharBuffer</code> object.
-   * 
+   * Wraps a <code>char</code> array into a <code>CharBuffer</code>
+   * 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 <code>CharBuffer</code> object.
+   * Wraps a <code>char</code> array into a <code>CharBuffer</code>
+   * 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 <code>chars<code> from this buffer into the given
+   * destination array.
+   *
+   * @param dst The destination array
+   * @param offset The offset within the array of the first <code>char</code>
+   * 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
+   * <code>chars</code> 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 <code>chars<code> from this buffer into the given
+   * destination array.
+   *
+   * @param dst The byte array to write into.
+   *
+   * @exception BufferUnderflowException If there are fewer than dst.length
+   * <code>chars</code> remaining in this buffer.
    */
   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 <code>CharBUFFER</code> src
+   * into the buffer.
+   *
+   * @param src The source data.
+   *
+   * @exception BufferOverflowException If there is insufficient space in this
+   * buffer for the remaining <code>chars<code> in the source buffer.
    * @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 <code>char array</code> 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 <code>chars<code> 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 <code>char array</code> 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 <code>chars<code> 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
+   * <code>char</code> array.
    */
   public final boolean hasArray ()
   {
     return (backing_buffer != null
-            && ! isReadOnly ());
+            && !isReadOnly ());
   }
 
   /**
-   * Returns the array that backs this buffer.
-   * 
+   * Returns the <code>char</code> 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 <code>CharBuffer</code> objects.
+   *
    * @exception ClassCastException If obj is not an object derived from
    * <code>CharBuffer</code>.
    */
-  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 <code>char</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferUnderflowException If there are no remaining
+   * <code>chars</code> in this buffer.
    */
   public abstract char get ();
-  
+
   /**
-   * Relative put method.
-   * 
-   * @exception BufferOverflowException If there no remaining characters in
-   * this buffer.
+   * Writes the <code>char</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferOverflowException If there no remaining 
+   * <code>chars</code> 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 ();
-  
+
+  /**
+   * Creates a new <code>CharBuffer</code> whose content is a shared
+   * subsequence of this buffer's content.
+   */
   public abstract CharBuffer slice ();
-  
+
   /**
-   * Duplicates this buffer.
+   * Creates a new <code>CharBuffer</code> that shares this buffer's
+   * content.
    */
   public abstract CharBuffer duplicate ();
-  
+
   /**
-   * Returns this buffer made read-only.
+   * Creates a new read-only <code>CharBuffer</code> that shares this
+   * buffer's content.
    */
   public abstract CharBuffer asReadOnlyBuffer ();
   
@@ -378,11 +439,6 @@ public abstract class CharBuffer extends Buffer
   }
 
   /**
-   * 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.
    *
index ef39ac1..f212566 100644 (file)
@@ -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)
+  DoubleBuffer (int capacity, int limit, int position, int mark)
   {
-    return new DoubleBufferImpl(capacity, 0, capacity);
+    super (capacity, limit, position, mark);
+    array_offset = 0;
   }
 
-  final public static DoubleBuffer wrap (double[] array, int offset, int length)
+  DoubleBuffer (double[] buffer, int offset, int capacity, int limit, int position, int mark)
   {
-    return new DoubleBufferImpl(array, offset, length);
+    super (capacity, limit, position, mark);
+    this.backing_buffer = buffer;
+    this.array_offset = offset;
   }
 
-  final public static DoubleBuffer wrap(String a)
+  /**
+   * Allocates a new <code>DoubleBuffer</code> object with a given capacity.
+   */
+  public static DoubleBuffer allocate (int capacity)
   {
-    int len = a.length();
-    double[] buffer = new double[len];
-
-    for (int i=0;i<len;i++)
-      {
-        buffer[i] = (double) a.charAt(i);
-      }
-
-    return wrap(buffer, 0, len);
+    return new DoubleBufferImpl (capacity);
   }
 
-  final public static DoubleBuffer wrap(double[] array)
+  /**
+   * Wraps a <code>double</code> array into a <code>DoubleBuffer</code>
+   * 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 wrap(array, 0, array.length);
+    return new DoubleBufferImpl (array, 0, array.length, offset + length, offset, -1, false);
   }
 
-  DoubleBuffer (int capacity, int limit, int position, int mark)
+  /**
+   * Wraps a <code>double</code> array into a <code>DoubleBuffer</code>
+   * object.
+   */
+  final public static DoubleBuffer wrap (double[] array)
   {
-    super (capacity, limit, position, mark);
+    return wrap (array, 0, array.length);
   }
   
+  /**
+   * This method transfers <code>doubles<code> from this buffer into the given
+   * destination array.
+   *
+   * @param dst The destination array
+   * @param offset The offset within the array of the first <code>double</code>
+   * 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
+   * <code>doubles</code> 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 <code>doubles<code> from this buffer into the given
+   * destination array.
+   *
+   * @param dst The byte array to write into.
+   *
+   * @exception BufferUnderflowException If there are fewer than dst.length
+   * <code>doubles</code> remaining in this buffer.
+   */
   public DoubleBuffer get (double[] dst)
   {
-    return get(dst, 0, dst.length);
+    return get (dst, 0, dst.length);
   }
 
+  /**
+   * Writes the content of the the <code>DoubleBUFFER</code> src
+   * into the buffer.
+   *
+   * @param src The source data.
+   *
+   * @exception BufferOverflowException If there is insufficient space in this
+   * buffer for the remaining <code>doubles<code> in the source buffer.
+   * @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 <code>double array</code> 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 <code>doubles<code> 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 <code>double array</code> 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 <code>doubles<code> 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
+   * <code>double</code> array.
+   */
+  public final boolean hasArray ()
   {
     return (backing_buffer != null
             && !isReadOnly ());
   }
 
-  public final double[] array()
+  /**
+   * Returns the <code>double</code> 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 <code>DoubleBuffer</code> objects.
+   *
+   * @exception ClassCastException If obj is not an object derived from
+   * <code>DoubleBuffer</code>.
+   */
+  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;i<r;i++)
+    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;
@@ -190,14 +301,74 @@ public abstract class DoubleBuffer extends Buffer implements Comparable
     return 0;
   }
 
+  /**
+   * Returns the byte order of this buffer.
+   */
   public abstract ByteOrder order ();
-  public abstract double get();
+
+  /**
+   * Reads the <code>double</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferUnderflowException If there are no remaining
+   * <code>doubles</code> in this buffer.
+   */
+  public abstract double get ();
+
+  /**
+   * Writes the <code>double</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferOverflowException If there no remaining 
+   * <code>doubles</code> 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 <code>DoubleBuffer</code> whose content is a shared
+   * subsequence of this buffer's content.
+   */
+  public abstract DoubleBuffer slice ();
+
+  /**
+   * Creates a new <code>DoubleBuffer</code> that shares this buffer's
+   * content.
+   */
+  public abstract DoubleBuffer duplicate ();
+
+  /**
+   * Creates a new read-only <code>DoubleBuffer</code> that shares this
+   * buffer's content.
+   */
+  public abstract DoubleBuffer asReadOnlyBuffer ();
 }
index 81feb45..65d680b 100644 (file)
@@ -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)
+  FloatBuffer (int capacity, int limit, int position, int mark)
   {
-    throw new Error ("direct buffers not implemented");
+    super (capacity, limit, position, mark);
+    array_offset = 0;
   }
 
-  public static FloatBuffer allocate(int capacity)
+  FloatBuffer (float[] buffer, int offset, int capacity, int limit, int position, int mark)
   {
-    return new FloatBufferImpl (capacity, 0, capacity);
+    super (capacity, limit, position, mark);
+    this.backing_buffer = buffer;
+    this.array_offset = offset;
   }
 
-  final public static FloatBuffer wrap(float[] array, int offset, int length)
+  /**
+   * Allocates a new <code>FloatBuffer</code> object with a given capacity.
+   */
+  public static FloatBuffer allocate (int capacity)
   {
-    return new FloatBufferImpl(array, offset, length);
+    return new FloatBufferImpl (capacity);
   }
 
-  final public static FloatBuffer wrap(String a)
+  /**
+   * Wraps a <code>float</code> array into a <code>FloatBuffer</code>
+   * 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)
   {
-    int len = a.length();
-    float[] buffer = new float[len];
-
-    for (int i=0;i<len;i++)
-      {
-        buffer[i] = (float) a.charAt(i);
-      }
-
-    return wrap(buffer, 0, len);
+    return new FloatBufferImpl (array, 0, array.length, offset + length, offset, -1, false);
   }
 
-  final public static FloatBuffer wrap(float[] array)
+  /**
+   * Wraps a <code>float</code> array into a <code>FloatBuffer</code>
+   * object.
+   */
+  final public static FloatBuffer wrap (float[] array)
   {
-    return wrap(array, 0, array.length);
-  }
-
-  FloatBuffer (int capacity, int limit, int position, int mark)
-  {
-    super (capacity, limit, position, mark);
-    array_offset = 0;                    
+    return wrap (array, 0, array.length);
   }
   
+  /**
+   * This method transfers <code>floats<code> from this buffer into the given
+   * destination array.
+   *
+   * @param dst The destination array
+   * @param offset The offset within the array of the first <code>float</code>
+   * 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
+   * <code>floats</code> 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 <code>floats<code> from this buffer into the given
+   * destination array.
+   *
+   * @param dst The byte array to write into.
+   *
+   * @exception BufferUnderflowException If there are fewer than dst.length
+   * <code>floats</code> remaining in this buffer.
+   */
   public FloatBuffer get (float[] dst)
   {
-    return get(dst, 0, dst.length);
+    return get (dst, 0, dst.length);
   }
 
+  /**
+   * Writes the content of the the <code>FloatBUFFER</code> src
+   * into the buffer.
+   *
+   * @param src The source data.
+   *
+   * @exception BufferOverflowException If there is insufficient space in this
+   * buffer for the remaining <code>floats<code> in the source buffer.
+   * @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 <code>float array</code> 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 <code>floats<code> 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 <code>float array</code> 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 <code>floats<code> 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
+   * <code>float</code> array.
+   */
+  public final boolean hasArray ()
   {
     return (backing_buffer != null
             && !isReadOnly ());
   }
 
-  public final float[] array()
+  /**
+   * Returns the <code>float</code> 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 <code>FloatBuffer</code> objects.
+   *
+   * @exception ClassCastException If obj is not an object derived from
+   * <code>FloatBuffer</code>.
+   */
+  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;i<r;i++)
+    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;
@@ -191,14 +301,74 @@ public abstract class FloatBuffer extends Buffer implements Comparable
     return 0;
   }
 
+  /**
+   * Returns the byte order of this buffer.
+   */
   public abstract ByteOrder order ();
-  public abstract float get();
-  public abstract java.nio. FloatBuffer put(float b);
-  public abstract float get(int index);
-  public abstract java.nio. FloatBuffer put(int index, float b);
-  public abstract FloatBuffer compact();
-  public abstract boolean isDirect();
-  public abstract FloatBuffer slice();
-  public abstract FloatBuffer duplicate();
-  public abstract FloatBuffer asReadOnlyBuffer();
+
+  /**
+   * Reads the <code>float</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferUnderflowException If there are no remaining
+   * <code>floats</code> in this buffer.
+   */
+  public abstract float get ();
+
+  /**
+   * Writes the <code>float</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferOverflowException If there no remaining 
+   * <code>floats</code> 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 <code>FloatBuffer</code> whose content is a shared
+   * subsequence of this buffer's content.
+   */
+  public abstract FloatBuffer slice ();
+
+  /**
+   * Creates a new <code>FloatBuffer</code> that shares this buffer's
+   * content.
+   */
+  public abstract FloatBuffer duplicate ();
+
+  /**
+   * Creates a new read-only <code>FloatBuffer</code> that shares this
+   * buffer's content.
+   */
+  public abstract FloatBuffer asReadOnlyBuffer ();
 }
index 295ad6a..c8e0d0f 100644 (file)
@@ -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)
+  IntBuffer (int capacity, int limit, int position, int mark)
   {
-    return new IntBufferImpl (capacity, 0, capacity);
+    super (capacity, limit, position, mark);
+    array_offset = 0;
   }
 
-  final public static IntBuffer wrap(int[] array, int offset, int length)
+  IntBuffer (int[] buffer, int offset, int capacity, int limit, int position, int mark)
   {
-    return new IntBufferImpl(array, offset, length);
+    super (capacity, limit, position, mark);
+    this.backing_buffer = buffer;
+    this.array_offset = offset;
   }
 
-  final public static IntBuffer wrap(String a)
+  /**
+   * Allocates a new <code>IntBuffer</code> object with a given capacity.
+   */
+  public static IntBuffer allocate (int capacity)
   {
-    int len = a.length();
-    int[] buffer = new int[len];
-
-    for (int i=0;i<len;i++)
-      {
-        buffer[i] = (int) a.charAt(i);
-      }
-
-    return wrap(buffer, 0, len);
+    return new IntBufferImpl (capacity);
   }
 
-  final public static IntBuffer wrap(int[] array)
+  /**
+   * Wraps a <code>int</code> array into a <code>IntBuffer</code>
+   * 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 wrap(array, 0, array.length);
+    return new IntBufferImpl (array, 0, array.length, offset + length, offset, -1, false);
   }
 
-  IntBuffer (int capacity, int limit, int position, int mark)
+  /**
+   * Wraps a <code>int</code> array into a <code>IntBuffer</code>
+   * object.
+   */
+  final public static IntBuffer wrap (int[] array)
   {
-    super (capacity, limit, position, mark);
-    array_offset = 0;
+    return wrap (array, 0, array.length);
   }
   
-  public IntBuffer get(int[] dst, int offset, int length)
+  /**
+   * This method transfers <code>ints<code> from this buffer into the given
+   * destination array.
+   *
+   * @param dst The destination array
+   * @param offset The offset within the array of the first <code>int</code>
+   * 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
+   * <code>ints</code> 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 <code>ints<code> from this buffer into the given
+   * destination array.
+   *
+   * @param dst The byte array to write into.
+   *
+   * @exception BufferUnderflowException If there are fewer than dst.length
+   * <code>ints</code> remaining in this buffer.
+   */
   public IntBuffer get (int[] dst)
   {
-    return get(dst, 0, dst.length);
+    return get (dst, 0, dst.length);
   }
 
+  /**
+   * Writes the content of the the <code>IntBUFFER</code> src
+   * into the buffer.
+   *
+   * @param src The source data.
+   *
+   * @exception BufferOverflowException If there is insufficient space in this
+   * buffer for the remaining <code>ints<code> in the source buffer.
+   * @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 <code>int array</code> 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 <code>ints<code> 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 <code>int array</code> 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 <code>ints<code> 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
+   * <code>int</code> array.
+   */
+  public final boolean hasArray ()
   {
     return (backing_buffer != null
             && !isReadOnly ());
   }
 
-  public final int[] array()
+  /**
+   * Returns the <code>int</code> 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 <code>IntBuffer</code> objects.
+   *
+   * @exception ClassCastException If obj is not an object derived from
+   * <code>IntBuffer</code>.
+   */
+  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;i<r;i++)
+    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;
@@ -191,14 +301,74 @@ public abstract class IntBuffer extends Buffer implements Comparable
     return 0;
   }
 
-  public abstract ByteOrder order();
-  public abstract int get();
-  public abstract IntBuffer put(int b);
-  public abstract int get(int index);
-  public abstract IntBuffer put(int index, int b);
-  public abstract IntBuffer compact();
-  public abstract boolean isDirect();
-  public abstract IntBuffer slice();
-  public abstract IntBuffer duplicate();
-  public abstract IntBuffer asReadOnlyBuffer();
+  /**
+   * Returns the byte order of this buffer.
+   */
+  public abstract ByteOrder order ();
+
+  /**
+   * Reads the <code>int</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferUnderflowException If there are no remaining
+   * <code>ints</code> in this buffer.
+   */
+  public abstract int get ();
+
+  /**
+   * Writes the <code>int</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferOverflowException If there no remaining 
+   * <code>ints</code> 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 <code>IntBuffer</code> whose content is a shared
+   * subsequence of this buffer's content.
+   */
+  public abstract IntBuffer slice ();
+
+  /**
+   * Creates a new <code>IntBuffer</code> that shares this buffer's
+   * content.
+   */
+  public abstract IntBuffer duplicate ();
+
+  /**
+   * Creates a new read-only <code>IntBuffer</code> that shares this
+   * buffer's content.
+   */
+  public abstract IntBuffer asReadOnlyBuffer ();
 }
index 3597854..8808fd5 100644 (file)
@@ -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)
+  LongBuffer (int capacity, int limit, int position, int mark)
   {
-    throw new Error ("direct buffers not implemented");
+    super (capacity, limit, position, mark);
+    array_offset = 0;
   }
 
-  public static LongBuffer allocate(int capacity)
+  LongBuffer (long[] buffer, int offset, int capacity, int limit, int position, int mark)
   {
-    return new LongBufferImpl(capacity, 0, capacity);
+    super (capacity, limit, position, mark);
+    this.backing_buffer = buffer;
+    this.array_offset = offset;
   }
 
-  final public static LongBuffer wrap(long[] array, int offset, int length)
+  /**
+   * Allocates a new <code>LongBuffer</code> object with a given capacity.
+   */
+  public static LongBuffer allocate (int capacity)
   {
-    return new LongBufferImpl (array, offset, length);
+    return new LongBufferImpl (capacity);
   }
 
-  final public static LongBuffer wrap(String a)
+  /**
+   * Wraps a <code>long</code> array into a <code>LongBuffer</code>
+   * 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)
   {
-    int len = a.length();
-    long[] buffer = new long[len];
-
-    for (int i=0;i<len;i++)
-      {
-        buffer[i] = (long) a.charAt(i);
-      }
-
-    return wrap(buffer, 0, len);
+    return new LongBufferImpl (array, 0, array.length, offset + length, offset, -1, false);
   }
 
-  final public static LongBuffer wrap(long[] array)
+  /**
+   * Wraps a <code>long</code> array into a <code>LongBuffer</code>
+   * object.
+   */
+  final public static LongBuffer wrap (long[] array)
   {
-    return wrap(array, 0, array.length);
-  }
-
-  LongBuffer (int capacity, int limit, int position, int mark)
-  {
-    super (capacity, limit, position, mark);
-    array_offset = 0;
+    return wrap (array, 0, array.length);
   }
   
+  /**
+   * This method transfers <code>longs<code> from this buffer into the given
+   * destination array.
+   *
+   * @param dst The destination array
+   * @param offset The offset within the array of the first <code>long</code>
+   * 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
+   * <code>longs</code> 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 <code>longs<code> from this buffer into the given
+   * destination array.
+   *
+   * @param dst The byte array to write into.
+   *
+   * @exception BufferUnderflowException If there are fewer than dst.length
+   * <code>longs</code> remaining in this buffer.
+   */
   public LongBuffer get (long[] dst)
   {
-    return get(dst, 0, dst.length);
+    return get (dst, 0, dst.length);
   }
 
+  /**
+   * Writes the content of the the <code>LongBUFFER</code> src
+   * into the buffer.
+   *
+   * @param src The source data.
+   *
+   * @exception BufferOverflowException If there is insufficient space in this
+   * buffer for the remaining <code>longs<code> in the source buffer.
+   * @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 <code>long array</code> 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 <code>longs<code> 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 <code>long array</code> 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 <code>longs<code> 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
+   * <code>long</code> array.
+   */
+  public final boolean hasArray ()
   {
     return (backing_buffer != null
             && !isReadOnly ());
   }
 
-  public final long[] array()
+  /**
+   * Returns the <code>long</code> 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 <code>LongBuffer</code> objects.
+   *
+   * @exception ClassCastException If obj is not an object derived from
+   * <code>LongBuffer</code>.
+   */
+  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;i<r;i++)
+    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)
           {
@@ -192,14 +301,74 @@ public abstract class LongBuffer extends Buffer implements Comparable
     return 0;
   }
 
-  public abstract ByteOrder order();
-  public abstract long get();
-  public abstract java.nio. LongBuffer put(long b);
-  public abstract long get(int index);
-  public abstract java.nio. LongBuffer put(int index, long b);
-  public abstract LongBuffer compact();
-  public abstract boolean isDirect();
-  public abstract LongBuffer slice();
-  public abstract LongBuffer duplicate();
-  public abstract LongBuffer asReadOnlyBuffer();
+  /**
+   * Returns the byte order of this buffer.
+   */
+  public abstract ByteOrder order ();
+
+  /**
+   * Reads the <code>long</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferUnderflowException If there are no remaining
+   * <code>longs</code> in this buffer.
+   */
+  public abstract long get ();
+
+  /**
+   * Writes the <code>long</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferOverflowException If there no remaining 
+   * <code>longs</code> 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 <code>LongBuffer</code> whose content is a shared
+   * subsequence of this buffer's content.
+   */
+  public abstract LongBuffer slice ();
+
+  /**
+   * Creates a new <code>LongBuffer</code> that shares this buffer's
+   * content.
+   */
+  public abstract LongBuffer duplicate ();
+
+  /**
+   * Creates a new read-only <code>LongBuffer</code> that shares this
+   * buffer's content.
+   */
+  public abstract LongBuffer asReadOnlyBuffer ();
 }
index 5e449f8..db14b48 100644 (file)
@@ -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)
+  ShortBuffer (int capacity, int limit, int position, int mark)
   {
-    return new ShortBufferImpl(capacity, 0, capacity);
+    super (capacity, limit, position, mark);
+    array_offset = 0;
   }
 
-  final public static ShortBuffer wrap(short[] array, int offset, int length)
+  ShortBuffer (short[] buffer, int offset, int capacity, int limit, int position, int mark)
   {
-    return new ShortBufferImpl(array, offset, length);
+    super (capacity, limit, position, mark);
+    this.backing_buffer = buffer;
+    this.array_offset = offset;
   }
 
-  final public static ShortBuffer wrap(String a)
+  /**
+   * Allocates a new <code>ShortBuffer</code> object with a given capacity.
+   */
+  public static ShortBuffer allocate (int capacity)
   {
-    int len = a.length();
-    short[] buffer = new short[len];
-
-    for (int i=0;i<len;i++)
-      {
-        buffer[i] = (short) a.charAt(i);
-      }
-
-    return wrap(buffer, 0, len);
+    return new ShortBufferImpl (capacity);
   }
 
-  final public static ShortBuffer wrap(short[] array)
+  /**
+   * Wraps a <code>short</code> array into a <code>ShortBuffer</code>
+   * 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 wrap(array, 0, array.length);
+    return new ShortBufferImpl (array, 0, array.length, offset + length, offset, -1, false);
   }
 
-  ShortBuffer (int capacity, int limit, int position, int mark)
+  /**
+   * Wraps a <code>short</code> array into a <code>ShortBuffer</code>
+   * object.
+   */
+  final public static ShortBuffer wrap (short[] array)
   {
-    super (capacity, limit, position, mark);
-    array_offset = 0;
+    return wrap (array, 0, array.length);
   }
   
+  /**
+   * This method transfers <code>shorts<code> from this buffer into the given
+   * destination array.
+   *
+   * @param dst The destination array
+   * @param offset The offset within the array of the first <code>short</code>
+   * 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
+   * <code>shorts</code> 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 <code>shorts<code> from this buffer into the given
+   * destination array.
+   *
+   * @param dst The byte array to write into.
+   *
+   * @exception BufferUnderflowException If there are fewer than dst.length
+   * <code>shorts</code> remaining in this buffer.
+   */
   public ShortBuffer get (short[] dst)
   {
-    return get(dst, 0, dst.length);
+    return get (dst, 0, dst.length);
   }
 
+  /**
+   * Writes the content of the the <code>ShortBUFFER</code> src
+   * into the buffer.
+   *
+   * @param src The source data.
+   *
+   * @exception BufferOverflowException If there is insufficient space in this
+   * buffer for the remaining <code>shorts<code> in the source buffer.
+   * @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 <code>short array</code> 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 <code>shorts<code> 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 <code>short array</code> 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 <code>shorts<code> 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
+   * <code>short</code> array.
+   */
+  public final boolean hasArray ()
   {
     return (backing_buffer != null
             && !isReadOnly ());
   }
 
-  public final short[] array()
+  /**
+   * Returns the <code>short</code> 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 <code>ShortBuffer</code> objects.
+   *
+   * @exception ClassCastException If obj is not an object derived from
+   * <code>ShortBuffer</code>.
+   */
+  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;i<r;i++)
+    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)
           {
@@ -192,14 +301,74 @@ public abstract class ShortBuffer extends Buffer implements Comparable
     return 0;
   }
 
+  /**
+   * Returns the byte order of this buffer.
+   */
   public abstract ByteOrder order ();
-  public abstract short get();
-  public abstract java.nio. ShortBuffer put(short b);
-  public abstract short get(int index);
-  public abstract java.nio. ShortBuffer put(int index, short b);
-  public abstract ShortBuffer compact();
-  public abstract boolean isDirect();
-  public abstract ShortBuffer slice();
-  public abstract ShortBuffer duplicate();
-  public abstract ShortBuffer asReadOnlyBuffer();
+
+  /**
+   * Reads the <code>short</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferUnderflowException If there are no remaining
+   * <code>shorts</code> in this buffer.
+   */
+  public abstract short get ();
+
+  /**
+   * Writes the <code>short</code> at this buffer's current position,
+   * and then increments the position.
+   *
+   * @exception BufferOverflowException If there no remaining 
+   * <code>shorts</code> 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 <code>ShortBuffer</code> whose content is a shared
+   * subsequence of this buffer's content.
+   */
+  public abstract ShortBuffer slice ();
+
+  /**
+   * Creates a new <code>ShortBuffer</code> that shares this buffer's
+   * content.
+   */
+  public abstract ShortBuffer duplicate ();
+
+  /**
+   * Creates a new read-only <code>ShortBuffer</code> that shares this
+   * buffer's content.
+   */
+  public abstract ShortBuffer asReadOnlyBuffer ();
 }