mirror of
https://github.com/torproject/collector.git
synced 2024-11-23 09:29:46 +00:00
Use StandardCharsets.US_ASCII instead of "US-ASCII".
This commit is contained in:
parent
38234a3788
commit
7338d79d1a
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user