加载中...
The Wayback Machine - https://sup1a9wrlpyh5li9ro.vcoronado.top/web/20090321133107/http://developer.android.com:80/reference/java/io/LineNumberReader.html
public class

LineNumberReader

extends BufferedReader
java.lang.Object
   ↳ java.io.Reader
     ↳ java.io.BufferedReader
       ↳ java.io.LineNumberReader

Class Overview

LineNumberReader is a buffered character input reader which counts line numbers as data is being read. The line number starts at 0 and is incremented any time '\r', '\n', or '\r\n' is read.

See Also

Summary

[Expand]
Inherited Fields
From class java.io.Reader
Public Constructors
LineNumberReader(Reader in)
Constructs a new buffered LineNumberReader on the Reader in.
LineNumberReader(Reader in, int size)
Constructs a new buffered LineNumberReader on the Reader in.
Public Methods
int getLineNumber()
Returns a int representing the current line number for this LineNumberReader.
void mark(int readlimit)
Set a Mark position in this LineNumberReader.
int read(char[] buffer, int offset, int count)
Reads at most count chars from this LineNumberReader and stores them in char array buffer starting at offset offset.
int read()
Reads a single char from this LineNumberReader and returns the result as an int.
String readLine()
Returns a String representing the next line of text available in this LineNumberReader.
void reset()
Reset this LineNumberReader to the last marked location.
void setLineNumber(int lineNumber)
Sets the lineNumber of this LineNumberReader to the specified lineNumber.
long skip(long count)
Skips count number of chars in this LineNumberReader.
[Expand]
Inherited Methods
From class java.io.BufferedReader
From class java.io.Reader
From class java.lang.Object
From interface java.io.Closeable
From interface java.lang.Readable

Public Constructors

public LineNumberReader (Reader in)

Constructs a new buffered LineNumberReader on the Reader in. The default buffer size (8K) is allocated and all reads can now be filtered through this LineNumberReader.

Parameters
in the Reader to buffer reads on.

public LineNumberReader (Reader in, int size)

Constructs a new buffered LineNumberReader on the Reader in. The buffer size is specified by the parameter size and all reads can now be filtered through this LineNumberReader.

Parameters
in the Reader to buffer reads on.
size the size of buffer to allocate.

Public Methods

public int getLineNumber ()

Returns a int representing the current line number for this LineNumberReader.

Returns
  • int the current line number.

public void mark (int readlimit)

Set a Mark position in this LineNumberReader. The parameter readLimit indicates how many characters can be read before a mark is invalidated. Sending reset() will reposition the reader back to the marked position provided readLimit has not been surpassed. The lineNumber associated with this marked position will also be saved and restored when reset() is sent provided readLimit has not been surpassed.

Parameters
readlimit an int representing how many characters must be read before invalidating the mark.
Throws
IOException If an error occurs attempting mark this LineNumberReader.

public int read (char[] buffer, int offset, int count)

Reads at most count chars from this LineNumberReader and stores them in char array buffer starting at offset offset. Answer the number of chars actually read or -1 if no chars were read and end of reader was encountered. This implementation reads chars from the target stream. The line number count is incremented if a line terminator is encountered. A line delimiter sequence is determined by '\r', '\n', or '\r\n'. In this method, the sequence is always translated into '\n'.

Parameters
buffer the char array in which to store the read chars.
offset the offset in buffer to store the read chars.
count the maximum number of chars to store in buffer.
Returns
  • the number of chars actually read or -1 if end of reader.
Throws
IOException If the reader is already closed or another IOException occurs.

public int read ()

Reads a single char from this LineNumberReader and returns the result as an int. The low-order 2 bytes are returned or -1 of the end of reader was encountered. This implementation returns a char from the target reader. The line number count is incremented if a line terminator is encountered. A line delimiter sequence is determined by '\r', '\n', or '\r\n'. In this method, the sequence is always translated into '\n'.

Returns
  • int The char read or -1 if end of reader.
Throws
IOException If the reader is already closed or another IOException occurs.

public String readLine ()

Returns a String representing the next line of text available in this LineNumberReader. A line is represented by 0 or more characters followed by '\n', '\r', "\n\r" or end of stream. The String does not include the newline sequence.

Returns
  • String the contents of the line or null if no characters were read before end of stream.
Throws
IOException If the LineNumberReader is already closed or some other IO error occurs.

public void reset ()

Reset this LineNumberReader to the last marked location. If the readlimit has been passed or no mark has been set, throw IOException. This implementation resets the target reader. It also resets the line count to what is was when this reader was marked.

Throws
IOException If the reader is already closed or another IOException occurs.

public void setLineNumber (int lineNumber)

Sets the lineNumber of this LineNumberReader to the specified lineNumber. Note that this may have side effects on the line number associated with the last marked position.

Parameters
lineNumber the new lineNumber value.

public long skip (long count)

Skips count number of chars in this LineNumberReader. Subsequent read()'s will not return these chars unless reset() is used. This implementation skips count number of chars in the target stream and increments the lineNumber count as chars are skipped.

Parameters
count the number of chars to skip.
Returns
  • the number of chars actually skipped.
Throws
IOException If the reader is already closed or another IOException occurs.