Package org.apache.hadoop.io
Class SequenceFile.Reader
java.lang.Object
org.apache.hadoop.io.SequenceFile.Reader
- All Implemented Interfaces:
Closeable,AutoCloseable
- Enclosing class:
- SequenceFile
Reads key/value pairs from a sequence-format file.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA tag interface for all of the Reader options -
Constructor Summary
ConstructorsConstructorDescriptionReader(Configuration conf, SequenceFile.Reader.Option... opts) Reader(FileSystem fs, Path file, Configuration conf) Deprecated.Use Reader(Configuration, Option...) instead.Reader(FSDataInputStream in, int buffersize, long start, long length, Configuration conf) Deprecated.Use Reader(Configuration, Reader.Option...) instead. -
Method Summary
Modifier and TypeMethodDescriptionstatic SequenceFile.Reader.OptionbufferSize(int value) Create an option with the buffer size for reading the given pathname.voidclose()Close the file.static SequenceFile.Reader.OptionCreate an option to specify the path name of the sequence file.Returns the compression codec of data in this file.Get the compression type for this file.getCurrentValue(Object val) voidgetCurrentValue(Writable val) Get the 'value' corresponding to the last read 'key'.Class<?>Returns the metadata object of the file.longClass<?>booleanReturns true if records are block-compressed.booleanReturns true if values are compressed.static SequenceFile.Reader.Optionlength(long value) Create an option to specify the number of bytes to read.Read the next key in the file, skipping its value.booleanbooleanRead the next key/value pair in the file intokeyandval.intnextRaw(DataOutputBuffer key, SequenceFile.ValueBytes val) Read 'raw' records.intRead 'raw' keys.intRead 'raw' values.protected FSDataInputStreamopenFile(FileSystem fs, Path file, int bufferSize, long length) Override this method to specialize the type ofFSDataInputStreamreturned.voidseek(long position) Set the current byte position in the input file.static SequenceFile.Reader.Optionstart(long value) Create an option to specify the starting byte to read.static SequenceFile.Reader.Optionstream(FSDataInputStream value) Create an option to specify the stream with the sequence file.voidsync(long position) Seek to the next sync mark past a given position.booleansyncSeen()toString()Returns the name of the file.
-
Constructor Details
-
Reader
- Throws:
IOException
-
Reader
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- unusedstart- The starting position.length- The length being read.conf- Configuration- Throws:
IOException- raised on errors performing I/O.
-
-
Method Details
-
file
Create an option to specify the path name of the sequence file.- Parameters:
value- the path to read- Returns:
- a new option
-
stream
Create an option to specify the stream with the sequence file.- Parameters:
value- the stream to read.- Returns:
- a new option
-
start
Create an option to specify the starting byte to read.- Parameters:
value- the number of bytes to skip over- Returns:
- a new option
-
length
Create an option to specify the number of bytes to read.- Parameters:
value- the number of bytes to read- Returns:
- a new option
-
bufferSize
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 ofFSDataInputStreamreturned.- 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
Close the file.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getKeyClassName
- Returns:
- Returns the name of the key class.
-
getKeyClass
- Returns:
- Returns the class of keys in this file.
-
getValueClassName
- Returns:
- Returns the name of the value 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
Returns the compression codec of data in this file.- Returns:
- CompressionCodec.
-
getCompressionType
Get the compression type for this file.- Returns:
- the compression type
-
getMetadata
Returns the metadata object of the file.- Returns:
- metadata.
-
getCurrentValue
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
- 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
- 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
Read the next key/value pair in the file intokeyandval.- 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
-
nextRaw
Read 'raw' records.- Parameters:
key- - The buffer into which the key is readval- - The 'raw' value- Returns:
- Returns the total record length or -1 for end of file
- Throws:
IOException- raised on errors performing I/O.
-
nextRawKey
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
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
Read 'raw' values.- Parameters:
val- - The 'raw' value- Returns:
- Returns the value length
- Throws:
IOException- raised on errors performing I/O.
-
seek
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, usesync(long).- Parameters:
position- input position.- Throws:
IOException- raised on errors performing I/O.
-
sync
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
- Returns:
- Return the current byte position in the input file.
- Throws:
IOException- raised on errors performing I/O.
-
toString
Returns the name of the file.
-