[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [collector/master] Use StandardCharsets.US_ASCII instead of "US-ASCII".
commit 7338d79d1abcfd04857a10818d076d6a7917649b
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date: Wed Nov 20 11:49:54 2019 +0100
Use StandardCharsets.US_ASCII instead of "US-ASCII".
---
.../collector/bridgedescs/BridgeDescriptorParser.java | 3 ++-
.../collector/bridgedescs/BridgeSnapshotReader.java | 3 ++-
.../collector/bridgedescs/SanitizedBridgesWriter.java | 6 +++---
.../metrics/collector/relaydescs/ArchiveReader.java | 2 +-
.../relaydescs/CachedRelayDescriptorReader.java | 7 ++++---
.../collector/relaydescs/RelayDescriptorParser.java | 9 +++++----
.../collector/relaydescs/ReferenceCheckerTest.java | 16 ++++++++--------
7 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/src/main/java/org/torproject/metrics/collector/bridgedescs/BridgeDescriptorParser.java b/src/main/java/org/torproject/metrics/collector/bridgedescs/BridgeDescriptorParser.java
index 04460c8..778d187 100644
--- a/src/main/java/org/torproject/metrics/collector/bridgedescs/BridgeDescriptorParser.java
+++ b/src/main/java/org/torproject/metrics/collector/bridgedescs/BridgeDescriptorParser.java
@@ -9,6 +9,7 @@ import org.slf4j.LoggerFactory;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
public class BridgeDescriptorParser {
@@ -33,7 +34,7 @@ public class BridgeDescriptorParser {
String authorityFingerprint) {
try {
BufferedReader br = new BufferedReader(new StringReader(
- new String(allData, "US-ASCII")));
+ new String(allData, StandardCharsets.US_ASCII)));
String line = br.readLine();
if (line == null) {
return;
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 68ee28b..041807e 100644
--- a/src/main/java/org/torproject/metrics/collector/bridgedescs/BridgeSnapshotReader.java
+++ b/src/main/java/org/torproject/metrics/collector/bridgedescs/BridgeSnapshotReader.java
@@ -20,6 +20,7 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
@@ -139,7 +140,7 @@ public class BridgeSnapshotReader {
}
String fileDigest = Hex.encodeHexString(DigestUtils.sha1(
allData));
- String ascii = new String(allData, "US-ASCII");
+ String ascii = new String(allData, StandardCharsets.US_ASCII);
BufferedReader br3 = new BufferedReader(new StringReader(
ascii));
String firstLine;
diff --git a/src/main/java/org/torproject/metrics/collector/bridgedescs/SanitizedBridgesWriter.java b/src/main/java/org/torproject/metrics/collector/bridgedescs/SanitizedBridgesWriter.java
index 921396c..45f2a1a 100644
--- a/src/main/java/org/torproject/metrics/collector/bridgedescs/SanitizedBridgesWriter.java
+++ b/src/main/java/org/torproject/metrics/collector/bridgedescs/SanitizedBridgesWriter.java
@@ -470,7 +470,7 @@ public class SanitizedBridgesWriter extends CollecTorMain {
try {
DescriptorBuilder scrubbed = new DescriptorBuilder();
BufferedReader br = new BufferedReader(new StringReader(new String(
- data, "US-ASCII")));
+ data, StandardCharsets.US_ASCII)));
String line;
String mostRecentDescPublished = null;
byte[] fingerprintBytes = null;
@@ -682,7 +682,7 @@ public class SanitizedBridgesWriter extends CollecTorMain {
String masterKeyEd25519FromIdentityEd25519 = null;
DescriptorBuilder scrubbed = new DescriptorBuilder();
try (BufferedReader br = new BufferedReader(new StringReader(
- new String(data, "US-ASCII")))) {
+ new String(data, StandardCharsets.US_ASCII)))) {
scrubbed.append(Annotation.BridgeServer.toString());
String line;
String masterKeyEd25519 = null;
@@ -1112,7 +1112,7 @@ public class SanitizedBridgesWriter extends CollecTorMain {
String masterKeyEd25519FromIdentityEd25519 = null;
try {
BufferedReader br = new BufferedReader(new StringReader(new String(
- data, "US-ASCII")));
+ data, StandardCharsets.US_ASCII)));
String line;
DescriptorBuilder scrubbed = null;
String hashedBridgeIdentity;
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 fee46c9..3326833 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/ArchiveReader.java
@@ -184,7 +184,7 @@ public class ArchiveReader {
bis.close();
byte[] allData = baos.toByteArray();
BufferedReader br = new BufferedReader(new StringReader(
- new String(allData, "US-ASCII")));
+ new String(allData, StandardCharsets.US_ASCII)));
String line;
do {
line = br.readLine();
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 0308f05..0a8012a 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/CachedRelayDescriptorReader.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/CachedRelayDescriptorReader.java
@@ -18,6 +18,7 @@ import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
@@ -130,7 +131,7 @@ public class CachedRelayDescriptorReader {
if (f.getName().equals("cached-consensus")) {
/* Check if directory information is stale. */
BufferedReader br = new BufferedReader(new StringReader(
- new String(allData, "US-ASCII")));
+ new String(allData, StandardCharsets.US_ASCII)));
String line;
while ((line = br.readLine()) != null) {
if (line.startsWith("valid-after ")) {
@@ -166,7 +167,7 @@ public class CachedRelayDescriptorReader {
} else if (f.getName().equals("v3-status-votes")) {
int parsedNum = 0;
int skippedNum = 0;
- String ascii = new String(allData, "US-ASCII");
+ String ascii = new String(allData, StandardCharsets.US_ASCII);
String startToken = "network-status-version ";
int end = ascii.length();
int start = ascii.indexOf(startToken);
@@ -197,7 +198,7 @@ public class CachedRelayDescriptorReader {
.append(" votes");
} else if (f.getName().startsWith("cached-descriptors")
|| f.getName().startsWith("cached-extrainfo")) {
- String ascii = new String(allData, "US-ASCII");
+ String ascii = new String(allData, StandardCharsets.US_ASCII);
int start;
int sig;
int end = -1;
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 a610ed9..abbd777 100644
--- a/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorParser.java
+++ b/src/main/java/org/torproject/metrics/collector/relaydescs/RelayDescriptorParser.java
@@ -13,6 +13,7 @@ import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.StringReader;
+import java.nio.charset.StandardCharsets;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
@@ -83,7 +84,7 @@ public class RelayDescriptorParser {
* the non-ASCII chars, but we don't care about them for parsing
* anyway. */
BufferedReader br = new BufferedReader(new StringReader(new String(
- data, "US-ASCII")));
+ data, StandardCharsets.US_ASCII)));
String line;
do {
line = br.readLine();
@@ -209,7 +210,7 @@ public class RelayDescriptorParser {
break;
default:
if (this.aw != null || this.rdd != null) {
- String ascii = new String(data, "US-ASCII");
+ String ascii = new String(data, StandardCharsets.US_ASCII);
String startToken = "network-status-version ";
String sigToken = "directory-signature ";
int start = ascii.indexOf(startToken);
@@ -260,7 +261,7 @@ public class RelayDescriptorParser {
: line.split(" ")[1].toLowerCase();
}
}
- String ascii = new String(data, "US-ASCII");
+ String ascii = new String(data, StandardCharsets.US_ASCII);
String startToken = "router ";
String sigToken = "\nrouter-signature\n";
int start = ascii.indexOf(startToken);
@@ -290,7 +291,7 @@ public class RelayDescriptorParser {
published = parseFormat.parse(publishedTime).getTime();
}
}
- String ascii = new String(data, "US-ASCII");
+ String ascii = new String(data, StandardCharsets.US_ASCII);
String startToken = "extra-info ";
String sigToken = "\nrouter-signature\n";
String digest = null;
diff --git a/src/test/java/org/torproject/metrics/collector/relaydescs/ReferenceCheckerTest.java b/src/test/java/org/torproject/metrics/collector/relaydescs/ReferenceCheckerTest.java
index 19672fc..9489315 100644
--- a/src/test/java/org/torproject/metrics/collector/relaydescs/ReferenceCheckerTest.java
+++ b/src/test/java/org/torproject/metrics/collector/relaydescs/ReferenceCheckerTest.java
@@ -12,7 +12,7 @@ import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import java.io.File;
-import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
public class ReferenceCheckerTest {
@@ -36,12 +36,12 @@ public class ReferenceCheckerTest {
File histFile = tmpf.newFile();
Files.write(refsFile.toPath(), validReferenceJson.getBytes());
assertEquals(validReferenceJson, Files.readAllLines(refsFile.toPath(),
- Charset.forName("US-ASCII")).get(0));
+ StandardCharsets.US_ASCII).get(0));
ReferenceChecker rc = new ReferenceChecker(descDir, refsFile, histFile);
rc.check();
assertTrue(refsFile.exists());
assertEquals(validReferenceJson, Files.readAllLines(refsFile.toPath(),
- Charset.forName("US-ASCII")).get(0));
+ StandardCharsets.US_ASCII).get(0));
}
@Test()
@@ -52,12 +52,12 @@ public class ReferenceCheckerTest {
String badJson = "[{\"xx\":7]}";
Files.write(refsFile.toPath(), badJson.getBytes());
assertEquals(badJson, Files.readAllLines(refsFile.toPath(),
- Charset.forName("US-ASCII")).get(0));
+ StandardCharsets.US_ASCII).get(0));
ReferenceChecker rc = new ReferenceChecker(descDir, refsFile, histFile);
rc.check();
assertTrue(refsFile.exists());
assertEquals("[]", Files.readAllLines(refsFile.toPath(),
- Charset.forName("US-ASCII")).get(0));
+ StandardCharsets.US_ASCII).get(0));
}
@Test()
@@ -70,7 +70,7 @@ public class ReferenceCheckerTest {
rc.check();
assertTrue(refsFile.exists());
assertEquals("The file's contents shouldn't have changed, but did.", "[]",
- Files.readAllLines(refsFile.toPath(), Charset.forName("US-ASCII"))
+ Files.readAllLines(refsFile.toPath(), StandardCharsets.US_ASCII)
.get(0));
}
@@ -87,13 +87,13 @@ public class ReferenceCheckerTest {
Files.write(refsFile.toPath(), validEmptyReferencedString.getBytes());
assertEquals(validEmptyReferencedString,
Files.readAllLines(refsFile.toPath(),
- Charset.forName("US-ASCII")).get(0));
+ StandardCharsets.US_ASCII).get(0));
ReferenceChecker rc = new ReferenceChecker(descDir, refsFile, histFile);
rc.check();
assertTrue(refsFile.exists());
assertEquals(validEmptyReferencedString,
Files.readAllLines(refsFile.toPath(),
- Charset.forName("US-ASCII")).get(0));
+ StandardCharsets.US_ASCII).get(0));
}
}
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits