
To increase the performance of your Java
If you know the maximum content length, the most optimal read would be a single line, like this:
len = instream.read( buf, 0, MAX_BUFFER_SIZE );
In this case we assume that the buffer has already been allocated with a size set to MAX_BUFFER_SIZE.
If the content is of varying size, we have to make a tradeoff between performance and memory usage. If you keep your buffer size just above the average content length, then the number of reallocations of the data buffer and the number of reads will be kept at a minimum. However if the average content length is too large to fit in memory, or if you only need access to sub sections at a time, it might be better to have the array size kept small and read from the stream.
Source http://developer.sonyericsson.com/site/global/techsupport/tipstrickscode/java/p_faststreamreadinginjava.jsp
0 comments on "Fast stream reading in Java"
Post a Comment