com.softicar.platform.common.io.reader.BufferedReaders Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of platform-common Show documentation
Show all versions of platform-common Show documentation
The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.
package com.softicar.platform.common.io.reader;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
/**
* Utility methods for {@link BufferedReader}.
*
* @author Oliver Richers
*/
public class BufferedReaders {
/**
* Reads all lines from the given {@link BufferedReader}.
*
* @param reader
* the {@link BufferedReader} instance to read from (never
* null)
* @return all read lines (never null)
*/
public static Collection readLines(BufferedReader reader) {
var lines = new ArrayList();
while (true) {
String line = readLine(reader);
if (line != null) {
lines.add(line);
} else {
break;
}
}
return lines;
}
/**
* Calls {@link BufferedReader#readLine()} and wraps any {@link IOException}
* into {@link RuntimeException}.
*
* @param reader
* the reader (never null)
* @return the line as returned by {@link BufferedReader#readLine()} (may be
* null)
*/
public static String readLine(BufferedReader reader) {
try {
return reader.readLine();
} catch (IOException exception) {
throw new RuntimeException(exception);
}
}
}