Re: Mixing text and binary I/O
"Mike Schilling" <mscottschilling@hotmail.com> writes:
/** @returns a character in the range 0 to 65535, or -1 at EOF
* @param moreDecoded returns true if another character is available
without consuming more bytes
*/
int readChar(out boolean moreDecoded);
Possibly, the Java SE way would be to implement the following interface.
I don't think so. An Iterator knows when there's nothing more to return.
Part of the assumption here is that the client knows (based on the protocol
definition) how many characters to ask for before switching back to binary.
There's nothing to tell the Iterator that.
I have not read the whole thread, but was just responding
to what I have quoted. If one wants something like
int readChar( out boolean moreDecoded )
, then this can be done with an iterator.
The ?out? means that ?readChar? tells its client whether there
are more characters by this out-parameter. When you now say
that the client already knows how many charaters will be
coming, you might be talking about something else beyond the
scope of my answer. I was just refering to
int readChar( out boolean moreDecoded )
in isolation.
Unless you mean that each call to readChar() returns an
Iterator<Character>. But that seems awfully cumbersome, both
for the implementation, which has to wrap each decoded char
into a Character and then wrap *that* in an Iterator, and for
the client which has to unwrap each of those..
For a sequence of multiple iterations using an iterator, there
is no need to create a new iterator object for each iteration.
The same iterator object might be reused using "set" instead
of "wrap". This, however, is not possible with
java.lang.Character, because it is immutable.
An iterator object also might implement other methods than
those of the interface "Iterator" to read information from
its client.