R
Rick Genter
I have an InputStream on which I will be reading intermixed text and
binary data. When I go to read the text data, I create an
InputStreamReader from the InputStream and read characters one at a
time until I read a delimiter character. At that point, I go back to
reading raw bytes from the InputStream.
InputStreamReader.read() returns an int. I want to put these ints into
a String. Is the following what I should be doing?
StringBuffer buffer = new StringBuffer ();
InputStreamReader reader = new InputStreamReader (input);
int nextCharacter;
do
{
nextCharacter = reader.read ();
if (nextCharacter == -1) // shouldn't happen given protocol
throw new EOFException ();
if ((char) nextCharacter != DELIMITER)
buffer.append ((char) nextCharacter);
}
while ((char) nextCharacter != DELIMITER);
I hate having to cast nextCharacter, but I suppose that I have no
choice (yes, I can create a char variable and do the cast once, which
I probably will end up doing, but still...)
Thanks in advance.
Rick
binary data. When I go to read the text data, I create an
InputStreamReader from the InputStream and read characters one at a
time until I read a delimiter character. At that point, I go back to
reading raw bytes from the InputStream.
InputStreamReader.read() returns an int. I want to put these ints into
a String. Is the following what I should be doing?
StringBuffer buffer = new StringBuffer ();
InputStreamReader reader = new InputStreamReader (input);
int nextCharacter;
do
{
nextCharacter = reader.read ();
if (nextCharacter == -1) // shouldn't happen given protocol
throw new EOFException ();
if ((char) nextCharacter != DELIMITER)
buffer.append ((char) nextCharacter);
}
while ((char) nextCharacter != DELIMITER);
I hate having to cast nextCharacter, but I suppose that I have no
choice (yes, I can create a char variable and do the cast once, which
I probably will end up doing, but still...)
Thanks in advance.
Rick