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

[tor-commits] [collector/release] Use DescriptorBuilder more often.



commit 4e61bb792bc4cd4db9df6eb49ab88890b34ff489
Author: iwakeh <iwakeh@xxxxxxxxxxxxxx>
Date:   Fri Oct 27 17:35:17 2017 +0000

    Use DescriptorBuilder more often.
    
    Add convenience constructor accepting the first string as argument.
---
 .../torproject/collector/bridgedescs/DescriptorBuilder.java  |  5 +++++
 .../collector/bridgedescs/SanitizedBridgesWriter.java        | 12 ++++++------
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/src/main/java/org/torproject/collector/bridgedescs/DescriptorBuilder.java b/src/main/java/org/torproject/collector/bridgedescs/DescriptorBuilder.java
index 9c47b5e..f530368 100644
--- a/src/main/java/org/torproject/collector/bridgedescs/DescriptorBuilder.java
+++ b/src/main/java/org/torproject/collector/bridgedescs/DescriptorBuilder.java
@@ -34,6 +34,11 @@ class DescriptorBuilder {
     this.parts.add(this.lastPart);
   }
 
+  public DescriptorBuilder(String firstString) {
+    this();
+    this.append(firstString);
+  }
+
   private void throwExceptionIfFinalized() {
     if (this.finalized) {
       throw new IllegalStateException("This DescriptorBuilder is finalized and"
diff --git a/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java b/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java
index 1d264a5..b4cd49e 100644
--- a/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java
+++ b/src/main/java/org/torproject/collector/bridgedescs/SanitizedBridgesWriter.java
@@ -461,7 +461,7 @@ public class SanitizedBridgesWriter extends CollecTorMain {
     }
 
     /* Parse the given network status line by line. */
-    StringBuilder header = new StringBuilder();
+    DescriptorBuilder header = new DescriptorBuilder();
     boolean includesFingerprintLine = false;
     SortedMap<String, String> scrubbedLines = new TreeMap<>();
     try {
@@ -483,7 +483,7 @@ public class SanitizedBridgesWriter extends CollecTorMain {
 
         /* Additional header lines don't have to be cleaned up. */
         } else if (line.startsWith("flag-thresholds ")) {
-          header.append(line + "\n");
+          header.append(line).newLine();
 
         /* The authority fingerprint in the "fingerprint" line can go in
          * unscrubbed. */
@@ -494,7 +494,7 @@ public class SanitizedBridgesWriter extends CollecTorMain {
                 + "\"fingerprint\" line (\"" + line + "\").");
             return;
           }
-          header.append(line + "\n");
+          header.append(line).newLine();
           includesFingerprintLine = true;
 
         /* r lines contain sensitive information that needs to be removed
@@ -593,7 +593,7 @@ public class SanitizedBridgesWriter extends CollecTorMain {
         scrubbed = new StringBuilder();
       }
       if (!includesFingerprintLine) {
-        header.append("fingerprint ").append(authorityFingerprint).append("\n");
+        header.append("fingerprint ").append(authorityFingerprint).newLine();
       }
 
       /* Check if we can tell from the descriptor publication times
@@ -879,13 +879,13 @@ public class SanitizedBridgesWriter extends CollecTorMain {
         /* Replace node fingerprints in the family line with their hashes
          * and leave nicknames unchanged. */
         } else if (line.startsWith("family ")) {
-          StringBuilder familyLine = new StringBuilder("family");
+          DescriptorBuilder familyLine = new DescriptorBuilder("family");
           for (String s : line.substring(7).split(" ")) {
             if (s.startsWith("$")) {
               familyLine.append(" $").append(DigestUtils.sha1Hex(Hex.decodeHex(
                   s.substring(1).toCharArray())).toUpperCase());
             } else {
-              familyLine.append(" ").append(s);
+              familyLine.space().append(s);
             }
           }
           scrubbed.append(familyLine.toString()).newLine();



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