public SynchronousLineReader(final Reader reader){ this.longLineBufferedReader = new LongLineBufferedReader(reader); }
/** * Reads a line of text. A line is considered to be terminated by any one * of a line feed ('\n'), a carriage return ('\r'), or a carriage return * followed immediately by a linefeed. * * @return A String containing the contents of the line, not including * any line-termination characters, or null if the end of the * stream has been reached * @throws IOException If an I/O error occurs */ public String readLine() throws IOException { return readLine(false); }
/** * Reads a single character. * * @return The character read, as an integer in the range * 0 to 65535 (<tt>0x00-0xffff</tt>), or -1 if the * end of the stream has been reached * @throws IOException If an I/O error occurs */ public int read() throws IOException { synchronized (lock) { ensureOpen(); for (; ; ) { if (nextChar >= nChars) { fill(); if (nextChar >= nChars) return -1; } if (skipLF) { skipLF = false; if (cb[nextChar] == '\n') { nextChar++; continue; } } return cb[nextChar++]; } } }
final LongLineBufferedReader longLineBufferedReader = new LongLineBufferedReader(new BufferedReader(new FileReader(testFile))); t0 = System.currentTimeMillis(); lineCount = 0; while (longLineBufferedReader.readLine() != null) { lineCount++; rate = ((double) lineCount) / dt; printStatus("BufferedReader", lineCount, rate, dt); longLineBufferedReader.close();
/** * Test that we read the correct number of lines * from a file * @throws Exception */ @Test public void testReadLines() throws Exception { String filePath = TestUtils.DATA_DIR + "large.txt"; BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(filePath))); LongLineBufferedReader testReader = new LongLineBufferedReader(new InputStreamReader(new FileInputStream(filePath))); String line; while((line = reader.readLine()) != null){ Assert.assertEquals(testReader.readLine(), line); } Assert.assertNull(testReader.readLine()); } }
public int read(char cbuf[], int off, int len) throws IOException { synchronized (lock) { ensureOpen(); if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) { int n = read1(cbuf, off, len); if (n <= 0) return n; while ((n < len) && in.ready()) { int n1 = read1(cbuf, off + n, len - n); if (n1 <= 0) break; n += n1;
/** * Resets the stream to the most recent mark. * * @throws IOException If the stream has never been marked, * or if the mark has been invalidated */ @Override public void reset() throws IOException { synchronized (lock) { ensureOpen(); if (markedChar < 0) throw new IOException((markedChar == INVALIDATED) ? "Mark invalid" : "Stream not marked"); nextChar = markedChar; skipLF = markedSkipLF; } }
public int read(char cbuf[], int off, int len) throws IOException { synchronized (lock) { ensureOpen(); if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) { int n = read1(cbuf, off, len); if (n <= 0) return n; while ((n < len) && in.ready()) { int n1 = read1(cbuf, off + n, len - n); if (n1 <= 0) break; n += n1;
/** * Resets the stream to the most recent mark. * * @throws IOException If the stream has never been marked, * or if the mark has been invalidated */ @Override public void reset() throws IOException { synchronized (lock) { ensureOpen(); if (markedChar < 0) throw new IOException((markedChar == INVALIDATED) ? "Mark invalid" : "Stream not marked"); nextChar = markedChar; skipLF = markedSkipLF; } }
/** * Reads a single character. * * @return The character read, as an integer in the range * 0 to 65535 (<tt>0x00-0xffff</tt>), or -1 if the * end of the stream has been reached * @throws IOException If an I/O error occurs */ @Override public int read() throws IOException { synchronized (lock) { ensureOpen(); for (; ; ) { if (nextChar >= nChars) { fill(); if (nextChar >= nChars) return -1; } if (skipLF) { skipLF = false; if (cb[nextChar] == '\n') { nextChar++; continue; } } return cb[nextChar++]; } } }
/** * Reads a line of text. A line is considered to be terminated by any one * of a line feed ('\n'), a carriage return ('\r'), or a carriage return * followed immediately by a linefeed. * * @return A String containing the contents of the line, not including * any line-termination characters, or null if the end of the * stream has been reached * @throws IOException If an I/O error occurs */ public String readLine() throws IOException { return readLine(false); }
ensureOpen(); if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) { int n = read1(cbuf, off, len); if (n <= 0) return n; while ((n < len) && in.ready()) { int n1 = read1(cbuf, off + n, len - n); if (n1 <= 0) break; n += n1;
public SynchronousLineReader(final Reader reader){ this.longLineBufferedReader = new LongLineBufferedReader(reader); }
/** * Resets the stream to the most recent mark. * * @throws IOException If the stream has never been marked, * or if the mark has been invalidated */ public void reset() throws IOException { synchronized (lock) { ensureOpen(); if (markedChar < 0) throw new IOException((markedChar == INVALIDATED) ? "Mark invalid" : "Stream not marked"); nextChar = markedChar; skipLF = markedSkipLF; } }
/** * Reads a single character. * * @return The character read, as an integer in the range * 0 to 65535 (<tt>0x00-0xffff</tt>), or -1 if the * end of the stream has been reached * @throws IOException If an I/O error occurs */ @Override public int read() throws IOException { synchronized (lock) { ensureOpen(); for (; ; ) { if (nextChar >= nChars) { fill(); if (nextChar >= nChars) return -1; } if (skipLF) { skipLF = false; if (cb[nextChar] == '\n') { nextChar++; continue; } } return cb[nextChar++]; } } }
/** * Reads a line of text. A line is considered to be terminated by any one * of a line feed ('\n'), a carriage return ('\r'), or a carriage return * followed immediately by a linefeed. * * @return A String containing the contents of the line, not including * any line-termination characters, or null if the end of the * stream has been reached * @throws IOException If an I/O error occurs */ public String readLine() throws IOException { return readLine(false); }
public AsynchronousLineReader(final Reader reader, final int lineReadAheadSize) { bufferedReader = new LongLineBufferedReader(reader); lineQueue = new LinkedBlockingQueue<String>(lineReadAheadSize); worker = new Thread(new Worker()); worker.setDaemon(true); worker.start(); }