本文整理汇总了Java中java.io.LineNumberReader.read方法的典型用法代码示例。如果您正苦于以下问题:Java LineNumberReader.read方法的具体用法?Java LineNumberReader.read怎么用?Java LineNumberReader.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.LineNumberReader
的用法示例。
在下文中一共展示了LineNumberReader.read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPartialReadAndLineNo
import java.io.LineNumberReader; //导入方法依赖的package包/类
public void testPartialReadAndLineNo() throws IOException {
MockLineReader r = new MockLineReader(5);
LineNumberReader lr = new LineNumberReader(r);
char[] buf = new char[5];
lr.read(buf, 0, 5);
assertEquals(0, lr.getLineNumber(), "LineNumberReader start with line 0");
assertEquals(1, r.getLineNumber(), "MockLineReader start with line 1");
assertEquals(new String(buf), "Line ");
String l1 = lr.readLine();
assertEquals(l1, "1", "Remaining of the first line");
assertEquals(1, lr.getLineNumber(), "Line 1 is read");
assertEquals(1, r.getLineNumber(), "MockLineReader not yet go next line");
lr.read(buf, 0, 4);
assertEquals(1, lr.getLineNumber(), "In the middle of line 2");
assertEquals(new String(buf, 0, 4), "Line");
ArrayList<String> ar = lr.lines()
.peek(l -> assertEquals(lr.getLineNumber(), r.getLineNumber()))
.collect(ArrayList::new, ArrayList::add, ArrayList::addAll);
assertEquals(ar.get(0), " 2", "Remaining in the second line");
for (int i = 1; i < ar.size(); i++) {
assertEquals(ar.get(i), "Line " + (i + 2), "Rest are full lines");
}
}