Content-Length is set by the server. It is not required. If you are using a servlet then you would have to set the content length. Why do you want to know the length of an input stream when you are transferring Objects? I like to think we use Objects so we don't have to think about bytes.
Joined: May 22, 2006
i would like to know how much "traffic" is on the net depending on the size of transfered objects.
If you just want a ballpark figure, serialize a known number of objects to a file and read the size. Keep in mind that there will be overhead for serialization housekeeping information and, if you serialize one, the collection itself. The size of the objects themselves may be variable, especially if they contain wildly variable Strings or collections. If you want an exact figure, you could try wrapping the ServletOutputStream you hook the ObjectOutputStream to and measure the bytes being written. You could also observe the network traffic with a sniffer, but I have no experience with that.