org.apache.hadoop.io
Class SequenceFile.Reader

java.lang.Object
  extended by org.apache.hadoop.io.SequenceFile.Reader
All Implemented Interfaces:
Closeable
Enclosing class:
SequenceFile

public static class SequenceFile.Reader
extends Object
implements Closeable

Reads key/value pairs from a sequence-format file.


Constructor Summary
SequenceFile.Reader(FileSystem fs, Path file, Configuration conf)
          Open the named file.
 
Method Summary
 void close()
          Close the file.
 SequenceFile.ValueBytes createValueBytes()
           
 CompressionCodec getCompressionCodec()
          Returns the compression codec of data in this file.
 Object getCurrentValue(Object val)
          Get the 'value' corresponding to the last read 'key'.
 void getCurrentValue(Writable val)
          Get the 'value' corresponding to the last read 'key'.
 Class<?> getKeyClass()
          Returns the class of keys in this file.
 String getKeyClassName()
          Returns the name of the key class.
 SequenceFile.Metadata getMetadata()
          Returns the metadata object of the file
 long getPosition()
          Return the current byte position in the input file.
 Class<?> getValueClass()
          Returns the class of values in this file.
 String getValueClassName()
          Returns the name of the value class.
 boolean isBlockCompressed()
          Returns true if records are block-compressed.
 boolean isCompressed()
          Returns true if values are compressed.
 int next(DataOutputBuffer buffer)
          Deprecated. Call nextRaw(DataOutputBuffer,SequenceFile.ValueBytes).
 Object next(Object key)
          Read the next key in the file, skipping its value.
 boolean next(Writable key)
          Read the next key in the file into key, skipping its value.
 boolean next(Writable key, Writable val)
          Read the next key/value pair in the file into key and val.
 int nextRaw(DataOutputBuffer key, SequenceFile.ValueBytes val)
          Read 'raw' records.
 int nextRawKey(DataOutputBuffer key)
          Read 'raw' keys.
 int nextRawValue(SequenceFile.ValueBytes val)
          Read 'raw' values.
protected  FSDataInputStream openFile(FileSystem fs, Path file, int bufferSize, long length)
          Override this method to specialize the type of FSDataInputStream returned.
 void seek(long position)
          Set the current byte position in the input file.
 void sync(long position)
          Seek to the next sync mark past a given position.
 boolean syncSeen()
          Returns true iff the previous call to next passed a sync mark.
 String toString()
          Returns the name of the file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SequenceFile.Reader

public SequenceFile.Reader(FileSystem fs,
                           Path file,
                           Configuration conf)
                    throws IOException
Open the named file.

Throws:
IOException
Method Detail

openFile

protected FSDataInputStream openFile(FileSystem fs,
                                     Path file,
                                     int bufferSize,
                                     long length)
                              throws IOException
Override this method to specialize the type of FSDataInputStream returned.

Throws:
IOException

close

public void close()
           throws IOException
Close the file.

Specified by:
close in interface Closeable
Throws:
IOException

getKeyClassName

public String getKeyClassName()
Returns the name of the key class.


getKeyClass

public Class<?> getKeyClass()
Returns the class of keys in this file.


getValueClassName

public String getValueClassName()
Returns the name of the value class.


getValueClass

public Class<?> getValueClass()
Returns the class of values in this file.


isCompressed

public boolean isCompressed()
Returns true if values are compressed.


isBlockCompressed

public boolean isBlockCompressed()
Returns true if records are block-compressed.


getCompressionCodec

public CompressionCodec getCompressionCodec()
Returns the compression codec of data in this file.


getMetadata

public SequenceFile.Metadata getMetadata()
Returns the metadata object of the file


getCurrentValue

public void getCurrentValue(Writable val)
                     throws IOException
Get the 'value' corresponding to the last read 'key'.

Parameters:
val - : The 'value' to be read.
Throws:
IOException

getCurrentValue

public Object getCurrentValue(Object val)
                       throws IOException
Get the 'value' corresponding to the last read 'key'.

Parameters:
val - : The 'value' to be read.
Throws:
IOException

next

public boolean next(Writable key)
             throws IOException
Read the next key in the file into key, skipping its value. True if another entry exists, and false at end of file.

Throws:
IOException

next

public boolean next(Writable key,
                    Writable val)
             throws IOException
Read the next key/value pair in the file into key and val. Returns true if such a pair exists and false when at end of file

Throws:
IOException

next

public int next(DataOutputBuffer buffer)
         throws IOException
Deprecated. Call nextRaw(DataOutputBuffer,SequenceFile.ValueBytes).

Throws:
IOException

createValueBytes

public SequenceFile.ValueBytes createValueBytes()

nextRaw

public int nextRaw(DataOutputBuffer key,
                   SequenceFile.ValueBytes val)
            throws IOException
Read 'raw' records.

Parameters:
key - - The buffer into which the key is read
val - - The 'raw' value
Returns:
Returns the total record length or -1 for end of file
Throws:
IOException

nextRawKey

public int nextRawKey(DataOutputBuffer key)
               throws IOException
Read 'raw' keys.

Parameters:
key - - The buffer into which the key is read
Returns:
Returns the key length or -1 for end of file
Throws:
IOException

next

public Object next(Object key)
            throws IOException
Read the next key in the file, skipping its value. Return null at end of file.

Throws:
IOException

nextRawValue

public int nextRawValue(SequenceFile.ValueBytes val)
                 throws IOException
Read 'raw' values.

Parameters:
val - - The 'raw' value
Returns:
Returns the value length
Throws:
IOException

seek

public void seek(long position)
          throws IOException
Set the current byte position in the input file.

The position passed must be a position returned by SequenceFile.Writer.getLength() when writing this file. To seek to an arbitrary position, use sync(long).

Throws:
IOException

sync

public void sync(long position)
          throws IOException
Seek to the next sync mark past a given position.

Throws:
IOException

syncSeen

public boolean syncSeen()
Returns true iff the previous call to next passed a sync mark.


getPosition

public long getPosition()
                 throws IOException
Return the current byte position in the input file.

Throws:
IOException

toString

public String toString()
Returns the name of the file.

Overrides:
toString in class Object


Copyright © 2009 The Apache Software Foundation