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.


Nested Class Summary
static interface SequenceFile.Reader.Option
          A tag interface for all of the Reader options
 
Constructor Summary
SequenceFile.Reader(Configuration conf, SequenceFile.Reader.Option... opts)
           
SequenceFile.Reader(FileSystem fs, Path file, Configuration conf)
          Deprecated. Use Reader(Configuration, Option...) instead.
SequenceFile.Reader(FSDataInputStream in, int buffersize, long start, long length, Configuration conf)
          Deprecated. Use Reader(Configuration, Reader.Option...) instead.
 
Method Summary
static SequenceFile.Reader.Option bufferSize(int value)
          Create an option with the buffer size for reading the given pathname.
 void close()
          Close the file.
 SequenceFile.ValueBytes createValueBytes()
           
static SequenceFile.Reader.Option file(Path value)
          Create an option to specify the path name of the sequence file.
 CompressionCodec getCompressionCodec()
          Returns the compression codec of data in this file.
 SequenceFile.CompressionType getCompressionType()
          Get the compression type for 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.
static SequenceFile.Reader.Option length(long value)
          Create an option to specify the number of bytes to read.
 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(org.apache.hadoop.io.DataOutputBuffer key, SequenceFile.ValueBytes val)
          Read 'raw' records.
 int nextRawKey(org.apache.hadoop.io.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.
static SequenceFile.Reader.Option start(long value)
          Create an option to specify the starting byte to read.
static SequenceFile.Reader.Option stream(FSDataInputStream value)
          Create an option to specify the stream with the sequence 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(Configuration conf,
                           SequenceFile.Reader.Option... opts)
                    throws IOException
Throws:
IOException

SequenceFile.Reader

@Deprecated
public SequenceFile.Reader(FileSystem fs,
                                      Path file,
                                      Configuration conf)
                    throws IOException
Deprecated. Use Reader(Configuration, Option...) instead.

Construct a reader by opening a file from the given file system.

Parameters:
fs - The file system used to open the file.
file - The file being read.
conf - Configuration
Throws:
IOException

SequenceFile.Reader

@Deprecated
public SequenceFile.Reader(FSDataInputStream in,
                                      int buffersize,
                                      long start,
                                      long length,
                                      Configuration conf)
                    throws IOException
Deprecated. Use Reader(Configuration, Reader.Option...) instead.

Construct a reader by the given input stream.

Parameters:
in - An input stream.
buffersize - unused
start - The starting position.
length - The length being read.
conf - Configuration
Throws:
IOException
Method Detail

file

public static SequenceFile.Reader.Option file(Path value)
Create an option to specify the path name of the sequence file.

Parameters:
value - the path to read
Returns:
a new option

stream

public static SequenceFile.Reader.Option stream(FSDataInputStream value)
Create an option to specify the stream with the sequence file.

Parameters:
value - the stream to read.
Returns:
a new option

start

public static SequenceFile.Reader.Option start(long value)
Create an option to specify the starting byte to read.

Parameters:
value - the number of bytes to skip over
Returns:
a new option

length

public static SequenceFile.Reader.Option length(long value)
Create an option to specify the number of bytes to read.

Parameters:
value - the number of bytes to read
Returns:
a new option

bufferSize

public static SequenceFile.Reader.Option bufferSize(int value)
Create an option with the buffer size for reading the given pathname.

Parameters:
value - the number of bytes to buffer
Returns:
a new option

openFile

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

Parameters:
fs - The file system used to open the file.
file - The file being read.
bufferSize - The buffer size used to read the file.
length - The length being read if it is >= 0. Otherwise, the length is not available.
Returns:
The opened stream.
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.


getCompressionType

public SequenceFile.CompressionType getCompressionType()
Get the compression type for this file.

Returns:
the compression type

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

createValueBytes

public SequenceFile.ValueBytes createValueBytes()

nextRaw

public int nextRaw(org.apache.hadoop.io.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(org.apache.hadoop.io.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 © 2013 Apache Software Foundation. All Rights Reserved.