本文整理匯總了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");
}
}