S
Stefan Ram
When a client sends an HTTP PUT request to my web server,
I start to read characters from the socket:
this.br =
new java.io.BufferedReader
( new java.io.InputStreamReader
( socket.getInputStream(), "ANSI_X3.4-1968" ));
But sometimes, after the initial text, the socket will
change to emit binary data (octets), that is, it will
send me the actual data of the PUT request during the
same transmission (TCP session).
The read()-method of the InputStreamReader will give
me a converted character. But I need unconverted octets
from this point on. With the above code, Java will
convert some octets and modify their values, so that
the binary data will become corrupted.
When I start then to use the read()-method of the
socket.getInputStream(), I might miss some octets which where
already read by the InputStreamReader or the BufferedReader.
But I also want to have buffering, because I/O usually is
slower without buffering.
Is there already a well-known solution to such a problem,
that is, switch from text to binary mode when reading from
a socket?
One possibility would be an encoding name that hints to
Java to treat 0A and 0D as line seperators, but otherwise
not to modify octet values, when converting octets to
characters. Then I could read the octets as characters.
(Or do I have to write a custom CharsetDecoder for this?)
I start to read characters from the socket:
this.br =
new java.io.BufferedReader
( new java.io.InputStreamReader
( socket.getInputStream(), "ANSI_X3.4-1968" ));
But sometimes, after the initial text, the socket will
change to emit binary data (octets), that is, it will
send me the actual data of the PUT request during the
same transmission (TCP session).
The read()-method of the InputStreamReader will give
me a converted character. But I need unconverted octets
from this point on. With the above code, Java will
convert some octets and modify their values, so that
the binary data will become corrupted.
When I start then to use the read()-method of the
socket.getInputStream(), I might miss some octets which where
already read by the InputStreamReader or the BufferedReader.
But I also want to have buffering, because I/O usually is
slower without buffering.
Is there already a well-known solution to such a problem,
that is, switch from text to binary mode when reading from
a socket?
One possibility would be an encoding name that hints to
Java to treat 0A and 0D as line seperators, but otherwise
not to modify octet values, when converting octets to
characters. Then I could read the octets as characters.
(Or do I have to write a custom CharsetDecoder for this?)