org.apache.flume.serialization
Class ResettableInputStream

java.lang.Object
  extended by org.apache.flume.serialization.ResettableInputStream
All Implemented Interfaces:
Closeable, Resettable, Seekable
Direct Known Subclasses:
ResettableFileInputStream

@InterfaceAudience.Public
@InterfaceStability.Unstable
public abstract class ResettableInputStream
extends Object
implements Resettable, Seekable, Closeable

This abstract class defines an interface for which the stream may be marked and reset with no limit to the number of bytes which may have been read between the calls.

Any implementation of this interface guarantees that the mark position will not be invalidated by reading any number of bytes.

Warning: We reserve the right to add public methods to this class in the future. Third-party subclasses beware.


Constructor Summary
ResettableInputStream()
           
 
Method Summary
abstract  void close()
           
abstract  void mark()
          Marks the current position in this input stream.
abstract  int read()
          Read a single byte of data from the stream.
abstract  int read(byte[] b, int off, int len)
          Read multiple bytes of data from the stream.
abstract  int readChar()
          Read a single character.
abstract  void reset()
          Reset stream position to that set by mark()
abstract  void seek(long position)
          Seek to the specified byte position in the stream.
abstract  long tell()
          Tell the current byte position.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResettableInputStream

public ResettableInputStream()
Method Detail

read

public abstract int read()
                  throws IOException
Read a single byte of data from the stream.

Returns:
the next byte of data, or -1 if the end of the stream has been reached.
Throws:
IOException

read

public abstract int read(byte[] b,
                         int off,
                         int len)
                  throws IOException
Read multiple bytes of data from the stream.

Parameters:
b - the buffer into which the data is read.
off - Offset into the array b at which the data is written.
len - the maximum number of bytes to read.
Returns:
the total number of bytes read into the buffer, or -1 if the end of the stream has been reached.
Throws:
IOException

readChar

public abstract int readChar()
                      throws IOException

Read a single character.

Note that this may lead to returning only one character in a 2-char surrogate pair sequence. When this happens, the underlying implementation should never persist a mark between two chars of a two-char surrogate pair sequence.

Returns:
The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached
Throws:
IOException

mark

public abstract void mark()
                   throws IOException
Marks the current position in this input stream. A subsequent call to the reset method repositions this stream at the last marked position so that subsequent reads re-read the same bytes.

Marking a closed stream should not have any effect on the stream.

Specified by:
mark in interface Resettable
Throws:
IOException - If there is an error while setting the mark position.
See Also:
InputStream.mark(int), InputStream.reset()

reset

public abstract void reset()
                    throws IOException
Reset stream position to that set by mark()

Specified by:
reset in interface Resettable
Throws:
IOException

seek

public abstract void seek(long position)
                   throws IOException
Seek to the specified byte position in the stream.

Specified by:
seek in interface Seekable
Parameters:
position - Absolute byte offset to seek to
Throws:
IOException

tell

public abstract long tell()
                   throws IOException
Tell the current byte position.

Specified by:
tell in interface Seekable
Returns:
the current absolute byte position in the stream
Throws:
IOException

close

public abstract void close()
                    throws IOException
Specified by:
close in interface Closeable
Throws:
IOException


Copyright © 2009-2015 Apache Software Foundation. All Rights Reserved.