Package org.apache.hadoop.util
Class LineReader
java.lang.Object
org.apache.hadoop.util.LineReader
- All Implemented Interfaces:
Closeable,AutoCloseable,IOStatisticsSource
@LimitedPrivate("MapReduce")
@Unstable
public class LineReader
extends Object
implements Closeable, IOStatisticsSource
A class that provides a line reader from an input stream.
Depending on the constructor used, lines will either be terminated by:
- one of the following: '\n' (LF) , '\r' (CR), or '\r\n' (CR+LF).
- or, a custom byte sequence delimiter
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a line reader that reads from the given stream using the default buffer-size (64k).LineReader(InputStream in, byte[] recordDelimiterBytes) Create a line reader that reads from the given stream using the default buffer-size, and using a custom delimiter of array of bytes.LineReader(InputStream in, int bufferSize) Create a line reader that reads from the given stream using the given buffer-size.LineReader(InputStream in, int bufferSize, byte[] recordDelimiterBytes) Create a line reader that reads from the given stream using the given buffer-size, and using a custom delimiter of array of bytes.LineReader(InputStream in, Configuration conf) Create a line reader that reads from the given stream using theio.file.buffer.sizespecified in the givenConfiguration.LineReader(InputStream in, Configuration conf, byte[] recordDelimiterBytes) Create a line reader that reads from the given stream using theio.file.buffer.sizespecified in the givenConfiguration, and using a custom delimiter of array of bytes. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the underlying stream.protected intfillBuffer(InputStream in, byte[] buffer, boolean inDelimiter) protected intprotected intReturn any IOStatistics provided by the source.intRead from the InputStream into the given Text.intRead from the InputStream into the given Text.intRead one line from the InputStream into the given Text.protected void
-
Constructor Details
-
LineReader
Create a line reader that reads from the given stream using the default buffer-size (64k).- Parameters:
in- The input stream
-
LineReader
Create a line reader that reads from the given stream using the given buffer-size.- Parameters:
in- The input streambufferSize- Size of the read buffer
-
LineReader
Create a line reader that reads from the given stream using theio.file.buffer.sizespecified in the givenConfiguration.- Parameters:
in- input streamconf- configuration- Throws:
IOException- raised on errors performing I/O.
-
LineReader
Create a line reader that reads from the given stream using the default buffer-size, and using a custom delimiter of array of bytes.- Parameters:
in- The input streamrecordDelimiterBytes- The delimiter
-
LineReader
Create a line reader that reads from the given stream using the given buffer-size, and using a custom delimiter of array of bytes.- Parameters:
in- The input streambufferSize- Size of the read bufferrecordDelimiterBytes- The delimiter
-
LineReader
public LineReader(InputStream in, Configuration conf, byte[] recordDelimiterBytes) throws IOException Create a line reader that reads from the given stream using theio.file.buffer.sizespecified in the givenConfiguration, and using a custom delimiter of array of bytes.- Parameters:
in- input streamconf- configurationrecordDelimiterBytes- The delimiter- Throws:
IOException- raised on errors performing I/O.
-
-
Method Details
-
close
Close the underlying stream.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException- raised on errors performing I/O.
-
getIOStatistics
Return any IOStatistics provided by the source.- Specified by:
getIOStatisticsin interfaceIOStatisticsSource- Returns:
- IO stats from the input stream.
-
readLine
Read one line from the InputStream into the given Text.- Parameters:
str- the object to store the given line (without newline)maxLineLength- the maximum number of bytes to store into str; the rest of the line is silently discarded.maxBytesToConsume- the maximum number of bytes to consume in this call. This is only a hint, because if the line cross this threshold, we allow it to happen. It can overshoot potentially by as much as one buffer length.- Returns:
- the number of bytes read including the (longest) newline found.
- Throws:
IOException- if the underlying stream throws
-
fillBuffer
- Throws:
IOException
-
readLine
Read from the InputStream into the given Text.- Parameters:
str- the object to store the given linemaxLineLength- the maximum number of bytes to store into str.- Returns:
- the number of bytes read including the newline
- Throws:
IOException- if the underlying stream throws
-
readLine
Read from the InputStream into the given Text.- Parameters:
str- the object to store the given line- Returns:
- the number of bytes read including the newline
- Throws:
IOException- if the underlying stream throws
-
getBufferPosn
protected int getBufferPosn() -
getBufferSize
protected int getBufferSize() -
unsetNeedAdditionalRecordAfterSplit
protected void unsetNeedAdditionalRecordAfterSplit()
-