This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[PATCH]
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Tue, 11 Feb 2003 08:44:37 +0100
- Subject: [PATCH]
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
I commeted the attached patch to make java.nio compile.
Tom: Perhaps this should go into 3.3 too.
Michael
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)
iD8DBQE+SKnpWSOgCCdjSDsRAvBfAJsFmwULGnf/ar7TPB4hKbXa+IcPBACfUWMx
0QvQYJd2iCltVF9lJwsFc74=
=NRus
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1676
diff -u -r1.1676 ChangeLog
--- ChangeLog 11 Feb 2003 06:51:34 -0000 1.1676
+++ ChangeLog 11 Feb 2003 07:41:38 -0000
@@ -1,5 +1,49 @@
2003-02-11 Michael Koch <konqueror@gmx.de>
+ * java/nio/Buffer.java
+ (cap, lim, pos, mark): Made private
+ (Buffer): Added package private constructor.
+ * java/nio/ByteBuffer.java
+ (ByteBuffer): Implements Cloneable.
+ (offset): New member variable.
+ (readOnly): New member variable.
+ (backing_buffer): New member variable.
+ (allocateDirect): Throw exception and tell that direct buffers are
+ not supported yet, documentation added.
+ (allocate): Documentation added.
+ (wrap): Documentation added.
+ (ByteBuffer): New constructor.
+ (hasArray): New method.
+ (array): New method.
+ (arrayOffset): New method.
+ (get): Documentation added.
+ (put): Documentation added.
+ * java/nio/CharBuffer.java
+ (CharBuffer): New constructor.
+ (compareTo): Don't access member variables of Buffer directly.
+ * java/nio/DoubleBuffer.java
+ (allocateDirect): Throw exception and tell that direct buffers are
+ not supported yet.
+ * java/nio/FloatBuffer.java
+ (allocateDirect): Throw exception and tell that direct buffers are
+ not supported yet.
+ * java/nio/IntBuffer.java
+ (allocateDirect): Throw exception and tell that direct buffers are
+ not supported yet.
+ * java/nio/LongBuffer.java
+ (allocateDirect): Throw exception and tell that direct buffers are
+ not supported yet.
+ * java/nio/MappedByteBuffer.java
+ (MappedByteBuffer): New method.
+ (force): New method.
+ (isLoaded): New method.
+ (load): New method.
+ * java/nio/ShortBuffer.java
+ (allocateDirect): Throw exception and tell that direct buffers are
+ not supported yet.
+
+2003-02-11 Michael Koch <konqueror@gmx.de>
+
* java/nio/DoubleBuffer.java
(DoubleBuffer): Implements Comparable.
(endian): Removed.
Index: java/nio/Buffer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/Buffer.java,v
retrieving revision 1.2
diff -u -r1.2 Buffer.java
--- java/nio/Buffer.java 13 Nov 2002 12:21:25 -0000 1.2
+++ java/nio/Buffer.java 11 Feb 2003 07:41:38 -0000
@@ -39,11 +39,33 @@
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: java/nio/ByteBuffer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/ByteBuffer.java,v
retrieving revision 1.3
diff -u -r1.3 ByteBuffer.java
--- java/nio/ByteBuffer.java 13 Nov 2002 18:43:20 -0000 1.3
+++ java/nio/ByteBuffer.java 11 Feb 2003 07:41:38 -0000
@@ -37,43 +37,178 @@
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: java/nio/CharBuffer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/CharBuffer.java,v
retrieving revision 1.1
diff -u -r1.1 CharBuffer.java
--- java/nio/CharBuffer.java 13 Nov 2002 12:21:25 -0000 1.1
+++ java/nio/CharBuffer.java 11 Feb 2003 07:41:38 -0000
@@ -88,6 +88,11 @@
{
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 @@
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: java/nio/DoubleBuffer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/DoubleBuffer.java,v
retrieving revision 1.2
diff -u -r1.2 DoubleBuffer.java
--- java/nio/DoubleBuffer.java 11 Feb 2003 06:51:34 -0000 1.2
+++ java/nio/DoubleBuffer.java 11 Feb 2003 07:41:38 -0000
@@ -46,7 +46,7 @@
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: java/nio/FloatBuffer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/FloatBuffer.java,v
retrieving revision 1.2
diff -u -r1.2 FloatBuffer.java
--- java/nio/FloatBuffer.java 11 Feb 2003 06:51:34 -0000 1.2
+++ java/nio/FloatBuffer.java 11 Feb 2003 07:41:38 -0000
@@ -46,7 +46,7 @@
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: java/nio/IntBuffer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/IntBuffer.java,v
retrieving revision 1.2
diff -u -r1.2 IntBuffer.java
--- java/nio/IntBuffer.java 11 Feb 2003 06:51:34 -0000 1.2
+++ java/nio/IntBuffer.java 11 Feb 2003 07:41:38 -0000
@@ -46,7 +46,7 @@
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: java/nio/LongBuffer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/LongBuffer.java,v
retrieving revision 1.2
diff -u -r1.2 LongBuffer.java
--- java/nio/LongBuffer.java 11 Feb 2003 06:51:34 -0000 1.2
+++ java/nio/LongBuffer.java 11 Feb 2003 07:41:38 -0000
@@ -46,7 +46,7 @@
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: java/nio/MappedByteBuffer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/MappedByteBuffer.java,v
retrieving revision 1.1
diff -u -r1.1 MappedByteBuffer.java
--- java/nio/MappedByteBuffer.java 7 Oct 2002 13:12:42 -0000 1.1
+++ java/nio/MappedByteBuffer.java 11 Feb 2003 07:41:38 -0000
@@ -37,6 +37,29 @@
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: java/nio/ShortBuffer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/ShortBuffer.java,v
retrieving revision 1.2
diff -u -r1.2 ShortBuffer.java
--- java/nio/ShortBuffer.java 11 Feb 2003 06:51:34 -0000 1.2
+++ java/nio/ShortBuffer.java 11 Feb 2003 07:41:38 -0000
@@ -46,7 +46,7 @@
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)