/** * Reads a line of text. A line is considered to be terminated by any one of a line feed ({@code * '\n'}), a carriage return ({@code '\r'}), or a carriage return followed immediately by a * linefeed ({@code "\r\n"}). * * @return a {@code String} containing the contents of the line, not including any * line-termination characters, or {@code null} if the end of the stream has been reached. * @throws IOException if an I/O error occurs */ @CanIgnoreReturnValue // to skip a line public String readLine() throws IOException { while (lines.peek() == null) { cbuf.clear(); // The default implementation of Reader#read(CharBuffer) allocates a // temporary char[], so we call Reader#read(char[], int, int) instead. int read = (reader != null) ? reader.read(buf, 0, buf.length) : readable.read(cbuf); if (read == -1) { lineBuf.finish(); break; } lineBuf.add(buf, 0, read); } return lines.poll(); } }
/** * Reads a line of text. A line is considered to be terminated by any one of a line feed ({@code * '\n'}), a carriage return ({@code '\r'}), or a carriage return followed immediately by a * linefeed ({@code "\r\n"}). * * @return a {@code String} containing the contents of the line, not including any * line-termination characters, or {@code null} if the end of the stream has been reached. * @throws IOException if an I/O error occurs */ @CanIgnoreReturnValue // to skip a line public String readLine() throws IOException { while (lines.peek() == null) { cbuf.clear(); // The default implementation of Reader#read(CharBuffer) allocates a // temporary char[], so we call Reader#read(char[], int, int) instead. int read = (reader != null) ? reader.read(buf, 0, buf.length) : readable.read(cbuf); if (read == -1) { lineBuf.finish(); break; } lineBuf.add(buf, 0, read); } return lines.poll(); } }
private static List<String> bufferHelper(String input, int chunk) throws IOException { final List<String> lines = Lists.newArrayList(); LineBuffer lineBuf = new LineBuffer() { @Override protected void handleLine(String line, String end) { lines.add(line + end); } }; char[] chars = input.toCharArray(); int off = 0; while (off < chars.length) { int len = Math.min(chars.length, off + chunk) - off; lineBuf.add(chars, off, len); off += len; } lineBuf.finish(); return lines; }
/** * Reads a line of text. A line is considered to be terminated by any one of a line feed ({@code * '\n'}), a carriage return ({@code '\r'}), or a carriage return followed immediately by a * linefeed ({@code "\r\n"}). * * @return a {@code String} containing the contents of the line, not including any * line-termination characters, or {@code null} if the end of the stream has been reached. * @throws IOException if an I/O error occurs */ @CanIgnoreReturnValue // to skip a line public String readLine() throws IOException { while (lines.peek() == null) { cbuf.clear(); // The default implementation of Reader#read(CharBuffer) allocates a // temporary char[], so we call Reader#read(char[], int, int) instead. int read = (reader != null) ? reader.read(buf, 0, buf.length) : readable.read(cbuf); if (read == -1) { lineBuf.finish(); break; } lineBuf.add(buf, 0, read); } return lines.poll(); } }
/** * Reads a line of text. A line is considered to be terminated by any * one of a line feed ({@code '\n'}), a carriage return * ({@code '\r'}), or a carriage return followed immediately by a linefeed * ({@code "\r\n"}). * * @return a {@code String} containing the contents of the line, not * including any line-termination characters, or {@code null} if the * end of the stream has been reached. * @throws IOException if an I/O error occurs */ public String readLine() throws IOException { while (lines.peek() == null) { cbuf.clear(); // The default implementation of Reader#read(CharBuffer) allocates a // temporary char[], so we call Reader#read(char[], int, int) instead. int read = (reader != null) ? reader.read(buf, 0, buf.length) : readable.read(cbuf); if (read == -1) { lineBuf.finish(); break; } lineBuf.add(buf, 0, read); } return lines.poll(); } }
/** * Reads a line of text. A line is considered to be terminated by any * one of a line feed ({@code '\n'}), a carriage return * ({@code '\r'}), or a carriage return followed immediately by a linefeed * ({@code "\r\n"}). * * @return a {@code String} containing the contents of the line, not * including any line-termination characters, or {@code null} if the * end of the stream has been reached. * @throws IOException if an I/O error occurs */ public String readLine() throws IOException { while (lines.peek() == null) { cbuf.clear(); // The default implementation of Reader#read(CharBuffer) allocates a // temporary char[], so we call Reader#read(char[], int, int) instead. int read = (reader != null) ? reader.read(buf, 0, buf.length) : readable.read(cbuf); if (read == -1) { lineBuf.finish(); break; } lineBuf.add(buf, 0, read); } return lines.poll(); } }
/** * Reads a line of text. A line is considered to be terminated by any * one of a line feed ({@code '\n'}), a carriage return * ({@code '\r'}), or a carriage return followed immediately by a linefeed * ({@code "\r\n"}). * * @return a {@code String} containing the contents of the line, not * including any line-termination characters, or {@code null} if the * end of the stream has been reached. * @throws IOException if an I/O error occurs */ public String readLine() throws IOException { while (lines.peek() == null) { cbuf.clear(); // The default implementation of Reader#read(CharBuffer) allocates a // temporary char[], so we call Reader#read(char[], int, int) instead. int read = (reader != null) ? reader.read(buf, 0, buf.length) : readable.read(cbuf); if (read == -1) { lineBuf.finish(); break; } lineBuf.add(buf, 0, read); } return lines.poll(); } }
/** * Reads a line of text. A line is considered to be terminated by any * one of a line feed ({@code '\n'}), a carriage return * ({@code '\r'}), or a carriage return followed immediately by a linefeed * ({@code "\r\n"}). * * @return a {@code String} containing the contents of the line, not * including any line-termination characters, or {@code null} if the * end of the stream has been reached. * @throws IOException if an I/O error occurs */ public String readLine() throws IOException { while (lines.peek() == null) { cbuf.clear(); // The default implementation of Reader#read(CharBuffer) allocates a // temporary char[], so we call Reader#read(char[], int, int) instead. int read = (reader != null) ? reader.read(buf, 0, buf.length) : readable.read(cbuf); if (read == -1) { lineBuf.finish(); break; } lineBuf.add(buf, 0, read); } return lines.poll(); } }
/** * Reads a line of text. A line is considered to be terminated by any * one of a line feed ({@code '\n'}), a carriage return * ({@code '\r'}), or a carriage return followed immediately by a linefeed * ({@code "\r\n"}). * * @return a {@code String} containing the contents of the line, not * including any line-termination characters, or {@code null} if the * end of the stream has been reached. * @throws IOException if an I/O error occurs */ public String readLine() throws IOException { while (lines.peek() == null) { cbuf.clear(); // The default implementation of Reader#read(CharBuffer) allocates a // temporary char[], so we call Reader#read(char[], int, int) instead. int read = (reader != null) ? reader.read(buf, 0, buf.length) : readable.read(cbuf); if (read == -1) { lineBuf.finish(); break; } lineBuf.add(buf, 0, read); } return lines.poll(); } }
/** * Reads a line of text. A line is considered to be terminated by any * one of a line feed ({@code '\n'}), a carriage return * ({@code '\r'}), or a carriage return followed immediately by a linefeed * ({@code "\r\n"}). * * @return a {@code String} containing the contents of the line, not * including any line-termination characters, or {@code null} if the * end of the stream has been reached. * @throws IOException if an I/O error occurs */ public String readLine() throws IOException { while (lines.peek() == null) { cbuf.clear(); // The default implementation of Reader#read(CharBuffer) allocates a // temporary char[], so we call Reader#read(char[], int, int) instead. int read = (reader != null) ? reader.read(buf, 0, buf.length) : readable.read(cbuf); if (read == -1) { lineBuf.finish(); break; } lineBuf.add(buf, 0, read); } return lines.poll(); } }
/** * Reads a line of text. A line is considered to be terminated by any * one of a line feed ({@code '\n'}), a carriage return * ({@code '\r'}), or a carriage return followed immediately by a linefeed * ({@code "\r\n"}). * * @return a {@code String} containing the contents of the line, not * including any line-termination characters, or {@code null} if the * end of the stream has been reached. * @throws IOException if an I/O error occurs */ public String readLine() throws IOException { while (lines.peek() == null) { cbuf.clear(); // The default implementation of Reader#read(CharBuffer) allocates a // temporary char[], so we call Reader#read(char[], int, int) instead. int read = (reader != null) ? reader.read(buf, 0, buf.length) : readable.read(cbuf); if (read == -1) { lineBuf.finish(); break; } lineBuf.add(buf, 0, read); } return lines.poll(); } }
/** * Reads a line of text. A line is considered to be terminated by any * one of a line feed ({@code '\n'}), a carriage return * ({@code '\r'}), or a carriage return followed immediately by a linefeed * ({@code "\r\n"}). * * @return a {@code String} containing the contents of the line, not * including any line-termination characters, or {@code null} if the * end of the stream has been reached. * @throws IOException if an I/O error occurs */ public String readLine() throws IOException { while (lines.peek() == null) { cbuf.clear(); // The default implementation of Reader#read(CharBuffer) allocates a // temporary char[], so we call Reader#read(char[], int, int) instead. int read = (reader != null) ? reader.read(buf, 0, buf.length) : readable.read(cbuf); if (read == -1) { lineBuf.finish(); break; } lineBuf.add(buf, 0, read); } return lines.poll(); } }
/** * Reads a line of text. A line is considered to be terminated by any * one of a line feed ({@code '\n'}), a carriage return * ({@code '\r'}), or a carriage return followed immediately by a linefeed * ({@code "\r\n"}). * * @return a {@code String} containing the contents of the line, not * including any line-termination characters, or {@code null} if the * end of the stream has been reached. * @throws IOException if an I/O error occurs */ public String readLine() throws IOException { while (lines.peek() == null) { cbuf.clear(); // The default implementation of Reader#read(CharBuffer) allocates a // temporary char[], so we call Reader#read(char[], int, int) instead. int read = (reader != null) ? reader.read(buf, 0, buf.length) : readable.read(cbuf); if (read == -1) { lineBuf.finish(); break; } lineBuf.add(buf, 0, read); } return lines.poll(); } }
/** * Reads a line of text. A line is considered to be terminated by any * one of a line feed ({@code '\n'}), a carriage return * ({@code '\r'}), or a carriage return followed immediately by a linefeed * ({@code "\r\n"}). * * @return a {@code String} containing the contents of the line, not * including any line-termination characters, or {@code null} if the * end of the stream has been reached. * @throws IOException if an I/O error occurs */ public String readLine() throws IOException { while (lines.peek() == null) { cbuf.clear(); // The default implementation of Reader#read(CharBuffer) allocates a // temporary char[], so we call Reader#read(char[], int, int) instead. int read = (reader != null) ? reader.read(buf, 0, buf.length) : readable.read(cbuf); if (read == -1) { lineBuf.finish(); break; } lineBuf.add(buf, 0, read); } return lines.poll(); } }
/** * Reads a line of text. A line is considered to be terminated by any one of a line feed ({@code * '\n'}), a carriage return ({@code '\r'}), or a carriage return followed immediately by a * linefeed ({@code "\r\n"}). * * @return a {@code String} containing the contents of the line, not including any * line-termination characters, or {@code null} if the end of the stream has been reached. * @throws IOException if an I/O error occurs */ @CanIgnoreReturnValue // to skip a line public String readLine() throws IOException { while (lines.peek() == null) { cbuf.clear(); // The default implementation of Reader#read(CharBuffer) allocates a // temporary char[], so we call Reader#read(char[], int, int) instead. int read = (reader != null) ? reader.read(buf, 0, buf.length) : readable.read(cbuf); if (read == -1) { lineBuf.finish(); break; } lineBuf.add(buf, 0, read); } return lines.poll(); } }
/** * Reads a line of text. A line is considered to be terminated by any one of a line feed ({@code * '\n'}), a carriage return ({@code '\r'}), or a carriage return followed immediately by a * linefeed ({@code "\r\n"}). * * @return a {@code String} containing the contents of the line, not including any * line-termination characters, or {@code null} if the end of the stream has been reached. * @throws IOException if an I/O error occurs */ @CanIgnoreReturnValue // to skip a line public String readLine() throws IOException { while (lines.peek() == null) { cbuf.clear(); // The default implementation of Reader#read(CharBuffer) allocates a // temporary char[], so we call Reader#read(char[], int, int) instead. int read = (reader != null) ? reader.read(buf, 0, buf.length) : readable.read(cbuf); if (read == -1) { lineBuf.finish(); break; } lineBuf.add(buf, 0, read); } return lines.poll(); } }
private static List<String> bufferHelper(String input, int chunk) throws IOException { final List<String> lines = Lists.newArrayList(); LineBuffer lineBuf = new LineBuffer() { @Override protected void handleLine(String line, String end) { lines.add(line + end); } }; char[] chars = input.toCharArray(); int off = 0; while (off < chars.length) { int len = Math.min(chars.length, off + chunk) - off; lineBuf.add(chars, off, len); off += len; } lineBuf.finish(); return lines; }