Why doesn't OutputStream.write() return an int?

D

Daniel

Does anyone know if there's a way to determine how many bytes actually
were written to the underlying stream?

As you may know, OutputStream.write doesn't return an int, but is
declared void. Especially for Sockets, it would be interesting to see
how many bytes actully were written. I know that's in the hands of the
underlying TCP implementation and other buffers, but can I be certain
that when the thread returns from OutputStream.write(), that the data
was or will be written to the socket if no exceptions are thrown after
flushing the stream?



Thanks,
Daniel.
 
I

Illya Kysil

Hello, Daniel!
You wrote on 26 Nov 2003 16:26:22 +0100:

D> Does anyone know if there's a way to determine how many bytes actually were written to
D> the underlying stream?

D> As you may know, OutputStream.write doesn't return an int, but is declared void.
D> Especially for Sockets, it would be interesting to see how many bytes actully were
D> written. I know that's in the hands of the underlying TCP implementation and other
D> buffers, but can I be certain that when the thread returns from OutputStream.write(),
D> that the data was or will be written to the socket if no exceptions are thrown after
D> flushing the stream?
java.io_OutputStream.write writes ALL passed data to underlying stream and/or OS buffers.
Otherwise it throws an exception.

Yes, data will be written. But that doesn't imply that it will be transmitted.
AFAIK the only value you can trust is the number of bytes other side received...

Regards
Illya Kysil, software developer
Delphi/C/C++/C#/Java/Forth/Assembler
If it is NOT SOURCE, it is NOT SOFTWARE. (C) NASA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top