OSDN Git Service

libjava/
[pf3gnuchains/gcc-fork.git] / libjava / classpath / java / nio / DirectByteBufferImpl.java
index 1667299..8c907f5 100644 (file)
@@ -1,4 +1,4 @@
-/* DirectByteBufferImpl.java -- 
+/* DirectByteBufferImpl.java --
    Copyright (C) 2003, 2004 Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
@@ -38,7 +38,7 @@ exception statement from your version. */
 
 package java.nio;
 
-import gnu.classpath.RawData;
+import gnu.classpath.Pointer;
 
 abstract class DirectByteBufferImpl extends ByteBuffer
 {
@@ -59,9 +59,9 @@ abstract class DirectByteBufferImpl extends ByteBuffer
 
   static final class ReadOnly extends DirectByteBufferImpl
   {
-    ReadOnly(Object owner, RawData address,
-            int capacity, int limit,
-            int position)
+    ReadOnly(Object owner, Pointer address,
+             int capacity, int limit,
+             int position)
     {
       super(owner, address, capacity, limit, position);
     }
@@ -89,9 +89,9 @@ abstract class DirectByteBufferImpl extends ByteBuffer
       super(capacity);
     }
 
-    ReadWrite(Object owner, RawData address,
-             int capacity, int limit,
-             int position)
+    ReadWrite(Object owner, Pointer address,
+              int capacity, int limit,
+              int position)
     {
       super(owner, address, capacity, limit, position);
     }
@@ -109,9 +109,9 @@ abstract class DirectByteBufferImpl extends ByteBuffer
     this.address = VMDirectByteBuffer.allocate(capacity);
   }
 
