Correlation between the array buffer and the read of a stream
InputStreamReader isr =new InputStreamReader(str, encoding);
ArrayList<String> al =new ArrayList<String>(128900);
char[] ar =newchar[26];
while(isr.read(ar) != -1){
al.add(new String(ar);
}
Why is that in my case of a 2.8 MB text file, when just doing a System.currentmillis I can faster times for a char array of 24-26 ?
What is the correlation?
[695 byte] By [
Mordana] at [2007-10-3 0:41:40]

I don't understand the question but, as the code doesn't work properly yet, timing it is irrelevant at this stage. You are ignoring the length returned by isr.read() so you are appending junk to a1 at least some of the time.
ejpa at 2007-7-14 17:35:56 >

Here is the full code
It reads a txt file with 128900 words in UTF-8
InputStreamReader isr = new InputStreamReader(str, encoding);
//__log.debug(isr.markSupported());
//128900
ArrayList<String> al = new ArrayList<String>(128900);
char[] ar = new char[24];
char[] word = new char[26];
int offset = 0;
int length = 0;
while( (length=isr.read(ar)) != -1) {
for (int i = 0; i < length; i++) {
if(ar[i] == '\r' || ar[i] == '\n') {
if(offset != 0) {
al.add(new String(word,0,offset));
offset = 0;
}
} else {
word[offset] = ar[i];
offset++;
}
}
}
This code executes in 600ms with a value of 24-26 in the array ar
If you change that value to more or less, code executes more slowly
NOTE: we know advance that the max length of a word is 26 char that why we have a word array of 26
Using a [url=http://java.sun.com/j2se/1.5.0/docs/api/java/io/BufferedReader.html]BufferedReader[/url] might be a good idea, IMHO.
A buffered reader provides a useful readLine method.
Anyway, regarding the impact of buffer size on performance, I guess you'ld better choose a power of two (e.g. try comparing using 1000 and 1024.)
However, I'm not sure you'll reach significantly better performance with your approach, comparing to using a BufferedReader.
And your code would certainely look simpler and clearer.