You should try to read from file and output to the net at the same time. The way you're doing it now costs more time and memory. More time, because you first read int eh whole file from disk, before you start outputing, while if you do this at the same time you will safe some time. Memory will saved, as you do not need to keep the whole file in memory, but only the part which you load in buffer.
Something like this:
int bufSize = 100000 // Don't know what the most efficient buffer size is... something you can experience with or google for
BufferedOutputStream bos = new BufferedOutputStream(out);
BufferedInputStream bis = new BufferedInputStream( new FileInputStream( yourFile ) );
byte[] buff = new byte[bufSize];
int bytesRead=0;
while ( (bytesRead = bis.read(buff)) > 0 ){
bos.write(buf, 0, byteRead);
}
Frans
On Fri, 7 Jan 2005 14:52:57 +0900, Jean-Christian Imbeault wrote:
> Frans Verhoef wrote:
>
>> Maybe you could send the part of the code which is involved in
>> the streaming of the file in your servlet?
>>
> Do you mean the code of the other servlet which first reads the
> file and then passes the file contents on to this servlet?
>
> The code that "streams" the file was given, it's this part here:
>
> BufferedOutputStream bos = null;
> byte[] buff = null;
>
> try {
> bos = new BufferedOutputStream(out);
>
> /* the file was read from disk and put in the VO */ buff =
> fileContentVO.getFileContent(); bos.write(buff, 0, buff.length);
>
> if (bos != null) {
> bos.close();
> }
>
> Jc
>
> Note: This e-mail contains privileged and confidential information
> and is for the sole use of the intended recipient(s). If you are
> not an intended recipient, you are hereby kindly requested to
> refrain from printing, copying, or distributing the information
> contained herein. Furthermore, any other use of the information
> contained herein is strictly prohibited. If you have received this
> transmission in error, please kindly notify the sender immediately
> and destroy all copies of the original message.
>
> ======================================================================
> ===== To unsubscribe, send email to listserv@(protected)
> include in the body of the message "signoff J2EE-INTEREST". For
> general help, send email to listserv@(protected)
> the body of the message "help".
===========================================================================
To unsubscribe, send email to listserv@(protected)
of the message "signoff J2EE-INTEREST". For general help, send email to
listserv@(protected)".