private List<GpsRecordAnnotation> readGpsFixesFromFile( FileReader fileReader, String csvFileName) { List<GpsRecordAnnotation> results = new LinkedList<GpsRecordAnnotation>(); CsvBeanReader beanReader = new CsvBeanReader(fileReader, CsvPreference.STANDARD_PREFERENCE); try { String[] headers = beanReader.getHeader(true); if (hasIncorrectHeaders(headers)) { closeReaders(fileReader, beanReader); throw getUnableToReadFileExceptionCauseOfHeaders(csvFileName); } getGpsFixesFromReader(results, beanReader, headers); closeReaders(fileReader, beanReader); } catch (IOException | NullPointerException e) { throw getUnableToReadFileExceptionCauseUnknown(csvFileName, e); } return results; }
private void getGpsFixesFromReader( List<GpsRecordAnnotation> results, CsvBeanReader beanReader, String[] headers) throws IOException { GpsRecordAnnotation gpsFix = null; do { gpsFix = beanReader.read(GpsRecordAnnotation.class, headers, getProcessors()); if (gpsFix != null) { results.add(gpsFix); } } while (gpsFix != null); }
private void closeReaders(FileReader fileReader, CsvBeanReader beanReader) throws IOException { beanReader.close(); fileReader.close(); }