/** * Reads all of the lines from a {@link Readable} object. The lines do * not include line-termination characters, but do include other * leading and trailing whitespace. * * <p>Does not close the {@code Readable}. If reading files or resources you * should use the {@link Files#readLines} and {@link Resources#readLines} * methods. * * @param r the object to read from * @return a mutable {@link List} containing all the lines * @throws IOException if an I/O error occurs */ public static List<String> readLines(Readable r) throws IOException { List<String> result = new ArrayList<String>(); LineReader lineReader = new LineReader(r); String line; while ((line = lineReader.readLine()) != null) { result.add(line); } return result; }
/** * Reads all of the lines from a {@link Readable} object. The lines do * not include line-termination characters, but do include other * leading and trailing whitespace. * * <p>Does not close the {@code Readable}. If reading files or resources you * should use the {@link Files#readLines} and {@link Resources#readLines} * methods. * * @param r the object to read from * @return a mutable {@link List} containing all the lines * @throws IOException if an I/O error occurs */ public static List<String> readLines(Readable r) throws IOException { List<String> result = new ArrayList<String>(); LineReader lineReader = new LineReader(r); String line; while ((line = lineReader.readLine()) != null) { result.add(line); } return result; }
/** * Reads all of the lines from a {@link Readable} object. The lines do * not include line-termination characters, but do include other * leading and trailing whitespace. * * <p>Does not close the {@code Readable}. If reading files or resources you * should use the {@link Files#readLines} and {@link Resources#readLines} * methods. * * @param r the object to read from * @return a mutable {@link List} containing all the lines * @throws IOException if an I/O error occurs */ public static List<String> readLines(Readable r) throws IOException { List<String> result = new ArrayList<String>(); LineReader lineReader = new LineReader(r); String line; while ((line = lineReader.readLine()) != null) { result.add(line); } return result; }
/** * Reads all of the lines from a {@link Readable} object. The lines do * not include line-termination characters, but do include other * leading and trailing whitespace. * * <p>Does not close the {@code Readable}. If reading files or resources you * should use the {@link Files#readLines} and {@link Resources#readLines} * methods. * * @param r the object to read from * @return a mutable {@link List} containing all the lines * @throws IOException if an I/O error occurs */ public static List<String> readLines(Readable r) throws IOException { List<String> result = new ArrayList<String>(); LineReader lineReader = new LineReader(r); String line; while ((line = lineReader.readLine()) != null) { result.add(line); } return result; }
/** * Reads all of the lines from a {@link Readable} object. The lines do * not include line-termination characters, but do include other * leading and trailing whitespace. * * <p>Does not close the {@code Readable}. If reading files or resources you * should use the {@link Files#readLines} and {@link Resources#readLines} * methods. * * @param r the object to read from * @return a mutable {@link List} containing all the lines * @throws IOException if an I/O error occurs */ public static List<String> readLines(Readable r) throws IOException { List<String> result = new ArrayList<String>(); LineReader lineReader = new LineReader(r); String line; while ((line = lineReader.readLine()) != null) { result.add(line); } return result; }
/** * Reads all of the lines from a {@link Readable} object. The lines do * not include line-termination characters, but do include other * leading and trailing whitespace. * * <p>Does not close the {@code Readable}. If reading files or resources you * should use the {@link Files#readLines} and {@link Resources#readLines} * methods. * * @param r the object to read from * @return a mutable {@link List} containing all the lines * @throws IOException if an I/O error occurs */ public static List<String> readLines(Readable r) throws IOException { List<String> result = new ArrayList<String>(); LineReader lineReader = new LineReader(r); String line; while ((line = lineReader.readLine()) != null) { result.add(line); } return result; }
/** * Reads the first line from a {@link Readable} & {@link Closeable} object * supplied by a factory. The line does not include line-termination * characters, but does include other leading and trailing whitespace. * * @param supplier the factory to read from * @return the first line, or null if the reader is empty * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable> String readFirstLine( InputSupplier<R> supplier) throws IOException { boolean threw = true; R r = supplier.getInput(); try { String line = new LineReader(r).readLine(); threw = false; return line; } finally { Closeables.close(r, threw); } }
/** * Reads the first line from a {@link Readable} & {@link Closeable} object * supplied by a factory. The line does not include line-termination * characters, but does include other leading and trailing whitespace. * * @param supplier the factory to read from * @return the first line, or null if the reader is empty * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable> String readFirstLine( InputSupplier<R> supplier) throws IOException { boolean threw = true; R r = supplier.getInput(); try { String line = new LineReader(r).readLine(); threw = false; return line; } finally { Closeables.close(r, threw); } }
/** * Reads the first line from a {@link Readable} & {@link Closeable} object * supplied by a factory. The line does not include line-termination * characters, but does include other leading and trailing whitespace. * * @param supplier the factory to read from * @return the first line, or null if the reader is empty * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable> String readFirstLine( InputSupplier<R> supplier) throws IOException { boolean threw = true; R r = supplier.getInput(); try { String line = new LineReader(r).readLine(); threw = false; return line; } finally { Closeables.close(r, threw); } }
/** * Reads the first line from a {@link Readable} & {@link Closeable} object * supplied by a factory. The line does not include line-termination * characters, but does include other leading and trailing whitespace. * * @param supplier the factory to read from * @return the first line, or null if the reader is empty * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable> String readFirstLine( InputSupplier<R> supplier) throws IOException { boolean threw = true; R r = supplier.getInput(); try { String line = new LineReader(r).readLine(); threw = false; return line; } finally { Closeables.close(r, threw); } }
/** * Reads the first line from a {@link Readable} & {@link Closeable} object * supplied by a factory. The line does not include line-termination * characters, but does include other leading and trailing whitespace. * * @param supplier the factory to read from * @return the first line, or null if the reader is empty * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable> String readFirstLine( InputSupplier<R> supplier) throws IOException { boolean threw = true; R r = supplier.getInput(); try { String line = new LineReader(r).readLine(); threw = false; return line; } finally { Closeables.close(r, threw); } }
/** * Reads the first line from a {@link Readable} & {@link Closeable} object * supplied by a factory. The line does not include line-termination * characters, but does include other leading and trailing whitespace. * * @param supplier the factory to read from * @return the first line, or null if the reader is empty * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable> String readFirstLine( InputSupplier<R> supplier) throws IOException { boolean threw = true; R r = supplier.getInput(); try { String line = new LineReader(r).readLine(); threw = false; return line; } finally { Closeables.close(r, threw); } }
/** * Streams lines from a {@link Readable} and {@link Closeable} object * supplied by a factory, stopping when our callback returns false, or we * have read all of the lines. * * @param supplier the factory to read from * @param callback the LineProcessor to use to handle the lines * @return the output of processing the lines * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable, T> T readLines( InputSupplier<R> supplier, LineProcessor<T> callback) throws IOException { boolean threw = true; R r = supplier.getInput(); try { LineReader lineReader = new LineReader(r); String line; while ((line = lineReader.readLine()) != null) { if (!callback.processLine(line)) { break; } } threw = false; } finally { Closeables.close(r, threw); } return callback.getResult(); }
/** * Streams lines from a {@link Readable} and {@link Closeable} object * supplied by a factory, stopping when our callback returns false, or we * have read all of the lines. * * @param supplier the factory to read from * @param callback the LineProcessor to use to handle the lines * @return the output of processing the lines * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable, T> T readLines( InputSupplier<R> supplier, LineProcessor<T> callback) throws IOException { boolean threw = true; R r = supplier.getInput(); try { LineReader lineReader = new LineReader(r); String line; while ((line = lineReader.readLine()) != null) { if (!callback.processLine(line)) { break; } } threw = false; } finally { Closeables.close(r, threw); } return callback.getResult(); }
/** * Streams lines from a {@link Readable} and {@link Closeable} object * supplied by a factory, stopping when our callback returns false, or we * have read all of the lines. * * @param supplier the factory to read from * @param callback the LineProcessor to use to handle the lines * @return the output of processing the lines * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable, T> T readLines( InputSupplier<R> supplier, LineProcessor<T> callback) throws IOException { boolean threw = true; R r = supplier.getInput(); try { LineReader lineReader = new LineReader(r); String line; while ((line = lineReader.readLine()) != null) { if (!callback.processLine(line)) { break; } } threw = false; } finally { Closeables.close(r, threw); } return callback.getResult(); }
/** * Streams lines from a {@link Readable} and {@link Closeable} object * supplied by a factory, stopping when our callback returns false, or we * have read all of the lines. * * @param supplier the factory to read from * @param callback the LineProcessor to use to handle the lines * @return the output of processing the lines * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable, T> T readLines( InputSupplier<R> supplier, LineProcessor<T> callback) throws IOException { boolean threw = true; R r = supplier.getInput(); try { LineReader lineReader = new LineReader(r); String line; while ((line = lineReader.readLine()) != null) { if (!callback.processLine(line)) { break; } } threw = false; } finally { Closeables.close(r, threw); } return callback.getResult(); }
/** * Streams lines from a {@link Readable} and {@link Closeable} object * supplied by a factory, stopping when our callback returns false, or we * have read all of the lines. * * @param supplier the factory to read from * @param callback the LineProcessor to use to handle the lines * @return the output of processing the lines * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable, T> T readLines( InputSupplier<R> supplier, LineProcessor<T> callback) throws IOException { boolean threw = true; R r = supplier.getInput(); try { LineReader lineReader = new LineReader(r); String line; while ((line = lineReader.readLine()) != null) { if (!callback.processLine(line)) { break; } } threw = false; } finally { Closeables.close(r, threw); } return callback.getResult(); }
/** * Streams lines from a {@link Readable} and {@link Closeable} object * supplied by a factory, stopping when our callback returns false, or we * have read all of the lines. * * @param supplier the factory to read from * @param callback the LineProcessor to use to handle the lines * @return the output of processing the lines * @throws IOException if an I/O error occurs */ public static <R extends Readable & Closeable, T> T readLines( InputSupplier<R> supplier, LineProcessor<T> callback) throws IOException { boolean threw = true; R r = supplier.getInput(); try { LineReader lineReader = new LineReader(r); String line; while ((line = lineReader.readLine()) != null) { if (!callback.processLine(line)) { break; } } threw = false; } finally { Closeables.close(r, threw); } return callback.getResult(); }