How to know thw size of the object to transfer?

Hi, I want to know how to know thw size of the object that is going to be transfered by a network. I am doing a game and I need to know how many bytes are being trasmited on each transfer. Is there anyway to get it, or any other quantity os size.?
[254 byte] By [MelGohana] at [2007-10-3 0:11:30]
# 1

can we use the available method of the inputStream that we are using?

For example:

.

.

.

BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream());

byte[] buffer=new byte(br.available());

.

.

.

nvraman_83a at 2007-7-14 17:01:12 > top of Java-index,Archived Forums,Socket Programming...
# 2
Any other way? becausse I need to do it before sending the data. I guess I may adapt this solution but it will need a lot of changes on my code.
MelGohana at 2007-7-14 17:01:12 > top of Java-index,Archived Forums,Socket Programming...
# 3

BufferedReader doesn't have an available() method for a start.

The InputStream.available() method is not a solution for this problem, or for any other problem I am aware of either.

The OP needs to write his data to a ByteArrayOutputStream and then find out its size, write the size, then get the bytes from the BAOS and write those.

ejpa at 2007-7-14 17:01:12 > top of Java-index,Archived Forums,Socket Programming...
# 4
OP'? BAOS?. I am afraid I dont understand!
MelGohana at 2007-7-14 17:01:12 > top of Java-index,Archived Forums,Socket Programming...
# 5
> OP'? BAOS?. I am afraid I dont understand!AbbreviationsOP = "Original Post" or "Original Poster"BAOS=ByteArrayOutputStream
jschella at 2007-7-14 17:01:12 > top of Java-index,Archived Forums,Socket Programming...