TrackAbbrv { public static void abbreviate(@NonNull File trackFileGz, @NonNull File abbrvFile) { final long startTime = System.currentTimeMillis(); try (BufferedReader br = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(trackFileGz)), StandardCharsets.UTF_8))) { try (FileWriter writer = new FileWriter(abbrvFile)) { boolean firstLine = true; String line; while ((line = br.readLine()) != null) { if (firstLine) { firstLine = false; writer.write(line); writer.write('\n'); } else if (!line.contains(",grv,") && !line.contains(",rot,") && !line.contains(",acc,")) { writer.write(line); writer.write('\n'); } } } } catch (EOFException e) { Log.e(TAG, "Premature end of gzip track file " + trackFileGz + " to " + abbrvFile + "\n" + e); } catch (IOException e) { Log.e(TAG, "Error abbreviated track data from " + trackFileGz + " to " + abbrvFile, e); } Log.i(TAG, "Abbreviated track " + (trackFileGz.length() >> 10) + "kb -> " + (abbrvFile.length() >> 10) + "kb in " + (System.currentTimeMillis() - startTime) + "ms"); }  static void abbreviate(@NonNull File trackFileGz, @NonNull File abbrvFile);  }
@Test public void abbreviate() throws IOException { File in = FileUtil.makeFileGz("time,sensor,x,y,z\n,gps,1,2,3\n,alt,4,5,6\n,grv,7,8,9"); File out = File.createTempFile("abbrv-out", ".csv"); TrackAbbrv.abbreviate(in, out); assertEquals(40, out.length()); }