org.apache.hadoop.util
Class LineReader

java.lang.Object
  extended by org.apache.hadoop.util.LineReader
Direct Known Subclasses:
LineRecordReader.LineReader

public class LineReader
extends Object

A class that provides a line reader from an input stream.


Constructor Summary
LineReader(InputStream in)
          Create a line reader that reads from the given stream using the default buffer-size (64k).
LineReader(InputStream in, Configuration conf)
          Create a line reader that reads from the given stream using the io.file.buffer.size specified in the given Configuration.
LineReader(InputStream in, int bufferSize)
          Create a line reader that reads from the given stream using the given buffer-size.
 
Method Summary
 void close()
          Close the underlying stream.
 int readLine(Text str)
          Read from the InputStream into the given Text.
 int readLine(Text str, int maxLineLength)
          Read from the InputStream into the given Text.
 int readLine(Text str, int maxLineLength, int maxBytesToConsume)
          Read one line from the InputStream into the given Text.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LineReader

public LineReader(InputStream in)
Create a line reader that reads from the given stream using the default buffer-size (64k).

Parameters:
in - The input stream
Throws:
IOException

LineReader

public LineReader(InputStream in,
                  int bufferSize)
Create a line reader that reads from the given stream using the given buffer-size.

Parameters:
in - The input stream
bufferSize - Size of the read buffer
Throws:
IOException

LineReader

public LineReader(InputStream in,
                  Configuration conf)
           throws IOException
Create a line reader that reads from the given stream using the io.file.buffer.size specified in the given Configuration.

Parameters:
in - input stream
conf - configuration
Throws:
IOException
Method Detail

close

public void close()
           throws IOException
Close the underlying stream.

Throws:
IOException

readLine

public int readLine(Text str,
                    int maxLineLength,
                    int maxBytesToConsume)
             throws IOException
Read one line from the InputStream into the given Text. A line can be terminated by one of the following: '\n' (LF) , '\r' (CR), or '\r\n' (CR+LF). EOF also terminates an otherwise unterminated line.

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

readLine

public int readLine(Text str,
                    int maxLineLength)
             throws IOException
Read from the InputStream into the given Text.

Parameters:
str - the object to store the given line
maxLineLength - 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

public int readLine(Text str)
             throws IOException
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


Copyright © 2009 The Apache Software Foundation