[2277] in java-interest
peek() into a stream lately?
daemon@ATHENA.MIT.EDU (Russell Ethington)
Wed Sep 27 18:45:32 1995
Date: Wed, 27 Sep 95 16:46:41 EDT
From: rethingt@lehman.com (Russell Ethington)
To: java-interest@java.sun.com
Cc: rethingt@lehman.com
I've been digging through the various input stream classes looking
for a way to peek() at my NetworkClient's serverInput stream without
taking bytes out of it. PushbackInputStream looked promising until I
saw the source (in 1.0Alpha3).
Using mark() and reset() would work, but they aren't implemented for
the SocketInputStream. So, should I:
1) Make a BufferedInputStream from a SocketInputStream and use
mark() and reset()?
2) Write something that extends FilterInputStream, implement peek(),
and override read() to insert a peeked byte when appropriate?
3) Jump out a window because I'm missing something really obvious
and should be programming in Cobol?
There must be a better way than:
public class PeekableStream extends BufferedInputStream
{
PeekableStream(InputStream in)
{
super(in);
}
public int peek()
{
mark();
int it = read();
reset();
return(it);
}
}
Having gobs of fun,
-r
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com