Am Freitag, 22. November 2002 10:48 schrieb Ito Kazumitsu:
> I would like the following JDK 1.4 features to be added to
> classpath. Thank you.
>
> --- java/nio/CharBuffer.java.orig Fri Nov 22 18:33:15 2002
> +++ java/nio/CharBuffer.java Fri Nov 22 18:37:27 2002
> @@ -42,7 +42,7 @@
> /**
> * @since 1.4
> */
> -public abstract class CharBuffer extends Buffer
> +public abstract class CharBuffer extends Buffer implements
> CharSequence {
> private ByteOrder endian = ByteOrder.BIG_ENDIAN;
>
>
>
> --- gnu/java/nio/CharBufferImpl.java.orig Fri Nov 22 18:34:47 2002
> +++ gnu/java/nio/CharBufferImpl.java Fri Nov 22 18:42:19 2002
> @@ -170,4 +170,19 @@
>
> return super.toString();
> }
> +
> + // There must be a better way of doing the following.
> + public CharSequence subSequence(int start, int end)
> + {
> + return toString().substring(start, end);
> + }
> + public int length()
> + {
> + return toString().length();
> + }
> + public char charAt(int i)
> + {
> + return toString().charAt(i);
> + }
> +
> }
Hello Ito,
I commited the attached patch to classpath. More changes are on my
hard disk and will go in slowly.
Michael
--
Homepage: http://www.worldforge.org/
GPG-key: http://konqueror.dyndns.org/~mkoch/michael.gpg
? autogen.sh
? build
Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.731
diff -b -u -r1.731 ChangeLog
--- ChangeLog 22 Nov 2002 12:35:11 -0000 1.731
+++ ChangeLog 22 Nov 2002 13:05:20 -0000
@@ -1,5 +1,19 @@
2002-11-22 Michael Koch <[EMAIL PROTECTED]>
+ * gnu/java/nio/CharBufferImpl.java
+ (subSequence): New stubbed method.
+ * gnu/java/nio/MappedCharFileBuffer.java:
+ Reindented.
+ (subSequence): New stubbed method.
+ * java/nio/CharBuffer.java
+ (CharBuffer): Implements Comparable and CharSequence.
+ (lenght): New method.
+ (charAt): New method.
+ (toString): New method.
+ (put): Removed unneeded "java.nio." prefix.
+
+2002-11-22 Michael Koch <[EMAIL PROTECTED]>
+
* java/nio/channels/Channels.java:
Reindented, documentation added.
(newInputStream): Documentation added.
Index: gnu/java/nio/CharBufferImpl.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/nio/CharBufferImpl.java,v
retrieving revision 1.9
diff -b -u -r1.9 CharBufferImpl.java
--- gnu/java/nio/CharBufferImpl.java 19 Nov 2002 11:21:34 -0000 1.9
+++ gnu/java/nio/CharBufferImpl.java 22 Nov 2002 13:05:20 -0000
@@ -87,6 +87,7 @@
private static native char[] nio_cast(int[]copy);
private static native char[] nio_cast(float[]copy);
private static native char[] nio_cast(double[]copy);
+
CharBufferImpl(byte[] copy) { this.backing_buffer = copy != null ? nio_cast(copy) : null; } private static native byte nio_get_Byte(CharBufferImpl b, int index, int limit); private static native void nio_put_Byte(CharBufferImpl b, int index, int limit, byte value); public ByteBuffer asByteBuffer() { ByteBufferImpl res = new ByteBufferImpl(backing_buffer); res.limit((limit()*1)/2); return res; }
CharBufferImpl(char[] copy) { this.backing_buffer = copy != null ? nio_cast(copy) : null; } private static native char nio_get_Char(CharBufferImpl b, int index, int limit); private static native void nio_put_Char(CharBufferImpl b, int index, int limit, char value); public CharBuffer asCharBuffer() { CharBufferImpl res = new CharBufferImpl(backing_buffer); res.limit((limit()*2)/2); return res; }
CharBufferImpl(short[] copy) { this.backing_buffer = copy != null ? nio_cast(copy) : null; } private static native short nio_get_Short(CharBufferImpl b, int index, int limit); private static native void nio_put_Short(CharBufferImpl b, int index, int limit, short value); public ShortBuffer asShortBuffer() { ShortBufferImpl res = new ShortBufferImpl(backing_buffer); res.limit((limit()*2)/2); return res; }
@@ -127,6 +128,12 @@
public boolean isDirect()
{
return backing_buffer != null;
+ }
+
+ final public CharSequence subSequence (int start, int end)
+ {
+ // FIXME
+ return null;
}
final public char get()
Index: gnu/java/nio/MappedCharFileBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/nio/MappedCharFileBuffer.java,v
retrieving revision 1.6
diff -b -u -r1.6 MappedCharFileBuffer.java
--- gnu/java/nio/MappedCharFileBuffer.java 30 Apr 2002 21:37:26 -0000 1.6
+++ gnu/java/nio/MappedCharFileBuffer.java 22 Nov 2002 13:05:20 -0000
@@ -36,8 +36,16 @@
exception statement from your version. */
package gnu.java.nio;
-import java.nio.*;
+
import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.CharBuffer;
+import java.nio.DoubleBuffer;
+import java.nio.FloatBuffer;
+import java.nio.IntBuffer;
+import java.nio.LongBuffer;
+import java.nio.ShortBuffer;
+
final public class MappedCharFileBuffer
extends CharBuffer
{
@@ -45,6 +53,7 @@
boolean ro;
boolean direct;
public FileChannelImpl ch;
+
public MappedCharFileBuffer(FileChannelImpl ch)
{
this.ch = ch;
@@ -56,6 +65,7 @@
System.err.println("failed to get size of file-channel's file");
}
}
+
public MappedCharFileBuffer(MappedCharFileBuffer b)
{
this.ro = b.ro;
@@ -63,55 +73,72 @@
address = b.address;
limit(b.limit());
}
+
public boolean isReadOnly()
{
return ro;
}
-final public char get()
+
+ final public char get()
{
char a = MappedByteFileBuffer.nio_read_Char_file_channel(ch, position(), limit(), address);
position(position() + 2);
return a;
}
-final public CharBuffer put(char b)
+
+ final public CharBuffer put(char b)
{
MappedByteFileBuffer.nio_write_Char_file_channel(ch, position(), limit(), b, address);
position(position() + 2);
return this;
}
-final public char get(int index)
+
+ final public char get(int index)
{
char a = MappedByteFileBuffer.nio_read_Char_file_channel(ch, index, limit(), address);
return a;
}
-final public CharBuffer put(int index, char b)
+
+ final public CharBuffer put(int index, char b)
{
MappedByteFileBuffer.nio_write_Char_file_channel(ch, index, limit(), b, address);
return this;
}
-final public CharBuffer compact()
+
+ final public CharBuffer compact()
{
return this;
}
-final public boolean isDirect()
+
+ final public boolean isDirect()
{
return direct;
}
-final public CharBuffer slice()
+
+ final public CharSequence subSequence (int start, int end)
+ {
+ // FIXME
+ return null;
+ }
+
+ final public CharBuffer slice()
{
MappedCharFileBuffer A = new MappedCharFileBuffer(this);
return A;
}
-public CharBuffer duplicate()
+
+ public CharBuffer duplicate()
{
return new MappedCharFileBuffer(this);
}
-public CharBuffer asReadOnlyBuffer()
+
+ public CharBuffer asReadOnlyBuffer()
{
MappedCharFileBuffer b = new MappedCharFileBuffer(this);
b.ro = true;
return b;
}
+
final public ByteBuffer asByteBuffer() { ByteBuffer res = new MappedByteFileBuffer(ch); res.limit((limit()*2)/1); return res; } final public byte getByte() { byte a = MappedByteFileBuffer.nio_read_Byte_file_channel(ch, position(), limit(), address); position(position() + 2); return a; } final public CharBuffer putByte(byte value) { MappedByteFileBuffer.nio_write_Byte_file_channel(ch, position(), limit(), value, address); position(position() + 2); return this; } final public byte getByte(int index) { byte a = MappedByteFileBuffer.nio_read_Byte_file_channel(ch, index, limit(), address); return a; } final public CharBuffer putByte(int index, byte value) { MappedByteFileBuffer.nio_write_Byte_file_channel(ch, index, limit(), value, address); return this; };
final public CharBuffer asCharBuffer() { CharBuffer res = new MappedCharFileBuffer(ch); res.limit((limit()*2)/2); return res; } final public char getChar() { char a = MappedByteFileBuffer.nio_read_Char_file_channel(ch, position(), limit(), address); position(position() + 2); return a; } final public CharBuffer putChar(char value) { MappedByteFileBuffer.nio_write_Char_file_channel(ch, position(), limit(), value, address); position(position() + 2); return this; } final public char getChar(int index) { char a = MappedByteFileBuffer.nio_read_Char_file_channel(ch, index, limit(), address); return a; } final public CharBuffer putChar(int index, char value) { MappedByteFileBuffer.nio_write_Char_file_channel(ch, index, limit(), value, address); return this; };
final public ShortBuffer asShortBuffer() { ShortBuffer res = new MappedShortFileBuffer(ch); res.limit((limit()*2)/2); return res; } final public short getShort() { short a = MappedByteFileBuffer.nio_read_Short_file_channel(ch, position(), limit(), address); position(position() + 2); return a; } final public CharBuffer putShort(short value) { MappedByteFileBuffer.nio_write_Short_file_channel(ch, position(), limit(), value, address); position(position() + 2); return this; } final public short getShort(int index) { short a = MappedByteFileBuffer.nio_read_Short_file_channel(ch, index, limit(), address); return a; } final public CharBuffer putShort(int index, short value) { MappedByteFileBuffer.nio_write_Short_file_channel(ch, index, limit(), value, address); return this; };
Index: java/nio/CharBuffer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/nio/CharBuffer.java,v
retrieving revision 1.5
diff -b -u -r1.5 CharBuffer.java
--- java/nio/CharBuffer.java 16 Nov 2002 16:02:56 -0000 1.5
+++ java/nio/CharBuffer.java 22 Nov 2002 13:05:21 -0000
@@ -43,6 +43,7 @@
* @since 1.4
*/
public abstract class CharBuffer extends Buffer
+ implements Comparable, CharSequence
{
private ByteOrder endian = ByteOrder.BIG_ENDIAN;
@@ -155,6 +156,35 @@
return false;
}
+ public abstract CharSequence subSequence (int start, int end);
+
+ public final int length ()
+ {
+ return limit ();
+ }
+
+ public final char charAt (int i)
+ {
+ if (hasArray ())
+ {
+ return backing_buffer[i];
+ }
+
+ // FIXME: there must be a more elegant way of doing this.
+ return toString ().charAt (i);
+ }
+
+ public String toString()
+ {
+ if (hasArray ())
+ {
+ return new String (backing_buffer);
+ }
+
+ // FIXME: Implement this.
+ return "";
+ }
+
public int compareTo(Object obj)
{
CharBuffer a = (CharBuffer) obj;
@@ -191,9 +221,9 @@
}
public abstract char get();
- public abstract java.nio. CharBuffer put(char b);
+ public abstract CharBuffer put(char b);
public abstract char get(int index);
- public abstract java.nio. CharBuffer put(int index, char b);
+ public abstract CharBuffer put(int index, char b);
public abstract CharBuffer compact();
public abstract boolean isDirect();
public abstract CharBuffer slice();