I have to retrieve some data from database using jdbc getBinaryStream() in
my servlet. The problem is that I have to step through the resultset,
concatenate the output instead of sending them directly to the caller since
I have to print out the length of the data before I send out the actual
data. So here are the code snippet:

     ByteArrayOutputStream buffer = new ByteArrayOutputStream();
            InputStream camera_mdl_data = null;
            int intLength = 0,c;
           //somehow get result set, prest
            while (prset.next ()){
                camera_mdl_data =  prset.getBinaryStream (1);
                while ((c = camera_mdl_data.read ()) != -1) {
                    buffer.write (c);
                    dataLen++;
                }
            }
     //somehow get ServletOutputStream, out
     out.print(dataLen);
     out.println();
     if (dataLen > 0)
        buffer.writeTo(out);
     out.flush();
     out.close();

 Do you see anywhere I can improve the performance both by speeding up and
reducing memory consumption. I am afraid byte by byte reading and writing
is too slow  and buffer writting will eat a lot of memory:

                while ((c = camera_mdl_data.read ()) != -1) {
                    buffer.write (c);
                    dataLen++;
                }
 If this servlet is called quite often and garbage collection does not kick
in fast enough, I will see huge performance drag.

Thanks

Bing

___________________________________________________________________________
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

Reply via email to