All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.softicar.platform.common.io.reader.BufferedReaders Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
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);
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy