Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

JPG content-length or deal with chunked transfer?

843841Jun 28 2006 — edited Jun 30 2006
Hi
I have to send a JPG image from a servlet to an applet, and, I have to do it through an URLConnection (the host doesn't allow doing that opening a raw socket connection). And here comes the (HTTP protocol specific) trouble. Before flushing the image from the servlet one has to know it's size in bytes to set the "content-length" property, otherwise the server sends it in "chunks", thus, my applet receives not only the image, but also the so called "chunk metadata". Hence I have 2 ways to solve the problem.
1. The easiest. To find out how many bytes occupies the JPG image and tell it to the server by setting the "content-length" property before flushing the image from the servlet to the applet.
2. Write a custom "transfer-encoding: chunked"-processing function in the applet, which would sort the bytes received and do low level bytes pushing to "put the image together", which I couldn't manage..

Thus, someone please give me a hint how to find out the byte size of a JPG image which is in the memory (or a function which puts back the data received via a "chunked" transfer). I could write the image to disk (on the server-side) then read the size of the image file and set this way the "content-length" property, but I really don't wanna do this cause it would work very slow and I think is an awkward solution..
Please help!
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 28 2006
Added on Jun 28 2006
2 comments
353 views