>>> JOSE ADRIANO BALTIERI <[EMAIL PROTECTED]> 03-Jun-00
1:14:42 PM >>>
>I'm migrating from CGI-WIN to servlets and, noticed that the loop
>below is not only slow but also, consumes a lot of CPU processor.
>Wonder if someone else could suggest something better.
> try
> {
> Thread.sleep(100);
> }
> catch(InterruptedException ex)
> {
> }
I don't really understand why you're taking a snooze...
Is FOut a File? if so...
> FileReader frout = new FileReader(FOut);
> BufferedReader brout = new BufferedReader(frout);
>
char[] content=new char[FOut.size()];
int red=brout.read(content,0,content.length);
while(red!=-1)
{
//this loop should never be called but it's a good safety
mesaure
red=brout.read(content,red-1,content.length-red);
}
//now output
rw.write(content,0,content.length);
> rw.close();
> brout.close();
> FOut.delete();
Alternately you could use a large block size (I often compute one as
some proportion of available memory) to read and write into the
array.
You will find that with an implementation of Reader that talks
correctly to it's realted InputStream the blocking of whatever
platform you are on will be used and the read will be pretty fast.
Certainly I use something like this in GNU-Paperclips' webserver
servlet.
Nic Ferrier
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html