Loading src/main/java/org/torproject/onionoo/docs/BandwidthStatus.java +29 −29 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ public class BandwidthStatus extends Document { } public void setFromDocumentString(String documentString) { Scanner s = new Scanner(documentString); try (Scanner s = new Scanner(documentString)) { while (s.hasNextLine()) { String line = s.nextLine(); String[] parts = line.split(" "); Loading Loading @@ -74,7 +74,7 @@ public class BandwidthStatus extends Document { bandwidth }); } } s.close(); } } public void addToWriteHistory(BandwidthHistory bandwidthHistory) { Loading src/main/java/org/torproject/onionoo/docs/ClientsStatus.java +10 −10 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ public class ClientsStatus extends Document { } public void setFromDocumentString(String documentString) { Scanner s = new Scanner(documentString); try (Scanner s = new Scanner(documentString)) { while (s.hasNextLine()) { String line = s.nextLine(); ClientsHistory parsedLine = ClientsHistory.fromString(line); Loading @@ -44,7 +44,7 @@ public class ClientsStatus extends Document { + line + "'. Skipping."); } } s.close(); } } public void addToHistory(SortedSet<ClientsHistory> newIntervals) { Loading src/main/java/org/torproject/onionoo/docs/DocumentStore.java +11 −17 Original line number Diff line number Diff line Loading @@ -110,9 +110,8 @@ public class DocumentStore { if (directory != null) { File summaryFile = new File(directory, "summary"); if (summaryFile.exists()) { try { BufferedReader br = new BufferedReader(new FileReader( summaryFile)); try (BufferedReader br = new BufferedReader(new FileReader( summaryFile))) { String line; while ((line = br.readLine()) != null) { if (line.length() == 0) { Loading @@ -123,7 +122,6 @@ public class DocumentStore { parsedNodeStatuses.put(node.getFingerprint(), node); } } br.close(); this.lastModifiedNodeStatuses = summaryFile.lastModified(); this.listedFiles += parsedNodeStatuses.size(); this.listOperations++; Loading Loading @@ -155,10 +153,9 @@ public class DocumentStore { File summaryFile = new File(this.outDir, "summary"); if (summaryFile.exists()) { String line = null; try { try (BufferedReader br = new BufferedReader(new FileReader( summaryFile))) { Gson gson = new Gson(); BufferedReader br = new BufferedReader(new FileReader( summaryFile)); while ((line = br.readLine()) != null) { if (line.length() == 0) { continue; Loading @@ -170,7 +167,6 @@ public class DocumentStore { summaryDocument); } } br.close(); this.lastModifiedSummaryDocuments = summaryFile.lastModified(); this.listedFiles += parsedSummaryDocuments.size(); this.listOperations++; Loading Loading @@ -443,16 +439,14 @@ public class DocumentStore { return null; } String documentString = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedInputStream bis = new BufferedInputStream( new FileInputStream(documentFile)); new FileInputStream(documentFile))) { int len; byte[] data = new byte[1024]; while ((len = bis.read(data, 0, 1024)) >= 0) { baos.write(data, 0, len); } bis.close(); byte[] allData = baos.toByteArray(); if (allData.length == 0) { /* Document file is empty. */ Loading Loading @@ -744,10 +738,10 @@ public class DocumentStore { private static void writeToFile(File file, String content) throws IOException { BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(file)); try (BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(file))) { bos.write(content.getBytes("US-ASCII")); bos.close(); } } private void writeSummaryDocuments() { Loading src/main/java/org/torproject/onionoo/docs/UptimeStatus.java +12 −12 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ public class UptimeStatus extends Document { } public void setFromDocumentString(String documentString) { Scanner s = new Scanner(documentString); try (Scanner s = new Scanner(documentString)) { while (s.hasNextLine()) { String line = s.nextLine(); UptimeHistory parsedLine = UptimeHistory.fromString(line); Loading @@ -51,7 +51,7 @@ public class UptimeStatus extends Document { + line + "'. Skipping."); } } s.close(); } } public void addToHistory(boolean relay, long startMillis, Loading src/main/java/org/torproject/onionoo/docs/WeightsStatus.java +38 −37 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ public class WeightsStatus extends Document { } public void setFromDocumentString(String documentString) { Scanner s = new Scanner(documentString); try (Scanner s = new Scanner(documentString)) { while (s.hasNextLine()) { String line = s.nextLine(); String[] parts = line.split(" "); Loading Loading @@ -65,7 +65,8 @@ public class WeightsStatus extends Document { + "weights status file. Skipping."); break; } long[] interval = new long[] { validAfterMillis, freshUntilMillis }; long[] interval = new long[] { validAfterMillis, freshUntilMillis }; double[] weights = new double[] { -1.0, Double.parseDouble(parts[5]), Double.parseDouble(parts[6]), Loading @@ -76,7 +77,7 @@ public class WeightsStatus extends Document { } this.history.put(interval, weights); } s.close(); } } public void addToHistory(long validAfterMillis, long freshUntilMillis, Loading Loading
src/main/java/org/torproject/onionoo/docs/BandwidthStatus.java +29 −29 Original line number Diff line number Diff line Loading @@ -44,7 +44,7 @@ public class BandwidthStatus extends Document { } public void setFromDocumentString(String documentString) { Scanner s = new Scanner(documentString); try (Scanner s = new Scanner(documentString)) { while (s.hasNextLine()) { String line = s.nextLine(); String[] parts = line.split(" "); Loading Loading @@ -74,7 +74,7 @@ public class BandwidthStatus extends Document { bandwidth }); } } s.close(); } } public void addToWriteHistory(BandwidthHistory bandwidthHistory) { Loading
src/main/java/org/torproject/onionoo/docs/ClientsStatus.java +10 −10 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ public class ClientsStatus extends Document { } public void setFromDocumentString(String documentString) { Scanner s = new Scanner(documentString); try (Scanner s = new Scanner(documentString)) { while (s.hasNextLine()) { String line = s.nextLine(); ClientsHistory parsedLine = ClientsHistory.fromString(line); Loading @@ -44,7 +44,7 @@ public class ClientsStatus extends Document { + line + "'. Skipping."); } } s.close(); } } public void addToHistory(SortedSet<ClientsHistory> newIntervals) { Loading
src/main/java/org/torproject/onionoo/docs/DocumentStore.java +11 −17 Original line number Diff line number Diff line Loading @@ -110,9 +110,8 @@ public class DocumentStore { if (directory != null) { File summaryFile = new File(directory, "summary"); if (summaryFile.exists()) { try { BufferedReader br = new BufferedReader(new FileReader( summaryFile)); try (BufferedReader br = new BufferedReader(new FileReader( summaryFile))) { String line; while ((line = br.readLine()) != null) { if (line.length() == 0) { Loading @@ -123,7 +122,6 @@ public class DocumentStore { parsedNodeStatuses.put(node.getFingerprint(), node); } } br.close(); this.lastModifiedNodeStatuses = summaryFile.lastModified(); this.listedFiles += parsedNodeStatuses.size(); this.listOperations++; Loading Loading @@ -155,10 +153,9 @@ public class DocumentStore { File summaryFile = new File(this.outDir, "summary"); if (summaryFile.exists()) { String line = null; try { try (BufferedReader br = new BufferedReader(new FileReader( summaryFile))) { Gson gson = new Gson(); BufferedReader br = new BufferedReader(new FileReader( summaryFile)); while ((line = br.readLine()) != null) { if (line.length() == 0) { continue; Loading @@ -170,7 +167,6 @@ public class DocumentStore { summaryDocument); } } br.close(); this.lastModifiedSummaryDocuments = summaryFile.lastModified(); this.listedFiles += parsedSummaryDocuments.size(); this.listOperations++; Loading Loading @@ -443,16 +439,14 @@ public class DocumentStore { return null; } String documentString = null; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); BufferedInputStream bis = new BufferedInputStream( new FileInputStream(documentFile)); new FileInputStream(documentFile))) { int len; byte[] data = new byte[1024]; while ((len = bis.read(data, 0, 1024)) >= 0) { baos.write(data, 0, len); } bis.close(); byte[] allData = baos.toByteArray(); if (allData.length == 0) { /* Document file is empty. */ Loading Loading @@ -744,10 +738,10 @@ public class DocumentStore { private static void writeToFile(File file, String content) throws IOException { BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(file)); try (BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(file))) { bos.write(content.getBytes("US-ASCII")); bos.close(); } } private void writeSummaryDocuments() { Loading
src/main/java/org/torproject/onionoo/docs/UptimeStatus.java +12 −12 Original line number Diff line number Diff line Loading @@ -36,7 +36,7 @@ public class UptimeStatus extends Document { } public void setFromDocumentString(String documentString) { Scanner s = new Scanner(documentString); try (Scanner s = new Scanner(documentString)) { while (s.hasNextLine()) { String line = s.nextLine(); UptimeHistory parsedLine = UptimeHistory.fromString(line); Loading @@ -51,7 +51,7 @@ public class UptimeStatus extends Document { + line + "'. Skipping."); } } s.close(); } } public void addToHistory(boolean relay, long startMillis, Loading
src/main/java/org/torproject/onionoo/docs/WeightsStatus.java +38 −37 Original line number Diff line number Diff line Loading @@ -37,7 +37,7 @@ public class WeightsStatus extends Document { } public void setFromDocumentString(String documentString) { Scanner s = new Scanner(documentString); try (Scanner s = new Scanner(documentString)) { while (s.hasNextLine()) { String line = s.nextLine(); String[] parts = line.split(" "); Loading Loading @@ -65,7 +65,8 @@ public class WeightsStatus extends Document { + "weights status file. Skipping."); break; } long[] interval = new long[] { validAfterMillis, freshUntilMillis }; long[] interval = new long[] { validAfterMillis, freshUntilMillis }; double[] weights = new double[] { -1.0, Double.parseDouble(parts[5]), Double.parseDouble(parts[6]), Loading @@ -76,7 +77,7 @@ public class WeightsStatus extends Document { } this.history.put(interval, weights); } s.close(); } } public void addToHistory(long validAfterMillis, long freshUntilMillis, Loading