[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [metrics-web/master] Detect broken GetTor stats lines.



commit 5f9a9ca0879fc03db5336ba5416e347d470b79c3
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Wed Nov 2 09:20:01 2011 +0100

    Detect broken GetTor stats lines.
---
 src/org/torproject/ernie/cron/GetTorProcessor.java |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/org/torproject/ernie/cron/GetTorProcessor.java b/src/org/torproject/ernie/cron/GetTorProcessor.java
index a6ddf11..65f2dd4 100644
--- a/src/org/torproject/ernie/cron/GetTorProcessor.java
+++ b/src/org/torproject/ernie/cron/GetTorProcessor.java
@@ -4,6 +4,7 @@ package org.torproject.ernie.cron;
 
 import java.io.*;
 import java.sql.*;
+import java.text.*;
 import java.util.*;
 import java.util.logging.*;
 
@@ -14,6 +15,7 @@ public class GetTorProcessor {
 
     /* Parse stats file. */
     File getTorFile = new File(getTorDirectory, "gettor_stats.txt");
+    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
     if (!getTorFile.exists() || getTorFile.isDirectory()) {
       logger.warning("Could not read GetTor stats");
       return;
@@ -28,6 +30,13 @@ public class GetTorProcessor {
       while ((line = br.readLine()) != null) {
         String[] parts = line.split(" ");
         String date = parts[0];
+        try {
+          dateFormat.parse(date);
+        } catch (ParseException e) {
+          logger.warning("Illegal line in GetTor stats file: '" + line
+              + "'.  Skipping.");
+          continue;
+        }
         Map<String, Integer> obs = new HashMap<String, Integer>();
         data.put(date, obs);
         for (int i = 2; i < parts.length; i++) {

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits