OSDN Git Service

2003-02-11 Michael Koch <konqueror@gmx.de>
authormkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 11 Feb 2003 07:42:17 +0000 (07:42 +0000)
committermkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 11 Feb 2003 07:42:17 +0000 (07:42 +0000)
* java/nio/Buffer.java
(cap, lim, pos, mark): Made private
(Buffer): Added package private constructor.
* java/nio/ByteBuffer.java
(ByteBuffer): Implements Cloneable.
(offset): New member variable.
(readOnly): New member variable.
(backing_buffer): New member variable.
(allocateDirect): Throw exception and tell that direct buffers are
not supported yet, documentation added.
(allocate): Documentation added.
(wrap): Documentation added.
(ByteBuffer): New constructor.
(hasArray): New method.
(array): New method.
(arrayOffset): New method.
(get): Documentation added.
(put): Documentation added.
* java/nio/CharBuffer.java
(CharBuffer): New constructor.
(compareTo): Don't access member variables of Buffer directly.
* java/nio/DoubleBuffer.java
(allocateDirect): Throw exception and tell that direct buffers are
not supported yet.
* java/nio/FloatBuffer.java
(allocateDirect): Throw exception and tell that direct buffers are
not supported yet.
* java/nio/IntBuffer.java
(allocateDirect): Throw exception and tell that direct buffers are
not supported yet.
* java/nio/LongBuffer.java
(allocateDirect): Throw exception and tell that direct buffers are
not supported yet.
* java/nio/MappedByteBuffer.java
(MappedByteBuffer): New method.
(force): New method.
(isLoaded): New method.
(load): New method.
* java/nio/ShortBuffer.java
(allocateDirect): Throw exception and tell that direct buffers are
not supported yet.

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

libjava/java/nio/Buffer.java
libjava/java/nio/ByteBuffer.java
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/MappedByteBuffer.java
libjava/java/nio/ShortBuffer.java

