The class BuffedInputStream provides the ability to read from a stream without consuming it. A MarkReachedException is thrown if more bytes are read than the stream contains.
BuffedInputStream
MarkReachedException