@Deprecated public class LineNumberInputStream extends FilterInputStream
一条线是一个序列的最后一个回车符字节('\r'
)、换行符('\n'
),或一个回车符后面紧跟一个换行字符。在所有三例,行结束符(S)是作为一个单一的换行符返回。
线数始于0
,并加1
当read
返回一个换行符。
LineNumberReader
in
Constructor and Description |
---|
LineNumberInputStream(InputStream in)
过时的。
构建了一个换行符号输入流读取输入从指定的输入流。
|
Modifier and Type | Method and Description |
---|---|
int |
available()
过时的。
返回可以从这个输入流中读取的字节数,而不阻塞。
|
int |
getLineNumber()
过时的。
返回当前行数。
|
void |
mark(int readlimit)
过时的。
标记此输入流中的当前位置。
|
int |
read()
过时的。
从这个输入流读取下一个数据字节。
|
int |
read(byte[] b, int off, int len)
过时的。
读到
len 从输入流到字节数组数据字节。
|
void |
reset()
过时的。
重新定位该流在时间的
mark 方法的位置上呼吁这个输入流。
|
void |
setLineNumber(int lineNumber)
过时的。
将行号设置为指定的参数。
|
long |
skip(long n)
过时的。
跳过并丢弃
n 字节从输入流中的数据。
|
close, markSupported, read
public LineNumberInputStream(InputStream in)
in
-数据输入流。
public int read() throws IOException
0
到
255
一
int
返回。如果没有可用的字节,因为已到达流的末尾,则返回值
-1
。此方法块,直到输入数据可用,流的结束被检测到,或抛出异常。
对LineNumberInputStream
的read
方法调用底层输入流的read
方法。它检查输入中的回车和换行符,并修改当前行数适当。一个回车符或回车后换行符都转换成一个换行符。
read
方法重写,继承类
FilterInputStream
-1
如果到达流的末尾。
IOException
如果I/O错误发生。
FilterInputStream.in
,
getLineNumber()
public int read(byte[] b, int off, int len) throws IOException
len
从输入流到字节数组数据字节。该方法块,直到有一个输入可用。
对LineNumberInputStream
的read
方法重复调用零参数的read
法填充字节数组中的。
read
方法重写,继承类
FilterInputStream
b
-缓冲区中读取数据。
off
的起始偏移量的数据。
len
-的最大字节数读。
-1
如果没有更多的数据,因为这已到达流的末尾。
IOException
如果I/O错误发生。
read()
public long skip(long n) throws IOException
n
字节从输入流中的数据。
skip
方法的可能,因为种种原因,最终跳过一些较小的字节数,可能
0
。跳过的字节数实际返回。如果
n
是负的,没有跳过的字节。
对LineNumberInputStream
的skip
方法创建一个字节数组,然后反复读到它直到n
字节已读或已到达流的末尾。
skip
方法重写,继承类
FilterInputStream
n
-字节数被跳过。
IOException
如果I/O错误发生。
FilterInputStream.in
public void setLineNumber(int lineNumber)
lineNumber
-新的行数。
getLineNumber()
public int getLineNumber()
setLineNumber(int)
public int available() throws IOException
注意,如果数据输入流能够无阻塞供应K输入字符,这LineNumberInputStream
只能保证提供的K / 2字无阻塞,因为从数据输入流的k个字符可能由K / 2对'\r'
和'\n'
,并转化为只K / 2 '\n'
字符。
available
方法重写,继承类
FilterInputStream
IOException
如果I/O错误发生。
FilterInputStream.in
public void mark(int readlimit)
reset
方法重新定位该流的最后标记的位置以便后续读重读相同的字节。
对LineNumberInputStream
的mark
方法记得在一个私有变量的行数,然后调用底层输入流的mark
方法。
mark
方法重写,继承类
FilterInputStream
readlimit
-字节可以在标记位置无效阅读最大限度。
FilterInputStream.in
,
reset()
public void reset() throws IOException
mark
方法的位置上呼吁这个输入流。
对LineNumberInputStream
的reset
方法复位线数是当时被称为mark
方法的行数,然后调用底层输入流的reset
方法。
流标记的目的是要使用的情况下,你需要阅读前面的一点,看看什么在流中。通常这是最容易通过调用一些通用的解析器来完成的。如果流是由解析器处理的类型,它只是遵循着幸福。如果流是不是该类型,解析器应该抛异常时,它失败了,它,如果它发生在readlimit字节,允许外码重置流并尝试另一个解析器。
reset
方法重写,继承类
FilterInputStream
IOException
如果I/O错误发生。
FilterInputStream.in
,
mark(int)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.