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

LineNumberInputStream

extends FilterInputStream
java.lang.Object
   ↳ java.io.InputStream
     ↳ java.io.FilterInputStream
       ↳ java.io.LineNumberInputStream

This class is deprecated.Use LineNumberReader

Class Overview

LineNumberInputStream is a filter class which counts the number of line terminators from the data read from the target InputStream. A line delimiter sequence is determined by '\r', '\n', or '\r\n'. When using read, the sequence is always translated into '\n'.

Summary

[Expand]
Inherited Fields
From class java.io.FilterInputStream
Public Constructors
LineNumberInputStream(InputStream in)
Constructs a new LineNumberInputStream on the InputStream in.
Public Methods
int available()
Returns a int representing the number of bytes that are available before this LineNumberInputStream will block.
int getLineNumber()
Returns a int representing the current line number for this LineNumberInputStream.
void mark(int readlimit)
Set a Mark position in this LineNumberInputStream.
int read(byte[] buffer, int offset, int length)
Reads at most length bytes from this LineNumberInputStream and stores them in byte array buffer starting at offset.
int read()
Reads a single byte from this LineNumberInputStream and returns the result as an int.
void reset()
Reset this LineNumberInputStream to the last marked location.
void setLineNumber(int lineNumber)
Sets the lineNumber of this LineNumberInputStream to the specified lineNumber.
long skip(long count)
Skips count number of bytes in this InputStream.
[Expand]
Inherited Methods
From class java.io.FilterInputStream
From class java.io.InputStream
From class java.lang.Object
From interface java.io.Closeable

Public Constructors

public LineNumberInputStream (InputStream in)

Constructs a new LineNumberInputStream on the InputStream in. All reads are now filtered through this stream and line numbers will be counted for all data read from this Stream.

Parameters
in The non-null InputStream to count line numbers.

Public Methods

public int available ()

Returns a int representing the number of bytes that are available before this LineNumberInputStream will block. This method returns the number of bytes available in the target stream. Since the target input stream may just be a sequence of \r\n characters and this filter only returns \n then available can only guarantee target.available()/2 characters.

Returns
  • int the number of bytes available before blocking.
Throws
IOException If an error occurs in this stream.

public int getLineNumber ()

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

Returns
  • int the current line number.

public void mark (int readlimit)

Set a Mark position in this LineNumberInputStream. The parameter readLimit indicates how many bytes can be read before a mark is invalidated. Sending reset() will reposition the Stream back to the marked position provided readLimit has not been surpassed. The lineNumber count will also be reset to the last marked lineNumber count.

This implementation sets a mark in the target stream.

Parameters
readlimit The number of bytes to be able to read before invalidating the mark.

public int read (byte[] buffer, int offset, int length)

Reads at most length bytes from this LineNumberInputStream and stores them in byte array buffer starting at offset. Answer the number of bytes actually read or -1 if no bytes were read and end of stream was encountered. This implementation reads bytes 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 non-null byte array in which to store the read bytes.
offset the offset in buffer to store the read bytes.
length the maximum number of bytes to store in buffer.
Returns
  • The number of bytes actually read or -1 if end of stream.
Throws
IOException If the stream is already closed or another IOException occurs.
NullPointerException If buffer is null.
IllegalArgumentException If offset or count are out of bounds.

public int read ()

Reads a single byte from this LineNumberInputStream and returns the result as an int. The low-order byte is returned or -1 of the end of stream was encountered. This implementation returns a byte 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'.

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

public void reset ()

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

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

public void setLineNumber (int lineNumber)

Sets the lineNumber of this LineNumberInputStream 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 bytes in this InputStream. Subsequent read()'s will not return these bytes unless reset() is used. This implementation skips count number of bytes in the target stream and increments the lineNumber count as bytes are skipped.

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