TrackFileReader { @NonNull List<MLocation> read() { if (trackFile.getName().endsWith(".gz")) { try (BufferedReader br = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(trackFile)), StandardCharsets.UTF_8))) { return parse(br); } catch (EOFException e) { Log.e(TAG, "Premature end of gzip track file " + trackFile + "\n" + e); } catch (IOException e) { Log.e(TAG, "Error reading track data from " + trackFile, e); } } else { try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(trackFile), StandardCharsets.UTF_8))) { return parse(br); } catch (IOException e) { Log.e(TAG, "Error reading track data from " + trackFile, e); } } return new ArrayList<>(); } TrackFileReader(@NonNull File trackFile);   }
@Test public void read() throws IOException { assertEquals(0, parse("").size()); assertEquals(0, parse("millis,sensor,lat,lon,alt\n").size()); assertEquals(1, parse("millis,sensor,lat,lon,alt\n1,gps,2,3,4").size()); assertEquals(1, parse("millis,sensor,lat,lon,alt\n1,gps,2,3,4\n").size()); assertEquals(1, parse("millis,sensor,lat,lon,alt\n1,gps,2,3,4\n5,alt,6,7,8").size()); assertEquals(1, parse("millis,sensor,lat,lon,alt\n1,gps,2,3,4\n5,alt,6,7,8\n9,alt,10,11,12").size()); assertEquals(2, parse("millis,sensor,lat,lon,alt\n1,gps,2,3,4\n5,gps,6,7,8").size()); assertEquals(1, parse("time,lat,lon,alt\n2019-04-20T16:20:00.00Z,2,3,4").size()); }
@Test public void readTwice() throws IOException { final TrackFileReader reader = new TrackFileReader(FileUtil.makeFile("millis,sensor,lat,lon,alt\n1,gps,2,3,4")); assertEquals(1, reader.read().size()); assertEquals(1, reader.read().size()); }