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

[tor-commits] [collector/master] Use chained String.append calls.



commit a9ebc71f75c55643eaba84c64529dd4f2bc94c50
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Mon Aug 20 15:45:50 2018 +0200

    Use chained String.append calls.
---
 .../bridgedescs/BridgeSnapshotReader.java          |  2 +-
 .../collector/exitlists/ExitListDownloader.java    |  5 +++--
 .../collector/relaydescs/ArchiveReader.java        |  2 +-
 .../collector/relaydescs/ArchiveWriter.java        | 26 ++++++++++++----------
 .../relaydescs/CachedRelayDescriptorReader.java    | 17 +++++++-------
 .../relaydescs/RelayDescriptorDownloader.java      |  6 ++---
 .../relaydescs/RelayDescriptorParser.java          |  4 ++--
 7 files changed, 33 insertions(+), 29 deletions(-)

diff --git a/src/main/java/org/torproject/metrics/collector/bridgedescs/BridgeSnapshotReader.java b/src/main/java/org/torproject/metrics/collector/bridgedescs/BridgeSnapshotReader.java
index 0ffb233..9df94d9 100644
--- a/src/main/java/org/torproject/metrics/collector/bridgedescs/BridgeSnapshotReader.java
+++ b/src/main/java/org/torproject/metrics/collector/bridgedescs/BridgeSnapshotReader.java
@@ -248,7 +248,7 @@ public class BridgeSnapshotReader {
         pbdFile.getParentFile().mkdirs();
         try (BufferedWriter bw = new BufferedWriter(new FileWriter(pbdFile))) {
           for (String f : parsed) {
-            bw.append(f + "\n");
+            bw.append(f).append("\n");
           }
           logger.debug("Finished writing file " + pbdFile.getAbsolutePath()
               + ".");
diff --git a/src/main/java/org/torproject/metrics/collector/exitlists/ExitListDownloader.java b/src/main/java/org/torproject/metrics/collector/exitlists/ExitListDownloader.java
index 4f9d082..a346d02 100644
--- a/src/main/java/org/torproject/metrics/collector/exitlists/ExitListDownloader.java
+++ b/src/main/java/org/torproject/metrics/collector/exitlists/ExitListDownloader.java
@@ -74,7 +74,8 @@ public class ExitListDownloader extends CollecTorMain {
     logger.debug("Downloading exit list...");
     StringBuilder sb = new StringBuilder();
     sb.append(Annotation.ExitList.toString());
-    sb.append("Downloaded " + dateTimeFormat.format(downloadedDate) + "\n");
+    sb.append("Downloaded ").append(dateTimeFormat.format(downloadedDate))
+        .append("\n");
     URL url = config.getUrl(Key.ExitlistUrl);
     try  {
       HttpURLConnection huc = (HttpURLConnection) url.openConnection();
@@ -183,7 +184,7 @@ public class ExitListDownloader extends CollecTorMain {
       }
     }
     for (File f : lastThreeExitLists) {
-      dumpStats.append("\n" + f.getName());
+      dumpStats.append("\n").append(f.getName());
     }
     logger.info(dumpStats.toString());
 
diff --git a/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java b/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java
index 72960b0..aea169f 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java
@@ -238,7 +238,7 @@ public class ArchiveReader {
             + "directory " + archivesDirectory + "/:");
         int printed = 0;
         for (File f : problems) {
-          sb.append("\n  " + f.getAbsolutePath());
+          sb.append("\n  ").append(f.getAbsolutePath());
           if (++printed >= 3) {
             sb.append("\n  ... more");
             break;
diff --git a/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveWriter.java b/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveWriter.java
index 08874b9..1e13d6d 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveWriter.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveWriter.java
@@ -302,15 +302,17 @@ public class ArchiveWriter extends CollecTorMain {
   /** Compiles a message with statistics on stored descriptors by type for
    * later inclusion in the log and resets counters. */
   public void intermediateStats(String event) {
-    intermediateStats.append("While " + event + ", we stored "
-        + this.storedConsensusesCounter + " consensus(es), "
-        + this.storedMicrodescConsensusesCounter + " microdesc "
-        + "consensus(es), " + this.storedVotesCounter + " vote(s), "
-        + this.storedCertsCounter + " certificate(s), "
-        + this.storedServerDescriptorsCounter + " server descriptor(s), "
-        + this.storedExtraInfoDescriptorsCounter + " extra-info "
-        + "descriptor(s), and " + this.storedMicrodescriptorsCounter
-        + " microdescriptor(s) to disk.\n");
+    intermediateStats.append("While ").append(event).append(", we stored ")
+        .append(this.storedConsensusesCounter).append(" consensus(es), ")
+        .append(this.storedMicrodescConsensusesCounter).append(" microdesc ")
+        .append("consensus(es), ").append(this.storedVotesCounter)
+        .append(" vote(s), ").append(this.storedCertsCounter)
+        .append(" certificate(s), ").append(this.storedServerDescriptorsCounter)
+        .append(" server descriptor(s), ")
+        .append(this.storedExtraInfoDescriptorsCounter).append(" extra-info ")
+        .append("descriptor(s), and ")
+        .append(this.storedMicrodescriptorsCounter)
+        .append(" microdescriptor(s) to disk.\n");
     this.storedConsensusesCounter = 0;
     this.storedMicrodescConsensusesCounter = 0;
     this.storedVotesCounter = 0;
@@ -376,7 +378,7 @@ public class ArchiveWriter extends CollecTorMain {
               }
             }
           }
-          sb.append("\nV, " + validAfterTime);
+          sb.append("\nV, ").append(validAfterTime);
           if (voteAllServerDescs > 0) {
             sb.append(String.format(", %d/%d S (%.1f%%)",
                 voteFoundServerDescs, voteAllServerDescs,
@@ -426,7 +428,7 @@ public class ArchiveWriter extends CollecTorMain {
           }
         }
       }
-      sb.append("\nC, " + validAfterTime);
+      sb.append("\nC, ").append(validAfterTime);
       int allVotes = this.expectedVotes.getOrDefault(validAfterMillis, 0);
       if (allVotes > 0) {
         sb.append(String.format(", %d/%d V (%.1f%%)", foundVotes, allVotes,
@@ -456,7 +458,7 @@ public class ArchiveWriter extends CollecTorMain {
             foundMicrodescriptors++;
           }
         }
-        sb.append("\nM, " + validAfterTime);
+        sb.append("\nM, ").append(validAfterTime);
         if (allMicrodescriptors > 0) {
           sb.append(String.format(", %d/%d M (%.1f%%)",
               foundMicrodescriptors, allMicrodescriptors,
diff --git a/src/main/java/org/torproject/metrics/collector/relaydescs/CachedRelayDescriptorReader.java b/src/main/java/org/torproject/metrics/collector/relaydescs/CachedRelayDescriptorReader.java
index 1a8922b..ad0f6a5 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/CachedRelayDescriptorReader.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/CachedRelayDescriptorReader.java
@@ -113,8 +113,8 @@ public class CachedRelayDescriptorReader {
             String line = null;
             while ((line = br.readLine()) != null) {
               if (line.startsWith("valid-after ")) {
-                dumpStats.append("\n" + f.getName() + ": " + line.substring(
-                    "valid-after ".length()));
+                dumpStats.append("\n").append(f.getName()).append(": ")
+                    .append(line.substring("valid-after ".length()));
                 SimpleDateFormat dateTimeFormat =
                     new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                 dateTimeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
@@ -172,8 +172,9 @@ public class CachedRelayDescriptorReader {
               }
               start = next;
             }
-            dumpStats.append("\n" + f.getName() + ": parsed " + parsedNum
-                + ", skipped " + skippedNum + " votes");
+            dumpStats.append("\n").append(f.getName()).append(": parsed ")
+                .append(parsedNum).append(", skipped ").append(skippedNum)
+                .append(" votes");
           } else if (f.getName().startsWith("cached-descriptors")
               || f.getName().startsWith("cached-extrainfo")) {
             String ascii = new String(allData, "US-ASCII");
@@ -215,10 +216,10 @@ public class CachedRelayDescriptorReader {
               }
               currentImportHistory.add(digest);
             }
-            dumpStats.append("\n" + f.getName() + ": parsed " + parsedNum
-                + ", skipped " + skippedNum + " "
-                + (f.getName().startsWith("cached-descriptors")
-                ? "server" : "extra-info") + " descriptors");
+            dumpStats.append("\n").append(f.getName()).append(": parsed ")
+                .append(parsedNum).append(", skipped ").append(skippedNum)
+                .append(" ").append(f.getName().startsWith("cached-descriptors")
+                ? "server" : "extra-info").append(" descriptors");
           }
         } catch (IOException | ParseException e) {
           logger.warn("Failed reading "
diff --git a/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorDownloader.java b/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorDownloader.java
index cf9ebc4..8becbe1 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorDownloader.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorDownloader.java
@@ -807,7 +807,7 @@ public class RelayDescriptorDownloader {
                 combinedResource = new StringBuilder("/tor/" + type
                     + "/d/" + descriptorIdentifier);
               } else {
-                combinedResource.append(separator + descriptorIdentifier);
+                combinedResource.append(separator).append(descriptorIdentifier);
               }
               descriptorsInCombinedResource++;
             }
@@ -1087,8 +1087,8 @@ public class RelayDescriptorDownloader {
         + " missing microdescriptor(s) from the directory authorities.");
     StringBuilder sb = new StringBuilder();
     for (String authority : this.authorities) {
-      sb.append(" " + authority + "="
-          + this.requestsByAuthority.get(authority));
+      sb.append(" ").append(authority).append("=").append(
+          this.requestsByAuthority.get(authority));
     }
     logger.info("We sent these numbers of requests to the directory "
         + "authorities:" + sb.toString());
diff --git a/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorParser.java b/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorParser.java
index 65e2e2e..664b566 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorParser.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorParser.java
@@ -115,7 +115,7 @@ public class RelayDescriptorParser {
               certificateString = certificateStringBuilder.toString();
               certificateStringBuilder = null;
             } else {
-              certificateStringBuilder.append(line + "\n");
+              certificateStringBuilder.append(line).append("\n");
             }
           }
           if (line.equals("vote-status vote")) {
@@ -129,7 +129,7 @@ public class RelayDescriptorParser {
             dirSources.add(dirSource);
           } else if (line.startsWith("dir-key-certificate-version ")) {
             certificateStringBuilder = new StringBuilder();
-            certificateStringBuilder.append(line + "\n");
+            certificateStringBuilder.append(line).append("\n");
           } else if (line.startsWith("fingerprint ")) {
             fingerprint = line.split(" ")[1];
           } else if (line.startsWith("dir-key-published ")) {



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