-  DirectByteBufferImpl(Object owner, RawData address,
-                      int capacity, int limit,
-                      int position)
+  DirectByteBufferImpl(Object owner, Pointer address,
+                       int capacity, int limit,
+                       int position)
   {
     super(capacity, limit, position, -1);
     this.owner = owner;
@@ -120,7 +120,7 @@ abstract class DirectByteBufferImpl extends ByteBuffer
 
   /**
    * Allocates a new direct byte buffer.
-   */ 
+   */
   public static ByteBuffer allocate(int capacity)
   {
     return new DirectByteBufferImpl.ReadWrite(capacity);
@@ -131,7 +131,7 @@ abstract class DirectByteBufferImpl extends ByteBuffer
     if (owner == this)
         VMDirectByteBuffer.free(address);
   }
-  
+
   public byte get()
   {
     checkForUnderflow();
@@ -170,7 +170,7 @@ abstract class DirectByteBufferImpl extends ByteBuffer
     position(pos + 1);
     return this;
   }
-  
+
   public ByteBuffer put(int index, byte value)
   {
     checkIndex(index);
@@ -178,12 +178,24 @@ abstract class DirectByteBufferImpl extends ByteBuffer
     VMDirectByteBuffer.put(address, index, value);
     return this;
   }
-  
+
+  public ByteBuffer put (byte[] src, int offset, int length)
+  {
+    checkArraySize (src.length, offset, length);
+    checkForUnderflow (length);
+
+    int index = position ();
+    VMDirectByteBuffer.put (address, index, src, offset, length);
+    position (index + length);
+
+    return this;
+  }
+
   void shiftDown(int dst_offset, int src_offset, int count)
   {
     VMDirectByteBuffer.shiftDown(address, dst_offset, src_offset, count);
   }
-  
+
   public ByteBuffer compact()
   {
     checkIfReadOnly();
@@ -191,15 +203,15 @@ abstract class DirectByteBufferImpl extends ByteBuffer
     int pos = position();
     if (pos > 0)
       {
-       int count = remaining();
-       VMDirectByteBuffer.shiftDown(address, 0, pos, count);
-       position(count);
-       limit(capacity());
+        int count = remaining();
+        VMDirectByteBuffer.shiftDown(address, 0, pos, count);
+        position(count);
+        limit(capacity());
       }
     else
       {
-       position(limit());
-       limit(capacity());
+        position(limit());
+        limit(capacity());
       }
     return this;
   }
@@ -220,7 +232,8 @@ abstract class DirectByteBufferImpl extends ByteBuffer
   private ByteBuffer duplicate(boolean readOnly)
   {
     int pos = position();
-    reset();
+    if (this.mark != -1)
+      reset();
     int mark = position();
     position(pos);
     DirectByteBufferImpl result;
@@ -233,9 +246,9 @@ abstract class DirectByteBufferImpl extends ByteBuffer
 
     if (mark != pos)
       {
-       result.position(mark);
-       result.mark();
-       result.position(pos);
+        result.position(mark);
+        result.mark();
+        result.position(pos);
       }
     return result;
   }
@@ -289,18 +302,18 @@ abstract class DirectByteBufferImpl extends ByteBuffer
   {
     return ByteBufferHelper.getChar(this, order());
   }
-  
+
   public ByteBuffer putChar(char value)
   {
     ByteBufferHelper.putChar(this, value, order());
     return this;
   }
-  
+
   public char getChar(int index)
   {
     return ByteBufferHelper.getChar(this, index, order());
   }
-  
+
   public ByteBuffer putChar(int index, char value)
   {
     ByteBufferHelper.putChar(this, index, value, order());
@@ -311,18 +324,18 @@ abstract class DirectByteBufferImpl extends ByteBuffer
   {
     return ByteBufferHelper.getShort(this, order());
   }
-  
+
   public ByteBuffer putShort(short value)
   {
     ByteBufferHelper.putShort(this, value, order());
     return this;
   }
-  
+
   public short getShort(int index)
   {
     return ByteBufferHelper.getShort(this, index, order());
   }
-  
+
   public ByteBuffer putShort(int index, short value)
   {
     ByteBufferHelper.putShort(this, index, value, order());
@@ -333,18 +346,18 @@ abstract class DirectByteBufferImpl extends ByteBuffer
   {
     return ByteBufferHelper.getInt(this, order());
   }
-  
+
   public ByteBuffer putInt(int value)
   {
     ByteBufferHelper.putInt(this, value, order());
     return this;
   }
-  
+
   public int getInt(int index)
   {
     return ByteBufferHelper.getInt(this, index, order());
   }
-  
+
   public ByteBuffer putInt(int index, int value)
   {
     ByteBufferHelper.putInt(this, index, value, order());
@@ -355,18 +368,18 @@ abstract class DirectByteBufferImpl extends ByteBuffer
   {
     return ByteBufferHelper.getLong(this, order());
   }
-  
+
   public ByteBuffer putLong(long value)
   {
     ByteBufferHelper.putLong(this, value, order());
     return this;
   }
-  
+
   public long getLong(int index)
   {
     return ByteBufferHelper.getLong(this, index, order());
   }
-  
+
   public ByteBuffer putLong(int index, long value)
   {
     ByteBufferHelper.putLong(this, index, value, order());
@@ -377,13 +390,13 @@ abstract class DirectByteBufferImpl extends ByteBuffer
   {
     return ByteBufferHelper.getFloat(this, order());
   }
-  
+
   public ByteBuffer putFloat(float value)
   {
     ByteBufferHelper.putFloat(this, value, order());
     return this;
   }
-  
+
   public float getFloat(int index)
   {
     return ByteBufferHelper.getFloat(this, index, order());
@@ -405,12 +418,12 @@ abstract class DirectByteBufferImpl extends ByteBuffer
     ByteBufferHelper.putDouble(this, value, order());
     return this;
   }
-  
+
   public double getDouble(int index)
   {
     return ByteBufferHelper.getDouble(this, index, order());
   }
-  
+
   public ByteBuffer putDouble(int index, double value)
   {
     ByteBufferHelper.putDouble(this, index, value, order());