index 9474fb4..7d291be 100644 (file)
@@ -39,11 +39,33 @@ package java.nio;
 
 public abstract class Buffer
 {
-  int cap = 0;
-  int limit = 0;
-  int pos = 0;
-  int mark = -1;
-
+  private int cap = 0;
+  private int limit = 0;
+  private int pos = 0;
+  private int mark = -1;
+
+  // Creates a new Buffer.
+  //
+  // Should be package private.
+  //
+  Buffer (int capacity, int limit, int position, int mark)
+  {
+    if (capacity < 0)
+      throw new IllegalArgumentException ();
+    
+    cap = capacity;
+    limit (limit);
+    position (position);
+    
+    if (mark > 0)
+    {
+      if (mark > pos)
+        throw new IllegalArgumentException ();
+      
+      this.mark = mark;
+    }
+  }
+  
   /**
    * Retrieves the capacity of the buffer.
    */
index 874943a..380e6c6 100644 (file)
@@ -37,43 +37,178 @@ exception statement from your version. */
 
 package java.nio;
 
-public abstract class ByteBuffer extends Buffer
+/**
+ * @since 1.4
+ */
+public abstract class ByteBuffer extends Buffer implements Comparable
 {
+  int offset;
+  boolean readOnly;
+  byte[] backing_buffer;
+  
+  /**
+   * Allocates a new direct byte buffer.
+   */ 
+  public static ByteBuffer allocateDirect (int capacity)
+  {
+    throw new Error ("direct buffers are not implemented");
+  }
+
+  /**
+   * Allocates a new byte buffer.
+   */
   public static ByteBuffer allocate (int capacity)
   {
     return null;
   }
  
+  /**
+   * Wraps a byte array into a buffer.
+   * 
+   * @exception IndexOutOfBoundsException If the preconditions on the offset
+   * and length parameters do not hold
+   */
   final public static ByteBuffer wrap (byte[] array, int offset, int length)
   {
     return null;
   }
 
+  /**
+   * Wraps a byte array into a buffer.
+   */
   final public static ByteBuffer wrap (byte[] array)
   {
     return wrap (array, 0, array.length);
   }
-  
-  final public ByteBuffer put (ByteBuffer src)
+
+  ByteBuffer (int capacity, int limit, int position, int mark)
+  {
+    super (capacity, limit, position, mark);
+  }
+
+  /**
+   * Writes the content of src into the buffer.
+   *
+   * @param src The source data.
+   *
+   * @exception BufferOverflowException If there is insufficient space in this
+   * buffer for the remaining bytes in the source buffer.
+   * @exception IllegalArgumentException If the source buffer is this buffer.
+   * @exception ReadOnlyBufferException If this buffer is read only.
+   */
+  public ByteBuffer put (ByteBuffer src)
   {
+    if (src == this)
+      throw new IllegalArgumentException ();
+
     while (src.hasRemaining ())
       put (src.get ());
     
     return this;
   }
-  
-  final public ByteBuffer put (byte[] src, int offset, int length)
+
+  /**
+   * Writes the content of the the array src into the buffer.
+   *
+   * @param src The array to copy into the buffer.
+   * @param offset The offset within the array of the first byte to be read;
+   * must be non-negative and no larger than src.length.
+   * @param length The number of bytes to be read from the given array;
+   * must be non-negative and no larger than src.length - offset.
+   *
+   * @exception BufferOverflowException If there is insufficient space in this
+   * buffer for the remaining bytes in the source buffer.
+   * @exception IndexOutOfBoundsException If the preconditions on the offset
+   * and length parameters do not hold.
+   * @exception ReadOnlyBufferException If this buffer is read only.
+   */
+  public ByteBuffer put (byte[] src, int offset, int length)
   {
+    if ((offset < 0) ||
+        (offset > src.length) ||
+        (length < 0) ||
+        (length > src.length - offset))
+      throw new IndexOutOfBoundsException ();
+
     for (int i = offset; i < offset + length; i++)
       put (src [i]);
+    
     return this;
   }
+
+  /**
+   * Writes the content of the the array src into the buffer.
+   *
+   * @param src The array to copy into the buffer.
+   *
+   * @exception BufferOverflowException If there is insufficient space in this
+   * buffer for the remaining bytes in the source buffer.
+   * @exception ReadOnlyBufferException If this buffer is read only.
+   */
   public final ByteBuffer put (byte[] src)
   {
     return put (src, 0, src.length);
   }
 
+  /**
+   * Tells whether or not this buffer is backed by an accessible byte array.
+   */
+  public final boolean hasArray ()
+  {
+    return (backing_buffer != null
+             && !readOnly);
+  }
+
+  /**
+   * Returns the byte array that backs this buffer.
+   *
+   * @exception ReadOnlyBufferException If this buffer is backed by an array
+   * but is read-only.
+   * @exception UnsupportedOperationException If this buffer is not backed
+   * by an accessible array.
+   */
+  public final byte[] array ()
+  {
+    if (backing_buffer == null)
+      throw new UnsupportedOperationException ();
+
+    if (readOnly)
+      throw new ReadOnlyBufferException ();
+
+    return backing_buffer;
+  }
+
+  /**
+   * Returns the offset within this buffer's backing array of the first element
+   * of the buffer  
+   *
+   * @exception ReadOnlyBufferException If this buffer is backed by an array
+   * but is read-only.
+   * @exception UnsupportedOperationException If this buffer is not backed
+   * by an accessible array.
+   */
+  public final int arrayOffset ()
+  {
+    if (backing_buffer == null)
+      throw new UnsupportedOperationException ();
+
+    if (readOnly)
+      throw new ReadOnlyBufferException ();
+
+    return offset;
+  }
+  
+  /**
+   * Relative get method.
+   */
   public abstract byte get ();
   
+  /**
+   * Relative put method.
+   *
+   * @exception BufferOverflowException If this buffer's current position is
+   * not smaller than its limit.
+   * @exception ReadOnlyBufferException If this buffer is read-only.
+   */
   public abstract ByteBuffer put (byte b);
 }
index 2a21ef9..0e61302 100644 (file)
@@ -88,6 +88,11 @@ public abstract class CharBuffer extends Buffer
   {
     return wrap  (array, 0, array.length);
   }
+  CharBuffer (int cap, int lim, int pos, int mark)
+  {
+    super (cap, lim, pos, mark);
+  }
   
   /**
    * @exception BufferUnderflowException FIXME
@@ -197,8 +202,8 @@ public abstract class CharBuffer extends Buffer
       return 1;
     
     int r = remaining ();
-    int i1 = pos;
-    int i2 = a.pos;
+    int i1 = position ();
+    int i2 = a.position ();
     
     for (int i = 0; i < r; i++)
       {
index 79de54a..72a6c09 100644 (file)
@@ -46,7 +46,7 @@ public abstract class DoubleBuffer extends Buffer implements Comparable
 
   public static DoubleBuffer allocateDirect(int capacity)
   {
-    return new DoubleBufferImpl(capacity, 0, capacity);
+    throw new Error ("direct buffers are not implemented");
   }
 
   public static DoubleBuffer allocate(int capacity)
index 7cabd96..b780ff5 100644 (file)
@@ -46,7 +46,7 @@ public abstract class FloatBuffer extends Buffer implements Comparable
 
   public static FloatBuffer allocateDirect(int capacity)
   {
-    return new FloatBufferImpl (capacity, 0, capacity);
+    throw new Error ("direct buffers not implemented");
   }
 
   public static FloatBuffer allocate(int capacity)
index 2aadf35..aca6e0f 100644 (file)
@@ -46,7 +46,7 @@ public abstract class IntBuffer extends Buffer implements Comparable
 
   public static IntBuffer allocateDirect(int capacity)
   {
-    return new IntBufferImpl (capacity, 0, capacity);
+    throw new Error ("direct buffers not implemented");
   }
 
   public static IntBuffer allocate(int capacity)
index 62ff390..0ddc793 100644 (file)
@@ -46,7 +46,7 @@ public abstract class LongBuffer extends Buffer implements Comparable
 
   public static LongBuffer allocateDirect(int capacity)
   {
-    return new LongBufferImpl(capacity, 0, capacity);
+    throw new Error ("direct buffers not implemented");
   }
 
   public static LongBuffer allocate(int capacity)
index dc1b20d..305327b 100644 (file)
@@ -37,6 +37,29 @@ exception statement from your version. */
 
 package java.nio;
 
+/**
+ * @author Michael Koch
+ * @since 1.4
+ */
 public abstract class MappedByteBuffer extends ByteBuffer
 {
+  MappedByteBuffer (int capacity, int limit, int position, int mark)
+  {
+    super (capacity, limit, position, mark);
+  }
+  
+  public final MappedByteBuffer force ()
+  {
+    return this;
+  }
+    
+  public final boolean isLoaded ()
+  {
+    return true;
+  }
+    
+  public final MappedByteBuffer load ()
+  {
+    return this;
+  }
 }
index 08c05c4..512c9fd 100644 (file)
@@ -46,7 +46,7 @@ public abstract class ShortBuffer extends Buffer implements Comparable
 
   public static ShortBuffer allocateDirect(int capacity)
   {
-    return new ShortBufferImpl(capacity, 0, capacity);
+    throw new Error ("direct buffers not implemented");
   }
 
   public static ShortBuffer allocate(int capacity)