private void saveData(TelemetryData data) { PrintWriter out; boolean newFile = false; if (saveCnt > 25000) { File logFile; int i; logFile = new File(telemetryDir + 99 + ".log"); logFile.delete(); newFile = true; for (i = 99; i > 0; i--) { logFile = new File(telemetryDir + (i - 1) + ".log"); logFile.renameTo(new File(telemetryDir + i + ".log")); } saveCnt = 0; } try { String text = ""; SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.GERMAN); saveCnt++; out = new PrintWriter(new FileOutputStream(telemetryDir + "0.log", true)); if (newFile) { text = "Time\tLatitude\tLongitude\tSpeed\tAcceleration X\tAcceleration Y\tAcceleration Z\tCoG\tOrientation Y\tOrientation Z\n\n"; out.print(text); } text = dateFormat.format(new Date(System.currentTimeMillis())) + "\t"; if (posValid) text = text + lastLat + "\t" + lastLon + "\t" + m_lastSpeed + "\t"; else text = text + "-\t-\t-\t"; text = text + data.getAccelX() + "\t" + data.getAccelY() + "\t" + data.getAccelZ() + "\t" + data.CoG + "\t" + data.getOrientY() + "\t" + data.getOrientZ() + "\n\n"; out.print(text); out.close(); } catch (IOException ioe) { } }
void removeFiles() throws IOException { BufferedReader reader = new BufferedReader(new FileReader(new File(sGREDir, "removed-files"))); try { for (String removedFileName = reader.readLine(); removedFileName != null; removedFileName = reader.readLine()) { File removedFile = new File(sGREDir, removedFileName); if (removedFile.exists()) removedFile.delete(); } } finally { reader.close(); } }