This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: NIO fixes
- From: Michael Koch <konqueror at gmx dot de>
- To: java-patches at gcc dot gnu dot org
- Date: Sun, 30 May 2004 15:39:31 +0200
- Subject: Patch: NIO fixes
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Hi list,
I just commited the attached patch to merge some fixes for NIO from
GNU classpath.
Michael
2004-05-30 Michael Koch <konqueror@gmx.de>
* java/nio/Buffer.java
(limit): Fixed off by one error.
* java/nio/CharBuffer.java
(wrap): Fixed arguments, added javadocs.
- --
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)
iD8DBQFAueQVWSOgCCdjSDsRAhDXAJ45NjBsD1idlriNssAtE3npjBB91gCfWdqB
PIwswOAHUY4Jyq23Gshdbtc=
=/3uz
-----END PGP SIGNATURE-----
Index: java/nio/Buffer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/Buffer.java,v
retrieving revision 1.7
diff -u -b -B -r1.7 Buffer.java
--- java/nio/Buffer.java 20 Apr 2004 15:27:37 -0000 1.7
+++ java/nio/Buffer.java 30 May 2004 13:38:01 -0000
@@ -148,11 +148,11 @@
if ((newLimit < 0) || (newLimit > cap))
throw new IllegalArgumentException ();
- if (newLimit <= mark)
+ if (newLimit < mark)
mark = -1;
if (pos > newLimit)
- pos = newLimit - 1;
+ pos = newLimit;
limit = newLimit;
return this;
Index: java/nio/CharBuffer.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/CharBuffer.java,v
retrieving revision 1.16
diff -u -b -B -r1.16 CharBuffer.java
--- java/nio/CharBuffer.java 4 May 2004 21:31:30 -0000 1.16
+++ java/nio/CharBuffer.java 30 May 2004 13:38:01 -0000
@@ -65,56 +65,75 @@
* Wraps a <code>char</code> array into a <code>CharBuffer</code>
* object.
*
+ * @param array the array to wrap
+ * @param offset the offset of the region in the array to wrap
+ * @param length the length of the region in the array to wrap
+ *
+ * @return a new <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)
+ final public static CharBuffer wrap(char[] array, int offset, int length)
{
- return new CharBufferImpl (array, 0, array.length, offset + length, offset, -1, false);
+ return new CharBufferImpl(array, 0, array.length, offset + length, offset, -1, false);
}
/**
* Wraps a character sequence into a <code>CharBuffer</code> object.
+ *
+ * @param seq the sequence to wrap
+ *
+ * @return a new <code>CharBuffer</code> object
*/
- final public static CharBuffer wrap (CharSequence a)
+ final public static CharBuffer wrap(CharSequence seq)
{
- return wrap (a, 0, a.length ());
+ return wrap(seq, 0, seq.length());
}
/**
* Wraps a character sequence into a <code>CharBuffer</code> object.
*
+ * @param seq the sequence to wrap
+ * @param start the index of the first character to wrap
+ * @param end the index of the first character not to wrap
+ *
+ * @return a new <code>CharBuffer</code> object
+ *
* @exception IndexOutOfBoundsException If the preconditions on the offset
* and length parameters do not hold
*/
- final public static CharBuffer wrap (CharSequence a, int offset, int length)
+ final public static CharBuffer wrap(CharSequence seq, int start, int end)
{
// FIXME: implement better handling of java.lang.String.
// Probably share data with String via reflection.
- if ((offset < 0)
- || (offset > a.length ())
- || (length < 0)
- || (length > (a.length () - offset)))
- throw new IndexOutOfBoundsException ();
+ if ((start < 0)
+ || (start > seq.length())
+ || (end < start)
+ || (end > (seq.length() - start)))
+ throw new IndexOutOfBoundsException();
- char [] buffer = new char [a.length ()];
+ int len = end - start;
+ char[] buffer = new char[len];
- for (int i = offset; i < length; i++)
- {
- buffer [i] = a.charAt (i);
- }
+ for (int i = 0; i < len; i++)
+ buffer[i] = seq.charAt(i + start);
- return wrap (buffer, offset, length).asReadOnlyBuffer ();
+ return wrap(buffer, 0, len).asReadOnlyBuffer();
}
/**
* Wraps a <code>char</code> array into a <code>CharBuffer</code>
* object.
+ *
+ * @param array the array to wrap
+ *
+ * @return a new <code>CharBuffer</code> object
*/
- final public static CharBuffer wrap (char[] array)
+ final public static CharBuffer wrap(char[] array)
{
- return wrap (array, 0, array.length);
+ return wrap(array, 0, array.length);
}
/**