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

de.thksystems.util.text.CsvUtils Maven / Gradle / Ivy

Go to download

Commons for lang, crypto, xml, dom, text, csv, reflection, annotations, parsing, ...

There is a newer version: 4.4.0
Show newest version
/*
 * tksCommons
 * 
 * Author : Thomas Kuhlmann (ThK-Systems, http://www.thk-systems.de) License : LGPL (https://www.gnu.org/licenses/lgpl.html)
 */
package de.thksystems.util.text;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.io.IOUtils;

/** Handle CSV. */
public final class CsvUtils {

	private CsvUtils() {
	}

	/**
	 * Returns the CSV-file from the input stream as a list of string-arrays.
	 */
	public static final List getAsList(InputStream is, char seperator) throws IOException {
		String sepStr = String.valueOf(seperator);
		List lines = IOUtils.readLines(is);
		List csvList = new ArrayList(lines.size());
		for (String line : lines) {
			if (line != null && line.length() > 0) {
				csvList.add(line.split(sepStr));
			}
		}
		return csvList;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy