Class SequenceFile.Reader

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

public static class SequenceFile.Reader extends Object implements Closeable
Reads key/value pairs from a sequence-format file.
  • Constructor Details

    • Reader

      public Reader(Configuration conf, SequenceFile.Reader.Option... opts) throws IOException
      Throws:
      IOException
    • Reader

      @Deprecated public 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 - raised on errors performing I/O.
    • Reader

      @Deprecated public 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 - raised on errors performing I/O.
  • Method Details

    • 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 - raised on errors performing I/O.
    • close

      public void close() throws IOException
      Close the file.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • getKeyClassName

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

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

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

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

      public boolean isCompressed()
      Returns true if values are compressed.
      Returns:
      if values are compressed true, not false.
    • isBlockCompressed

      public boolean isBlockCompressed()
      Returns true if records are block-compressed.
      Returns:
      if records are block-compressed true, not false.
    • getCompressionCodec

      public CompressionCodec getCompressionCodec()
      Returns the compression codec of data in this file.
      Returns:
      CompressionCodec.
    • 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.
      Returns:
      metadata.
    • 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 - raised on errors performing I/O.
    • getCurrentValue

      public Object getCurrentValue(Object val) throws IOException
      Parameters:
      val - : The 'value' to be read.
      Returns:
      Get the 'value' corresponding to the last read 'key'.
      Throws:
      IOException - raised on errors performing I/O.
    • next

      public boolean next(Writable key) throws IOException
      Parameters:
      key - key.
      Returns:
      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 - raised on errors performing I/O.
    • next

      public boolean next(Writable key, Writable val) throws IOException
      Read the next key/value pair in the file into key and val.
      Parameters:
      key - input key.
      val - input val.
      Returns:
      Returns true if such a pair exists and false when at end of file.
      Throws:
      IOException - raised on errors performing I/O.
    • 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 - raised on errors performing I/O.
    • 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 - raised on errors performing I/O.
    • next

      public Object next(Object key) throws IOException
      Read the next key in the file, skipping its value.
      Parameters:
      key - input Object key.
      Returns:
      Return null at end of file.
      Throws:
      IOException - raised on errors performing I/O.
    • nextRawValue

      public int nextRawValue(SequenceFile.ValueBytes val) throws IOException
      Read 'raw' values.
      Parameters:
      val - - The 'raw' value
      Returns:
      Returns the value length
      Throws:
      IOException - raised on errors performing I/O.
    • 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).

      Parameters:
      position - input position.
      Throws:
      IOException - raised on errors performing I/O.
    • sync

      public void sync(long position) throws IOException
      Seek to the next sync mark past a given position.
      Parameters:
      position - position.
      Throws:
      IOException - raised on errors performing I/O.
    • syncSeen

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

      public long getPosition() throws IOException
      Returns:
      Return the current byte position in the input file.
      Throws:
      IOException - raised on errors performing I/O.
    • toString

      public String toString()
      Returns the name of the file.
      Overrides:
      toString in class Object