use of com.opencsv.CSVReader in project ice by JBEI.
the class Entries method validateEntries.
/**
* @param stream csv file input stream
*/
public List<ParsedEntryId> validateEntries(InputStream stream) throws IOException {
List<ParsedEntryId> accepted = new ArrayList<>();
EntryAuthorization authorization = new EntryAuthorization();
try (CSVReader reader = new CSVReader(new InputStreamReader(stream, StandardCharsets.UTF_8))) {
List<String[]> results = reader.readAll();
for (String[] result : results) {
if (result[0].isEmpty())
continue;
Entry entry = dao.getByPartNumber(result[0]);
if (entry == null || !authorization.canRead(this.userId, entry)) {
accepted.add(new ParsedEntryId(result[0], null));
continue;
}
PartData partData = new PartData(EntryType.nameToType(entry.getRecordType()));
partData.setPartId(entry.getPartNumber());
partData.setId(entry.getId());
accepted.add(new ParsedEntryId(result[0], partData));
}
}
return accepted;
}
use of com.opencsv.CSVReader in project gatk-protected by broadinstitute.
the class PoNTestUtils method readTsvIntoMatrix.
/**
* Reads a very basic tsv (numbers separated by tabs) into a RealMatrix.
* <p>Very little error checking happens in this method</p>
*
* @param inputFile readable file. Not {@code null}
* @return never {@code null}
*/
public static RealMatrix readTsvIntoMatrix(final File inputFile) {
IOUtils.canReadFile(inputFile);
final List<double[]> allData = new ArrayList<>();
int ctr = 0;
try {
final CSVReader reader = new CSVReader(new FileReader(inputFile), '\t', CSVWriter.NO_QUOTE_CHARACTER);
String[] nextLine;
while ((nextLine = reader.readNext()) != null) {
ctr++;
allData.add(Arrays.stream(nextLine).filter(s -> StringUtils.trim(s).length() > 0).map(s -> Double.parseDouble(StringUtils.trim(s))).mapToDouble(d -> d).toArray());
}
} catch (final IOException ioe) {
Assert.fail("Could not open test file: " + inputFile, ioe);
}
final RealMatrix result = new Array2DRowRealMatrix(allData.size(), allData.get(0).length);
for (int i = 0; i < result.getRowDimension(); i++) {
result.setRow(i, allData.get(i));
}
return result;
}
Aggregations