org.apache.hadoop.hdfs
Class DFSInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.apache.hadoop.fs.FSInputStream
          extended by org.apache.hadoop.hdfs.DFSInputStream
All Implemented Interfaces:
Closeable, org.apache.hadoop.fs.PositionedReadable, org.apache.hadoop.fs.Seekable

@InterfaceAudience.Private
public class DFSInputStream
extends org.apache.hadoop.fs.FSInputStream

DFSInputStream provides bytes from a named file. It handles negotiation of the namenode and various datanodes as necessary.


Method Summary
 int available()
          Return the size of the remaining available bytes if the size is less than or equal to Integer.MAX_VALUE, otherwise, return Integer.MAX_VALUE.
 void close()
          Close it down!
protected  BlockReader getBlockReader(InetSocketAddress dnAddr, String file, Block block, org.apache.hadoop.security.token.Token<BlockTokenIdentifier> blockToken, long startOffset, long len, int bufferSize, boolean verifyChecksum, String clientName)
          Retrieve a BlockReader suitable for reading.
 Block getCurrentBlock()
          Returns the block containing the target position.
 DatanodeInfo getCurrentDatanode()
          Returns the datanode from which the stream is currently reading.
 long getFileLength()
           
 long getPos()
           
 void mark(int readLimit)
           
 boolean markSupported()
          We definitely don't support marks
 int read()
           
 int read(byte[] buf, int off, int len)
          Read the entire buffer.
 int read(long position, byte[] buffer, int offset, int length)
          Read bytes starting from the specified position.
 void reset()
           
 void seek(long targetPos)
          Seek to a new arbitrary location
 boolean seekToNewSource(long targetPos)
          Seek to given position on a node other than the current node.
 long skip(long n)
           
 
Methods inherited from class org.apache.hadoop.fs.FSInputStream
readFully, readFully
 
Methods inherited from class java.io.InputStream
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getFileLength

public long getFileLength()

getCurrentDatanode

public DatanodeInfo getCurrentDatanode()
Returns the datanode from which the stream is currently reading.


getCurrentBlock

public Block getCurrentBlock()
Returns the block containing the target position.


close

public void close()
           throws IOException
Close it down!

Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] buf,
                int off,
                int len)
         throws IOException
Read the entire buffer.

Overrides:
read in class InputStream
Throws:
IOException

getBlockReader

protected BlockReader getBlockReader(InetSocketAddress dnAddr,
                                     String file,
                                     Block block,
                                     org.apache.hadoop.security.token.Token<BlockTokenIdentifier> blockToken,
                                     long startOffset,
                                     long len,
                                     int bufferSize,
                                     boolean verifyChecksum,
                                     String clientName)
                              throws IOException
Retrieve a BlockReader suitable for reading. This method will reuse the cached connection to the DN if appropriate. Otherwise, it will create a new connection.

Parameters:
dnAddr - Address of the datanode
file - File location
block - The Block object
blockToken - The access token for security
startOffset - The read offset, relative to block head
len - The number of bytes to read
bufferSize - The IO buffer size (not the client buffer size)
verifyChecksum - Whether to verify checksum
clientName - Client name
Returns:
New BlockReader instance
Throws:
IOException

read

public int read(long position,
                byte[] buffer,
                int offset,
                int length)
         throws IOException
Read bytes starting from the specified position.

Specified by:
read in interface org.apache.hadoop.fs.PositionedReadable
Overrides:
read in class org.apache.hadoop.fs.FSInputStream
Parameters:
position - start read from this position
buffer - read buffer
offset - offset into buffer
length - number of bytes to read
Returns:
actual number of bytes read
Throws:
IOException

skip

public long skip(long n)
          throws IOException
Overrides:
skip in class InputStream
Throws:
IOException

seek

public void seek(long targetPos)
          throws IOException
Seek to a new arbitrary location

Specified by:
seek in interface org.apache.hadoop.fs.Seekable
Specified by:
seek in class org.apache.hadoop.fs.FSInputStream
Throws:
IOException

seekToNewSource

public boolean seekToNewSource(long targetPos)
                        throws IOException
Seek to given position on a node other than the current node. If a node other than the current node is found, then returns true. If another node could not be found, then returns false.

Specified by:
seekToNewSource in interface org.apache.hadoop.fs.Seekable
Specified by:
seekToNewSource in class org.apache.hadoop.fs.FSInputStream
Throws:
IOException

getPos

public long getPos()
            throws IOException
Specified by:
getPos in interface org.apache.hadoop.fs.Seekable
Specified by:
getPos in class org.apache.hadoop.fs.FSInputStream
Throws:
IOException

available

public int available()
              throws IOException
Return the size of the remaining available bytes if the size is less than or equal to Integer.MAX_VALUE, otherwise, return Integer.MAX_VALUE.

Overrides:
available in class InputStream
Throws:
IOException

markSupported

public boolean markSupported()
We definitely don't support marks

Overrides:
markSupported in class InputStream

mark

public void mark(int readLimit)
Overrides:
mark in class InputStream

reset

public void reset()
           throws IOException
Overrides:
reset in class InputStream
Throws:
IOException


Copyright © 2009 The Apache Software Foundation