[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Bug Report] java.nio.CharBuffer: toString() returns empty string
From: |
Ito Kazumitsu |
Subject: |
[Bug Report] java.nio.CharBuffer: toString() returns empty string |
Date: |
Mon, 19 May 2003 11:49:42 +0900 |
User-agent: |
SEMI/1.14.3 (Ushinoya) FLIM/1.14.3 (Unebigory ōmae) APEL/10.3 Emacs/20.7 (i386-*-windows98.2222) MULE/4.1 (AOI) Meadow/1.14 (AWSAKA:62) |
toString() of java.nio.CharBuffer should not change the buffer's position
but the get() used in the toString() changes it. So the output of
toString() is always empty.
Test program:
import java.nio.CharBuffer;
public class CharBufferTest {
public static void main(String[] args) throws Exception {
String s = "Ito Kazumitsu";
int l = s.length();
char[] charbuf = new char[l];
for (int i = 0; i < l; i++) {
charbuf[i] = s.charAt(i);
}
CharBuffer cb = CharBuffer.wrap(charbuf, 0, l);
System.out.println("Before toString()");
System.out.println("length="+ cb.length());
System.out.println("position=" +cb.position());
System.out.println("limit=" +cb.limit());
String s1 = cb.toString();
System.out.println("After toString()");
System.out.println("length="+ cb.length());
System.out.println("position=" +cb.position());
System.out.println("limit=" +cb.limit());
System.out.println("String length = " + s1.length());
System.out.println(s1);
}
}
Result:
bash$ java CharBufferTest
Before toString()
length=13
position=0
limit=13
After toString()
length=0
position=13
limit=13
String length = 0
bash$
Result under Sun's JDK.
bash$ java CharBufferTest
Before toString()
length=13
position=0
limit=13
After toString()
length=13
position=0
limit=13
String length = 13
Ito Kazumitsu
bash$
- [Bug Report] java.nio.CharBuffer: toString() returns empty string,
Ito Kazumitsu <=