org.apache.flume.serialization
Class ResettableFileInputStream

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

@InterfaceAudience.Private
@InterfaceStability.Evolving
public class ResettableFileInputStream
extends ResettableInputStream
implements RemoteMarkable, LengthMeasurable

This class makes the following assumptions:

  1. The underlying file is not changing while it is being read

The ability to reset() is dependent on the underlying PositionTracker instance's durability semantics.


Field Summary
static int DEFAULT_BUF_SIZE
           
 
Constructor Summary
ResettableFileInputStream(File file, PositionTracker tracker)
           
ResettableFileInputStream(File file, PositionTracker tracker, int bufSize, Charset charset)
           
 
Method Summary
 void close()
           
 long getMarkPosition()
          Return the saved mark position without moving the mark pointer.
 long length()
          returns the total length of the stream or file
 void mark()
          Marks the current position in this input stream.
 void markPosition(long position)
          Indicate that the specified position should be returned to in the case of Resettable.reset() being called.
 int read()
          Read a single byte of data from the stream.
 int read(byte[] b, int off, int len)
          Read multiple bytes of data from the stream.
 int readChar()
          Read a single character.
 void reset()
          Reset stream position to that set by ResettableInputStream.mark()
 void seek(long newPos)
          Seek to the specified byte position in the stream.
 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
 

Field Detail

DEFAULT_BUF_SIZE

public static final int DEFAULT_BUF_SIZE
See Also:
Constant Field Values
Constructor Detail

ResettableFileInputStream

public ResettableFileInputStream(File file,
                                 PositionTracker tracker)
                          throws IOException
Parameters:
file - File to read
tracker - PositionTracker implementation to make offset position durable
Throws:
FileNotFoundException
IOException

ResettableFileInputStream

public ResettableFileInputStream(File file,
                                 PositionTracker tracker,
                                 int bufSize,
                                 Charset charset)
                          throws IOException
Parameters:
file - File to read
tracker - PositionTracker implementation to make offset position durable
bufSize - Size of the underlying buffer used for input
charset - Character set used for decoding text, as necessary
Throws:
FileNotFoundException
IOException
Method Detail

read

public int read()
         throws IOException
Description copied from class: ResettableInputStream
Read a single byte of data from the stream.

Specified by:
read in class ResettableInputStream
Returns:
the next byte of data, or -1 if the end of the stream has been reached.
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Description copied from class: ResettableInputStream
Read multiple bytes of data from the stream.

Specified by:
read in class ResettableInputStream
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 int readChar()
             throws IOException
Description copied from class: ResettableInputStream

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.

Specified by:
readChar in class ResettableInputStream
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 void mark()
          throws IOException
Description copied from class: ResettableInputStream
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
Specified by:
mark in class ResettableInputStream
Throws:
IOException - If there is an error while setting the mark position.
See Also:
InputStream.mark(int), InputStream.reset()

markPosition

public void markPosition(long position)
                  throws IOException
Description copied from interface: RemoteMarkable
Indicate that the specified position should be returned to in the case of Resettable.reset() being called.

Specified by:
markPosition in interface RemoteMarkable
Throws:
IOException

getMarkPosition

public long getMarkPosition()
                     throws IOException
Description copied from interface: RemoteMarkable
Return the saved mark position without moving the mark pointer.

Specified by:
getMarkPosition in interface RemoteMarkable
Throws:
IOException

reset

public void reset()
           throws IOException
Description copied from class: ResettableInputStream
Reset stream position to that set by ResettableInputStream.mark()

Specified by:
reset in interface Resettable
Specified by:
reset in class ResettableInputStream
Throws:
IOException

length

public long length()
            throws IOException
Description copied from interface: LengthMeasurable
returns the total length of the stream or file

Specified by:
length in interface LengthMeasurable
Throws:
IOException

tell

public long tell()
          throws IOException
Description copied from class: ResettableInputStream
Tell the current byte position.

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

seek

public void seek(long newPos)
          throws IOException
Description copied from class: ResettableInputStream
Seek to the specified byte position in the stream.

Specified by:
seek in interface Seekable
Specified by:
seek in class ResettableInputStream
Parameters:
newPos - Absolute byte offset to seek to
Throws:
IOException

close

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


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