public class TailStream extends FilterInputStream
A specialized input stream implementation which records the last portion read from an underlying stream.
This stream implementation is useful to deal with information which is known to be located at the end of a stream (e.g. ID3 v1 tags). While reading bytes from the underlying stream, a given number of bytes is kept in an internal buffer. This buffer can then be queried after the whole stream was read. It contains the last bytes read from the original input stream.
in
Constructor and Description |
---|
TailStream(InputStream in,
int size)
Creates a new instance of
TailStream . |
Modifier and Type | Method and Description |
---|---|
byte[] |
getTail()
Returns an array with the last data read from the underlying stream.
|
void |
mark(int limit)
This implementation saves the internal state including the
content of the tail buffer so that it can be restored when ''reset()'' is
called later.
|
int |
read()
This implementation adds the read byte to the internal tail
buffer.
|
int |
read(byte[] buf)
This implementation delegates to the underlying stream and
then adds the correct portion of the read buffer to the internal tail
buffer.
|
int |
read(byte[] buf,
int ofs,
int length)
This implementation delegates to the underlying stream and
then adds the correct portion of the read buffer to the internal tail
buffer.
|
void |
reset()
This implementation restores this stream's state to the
state when ''mark()'' was called the last time.
|
long |
skip(long n)
This implementation delegates to the
read() method
to ensure that the tail buffer is also filled if data is skipped. |
available, close, markSupported
public TailStream(InputStream in, int size)
TailStream
.in
- the underlying input streamsize
- the size of the tail bufferpublic int read() throws IOException
read
in class FilterInputStream
IOException
public int read(byte[] buf) throws IOException
read
in class FilterInputStream
IOException
public int read(byte[] buf, int ofs, int length) throws IOException
read
in class FilterInputStream
IOException
public long skip(long n) throws IOException
read()
method
to ensure that the tail buffer is also filled if data is skipped.skip
in class FilterInputStream
IOException
public void mark(int limit)
mark
in class FilterInputStream
public void reset()
reset
in class FilterInputStream
public byte[] getTail()
Copyright © 2007–2017 The Apache Software Foundation. All rights reserved.