org.apache.hadoop.fs
Class FSDataInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by java.io.FilterInputStream
          extended by java.io.DataInputStream
              extended by org.apache.hadoop.fs.FSDataInputStream
All Implemented Interfaces:
Closeable, DataInput, HasFileDescriptor, PositionedReadable, Seekable

public class FSDataInputStream
extends DataInputStream
implements Seekable, PositionedReadable, Closeable, HasFileDescriptor

Utility that wraps a FSInputStream in a DataInputStream and buffers input through a BufferedInputStream.


Field Summary
 
Fields inherited from class java.io.FilterInputStream
in
 
Constructor Summary
FSDataInputStream(InputStream in)
           
 
Method Summary
 FileDescriptor getFileDescriptor()
           
 long getPos()
          Return the current offset from the start of the file
 int read(long position, byte[] buffer, int offset, int length)
          Read upto the specified number of bytes, from a given position within a file, and return the number of bytes read.
 void readFully(long position, byte[] buffer)
          Read number of bytes equalt to the length of the buffer, from a given position within a file.
 void readFully(long position, byte[] buffer, int offset, int length)
          Read the specified number of bytes, from a given position within a file.
 void seek(long desired)
          Seek to the given offset from the start of the file.
 boolean seekToNewSource(long targetPos)
          Seeks a different copy of the data.
 
Methods inherited from class java.io.DataInputStream
read, read, readBoolean, readByte, readChar, readDouble, readFloat, readFully, readFully, readInt, readLine, readLong, readShort, readUnsignedByte, readUnsignedShort, readUTF, readUTF, skipBytes
 
Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.io.Closeable
close
 

Constructor Detail

FSDataInputStream

public FSDataInputStream(InputStream in)
                  throws IOException
Throws:
IOException
Method Detail

seek

public void seek(long desired)
          throws IOException
Description copied from interface: Seekable
Seek to the given offset from the start of the file. The next read() will be from that location. Can't seek past the end of the file.

Specified by:
seek in interface Seekable
Throws:
IOException

getPos

public long getPos()
            throws IOException
Description copied from interface: Seekable
Return the current offset from the start of the file

Specified by:
getPos in interface Seekable
Throws:
IOException

read

public int read(long position,
                byte[] buffer,
                int offset,
                int length)
         throws IOException
Description copied from interface: PositionedReadable
Read upto the specified number of bytes, from a given position within a file, and return the number of bytes read. This does not change the current offset of a file, and is thread-safe.

Specified by:
read in interface PositionedReadable
Throws:
IOException

readFully

public void readFully(long position,
                      byte[] buffer,
                      int offset,
                      int length)
               throws IOException
Description copied from interface: PositionedReadable
Read the specified number of bytes, from a given position within a file. This does not change the current offset of a file, and is thread-safe.

Specified by:
readFully in interface PositionedReadable
Throws:
IOException

readFully

public void readFully(long position,
                      byte[] buffer)
               throws IOException
Description copied from interface: PositionedReadable
Read number of bytes equalt to the length of the buffer, from a given position within a file. This does not change the current offset of a file, and is thread-safe.

Specified by:
readFully in interface PositionedReadable
Throws:
IOException

seekToNewSource

public boolean seekToNewSource(long targetPos)
                        throws IOException
Description copied from interface: Seekable
Seeks a different copy of the data. Returns true if found a new source, false otherwise.

Specified by:
seekToNewSource in interface Seekable
Throws:
IOException

getFileDescriptor

public FileDescriptor getFileDescriptor()
                                 throws IOException
Specified by:
getFileDescriptor in interface HasFileDescriptor
Returns:
the FileDescriptor
Throws:
IOException


Copyright © 2009 The Apache Software Foundation