Java Code Examples for java.io.LineNumberReader#read()
The following examples show how to use
java.io.LineNumberReader#read() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Lines.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
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"); } }
Example 2
Source File: Lines.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
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"); } }
Example 3
Source File: Lines.java From jdk8u60 with GNU General Public License v2.0 | 6 votes |
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"); } }
Example 4
Source File: Lines.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
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"); } }
Example 5
Source File: Lines.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 6 votes |
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"); } }
Example 6
Source File: Lines.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
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"); } }
Example 7
Source File: Lines.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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"); } }
Example 8
Source File: Lines.java From hottub with GNU General Public License v2.0 | 6 votes |
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"); } }
Example 9
Source File: Lines.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
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"); } }
Example 10
Source File: Lines.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
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"); } }
Example 11
Source File: Lines.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
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"); } }
Example 12
Source File: Lines.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
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"); } }
Example 13
Source File: Lines.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
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"); } }
Example 14
Source File: OldLineNumberReaderTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * java.io.LineNumberReader#read() */ public void test_read() throws IOException { lnr = new LineNumberReader(new StringReader(text)); int c = lnr.read(); assertEquals("Test 1: Read returned incorrect character;", '0', c); lnr.read(); assertEquals("Test 2: Read failed to increase the line number;", 1, lnr.getLineNumber()); lnr.close(); try { lnr.read(); fail("Test 3: IOException expected."); } catch (IOException e) { // Expected. } }
Example 15
Source File: OldLineNumberReaderTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * java.io.LineNumberReader#read(char[], int, int) */ public void test_read$CII() throws IOException { lnr = new LineNumberReader(new StringReader(text)); char[] c = new char[100]; lnr.read(c, 0, 4); assertTrue("Test 1: Read returned incorrect characters.", "0\n1\n" .equals(new String(c, 0, 4))); assertEquals("Test 2: Read failed to inc lineNumber", 2, lnr.getLineNumber()); lnr.close(); try { lnr.read(c, 0, 4); fail("Test 3: IOException expected."); } catch (IOException e) { // Expected. } }
Example 16
Source File: CharsetToolkit.java From groovy with Apache License 2.0 | 5 votes |
/** * Gets a <code>BufferedReader</code> (indeed a <code>LineNumberReader</code>) from the <code>File</code> * specified in the constructor of <code>CharsetToolkit</code> using the charset discovered or the default * charset if an 8-bit <code>Charset</code> is encountered. * * @return a <code>BufferedReader</code> * @throws FileNotFoundException if the file is not found. */ public BufferedReader getReader() throws FileNotFoundException { LineNumberReader reader = new LineNumberReader(new InputStreamReader(new FileInputStream(file), getCharset())); if (hasUTF8Bom() || hasUTF16LEBom() || hasUTF16BEBom()) { try { reader.read(); } catch (IOException e) { // should never happen, as a file with no content // but with a BOM has at least one char } } return reader; }