[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [metrics-lib/master] Checkstyle complaints reduced to three.
commit 72942181589bfe2118df316dc4850681213fad25
Author: iwakeh <iwakeh@xxxxxxxxxxxxxx>
Date: Wed Jul 6 18:14:46 2016 +0000
Checkstyle complaints reduced to three.
---
.gitignore | 1 +
.../descriptor/DescriptorParseException.java | 5 ++++
.../descriptor/DescriptorSourceFactory.java | 12 ++++------
.../ImplementationNotAccessibleException.java | 9 +++++--
.../descriptor/impl/BlockingIteratorImpl.java | 3 +++
.../descriptor/impl/BridgeNetworkStatusImpl.java | 10 ++++----
.../descriptor/impl/BridgePoolAssignmentImpl.java | 6 ++---
.../descriptor/impl/DescriptorCollectorImpl.java | 28 +++++++++++-----------
.../torproject/descriptor/impl/DescriptorImpl.java | 6 ++---
.../descriptor/impl/DescriptorParseException.java | 5 ++++
.../descriptor/impl/DirSourceEntryImpl.java | 6 ++---
.../descriptor/impl/DirectoryDownloader.java | 6 ++---
.../impl/DirectoryKeyCertificateImpl.java | 6 ++---
.../descriptor/impl/DirectorySignatureImpl.java | 6 ++---
.../descriptor/impl/ExitListEntryImpl.java | 6 ++---
.../torproject/descriptor/impl/ExitListImpl.java | 10 ++++----
.../descriptor/impl/ExtraInfoDescriptorImpl.java | 6 ++---
.../descriptor/impl/MicrodescriptorImpl.java | 6 ++---
.../descriptor/impl/NetworkStatusEntryImpl.java | 12 +++++-----
.../descriptor/impl/NetworkStatusImpl.java | 16 ++++++-------
.../torproject/descriptor/impl/ParseHelper.java | 4 ++--
.../descriptor/impl/RelayDirectoryImpl.java | 14 +++++------
.../impl/RelayNetworkStatusConsensusImpl.java | 12 +++++-----
.../descriptor/impl/RelayNetworkStatusImpl.java | 12 +++++-----
.../impl/RelayNetworkStatusVoteImpl.java | 12 +++++-----
.../descriptor/impl/ServerDescriptorImpl.java | 6 ++---
.../descriptor/impl/TorperfResultImpl.java | 6 ++---
27 files changed, 123 insertions(+), 108 deletions(-)
diff --git a/.gitignore b/.gitignore
index ff410d7..bb59c26 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
classes/
+generated/
lib/
descriptor-*.jar
descriptor-*.tar.gz
diff --git a/src/main/java/org/torproject/descriptor/DescriptorParseException.java b/src/main/java/org/torproject/descriptor/DescriptorParseException.java
index 731db3e..65e774a 100644
--- a/src/main/java/org/torproject/descriptor/DescriptorParseException.java
+++ b/src/main/java/org/torproject/descriptor/DescriptorParseException.java
@@ -18,5 +18,10 @@ public class DescriptorParseException
public DescriptorParseException(String message) {
super(message);
}
+
+ public DescriptorParseException(String message, Exception ex) {
+ super(message, ex);
+ }
+
}
diff --git a/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java b/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java
index f51434f..9c78e5c 100644
--- a/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java
+++ b/src/main/java/org/torproject/descriptor/DescriptorSourceFactory.java
@@ -168,16 +168,14 @@ public final class DescriptorSourceFactory {
case COLLECTOR_PROPERTY:
clazzName = System.getProperty(type, COLLECTOR_DEFAULT);
break;
+ default:
+ throw new ImplementationNotAccessibleException("Cannot "
+ + "retrieve class for type " + type + ".");
}
object = ClassLoader.getSystemClassLoader().loadClass(clazzName)
.newInstance();
- } catch (ClassNotFoundException ex) {
- throw new ImplementationNotAccessibleException("Cannot load class "
- + clazzName + "for type " + type, ex);
- } catch (InstantiationException ex) {
- throw new ImplementationNotAccessibleException("Cannot load class "
- + clazzName + "for type " + type, ex);
- } catch (IllegalAccessException ex) {
+ } catch (ClassNotFoundException | InstantiationException
+ | IllegalAccessException ex) {
throw new ImplementationNotAccessibleException("Cannot load class "
+ clazzName + "for type " + type, ex);
}
diff --git a/src/main/java/org/torproject/descriptor/ImplementationNotAccessibleException.java b/src/main/java/org/torproject/descriptor/ImplementationNotAccessibleException.java
index c54e48f..1c7e937 100644
--- a/src/main/java/org/torproject/descriptor/ImplementationNotAccessibleException.java
+++ b/src/main/java/org/torproject/descriptor/ImplementationNotAccessibleException.java
@@ -14,9 +14,14 @@ package org.torproject.descriptor;
public class ImplementationNotAccessibleException
extends RuntimeException {
- public ImplementationNotAccessibleException(String string,
+ public ImplementationNotAccessibleException(String message,
Throwable ex) {
- super(string, ex);
+ super(message, ex);
}
+
+ public ImplementationNotAccessibleException(String message) {
+ super(message);
+ }
+
}
diff --git a/src/main/java/org/torproject/descriptor/impl/BlockingIteratorImpl.java b/src/main/java/org/torproject/descriptor/impl/BlockingIteratorImpl.java
index 7ec395b..3e7fa86 100644
--- a/src/main/java/org/torproject/descriptor/impl/BlockingIteratorImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/BlockingIteratorImpl.java
@@ -39,6 +39,7 @@ public class BlockingIteratorImpl<T> implements Iterator<T> {
try {
wait();
} catch (InterruptedException e) {
+ /* nothing to be done */
}
}
this.queue.offer(object);
@@ -66,6 +67,7 @@ public class BlockingIteratorImpl<T> implements Iterator<T> {
try {
wait();
} catch (InterruptedException e) {
+ /* nothing to be done */
}
}
return this.queue.peek() != null;
@@ -81,6 +83,7 @@ public class BlockingIteratorImpl<T> implements Iterator<T> {
try {
wait();
} catch (InterruptedException e) {
+ /* nothing to be done */
}
}
if (this.queue.peek() == null) {
diff --git a/src/main/java/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java b/src/main/java/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java
index ab44452..6a56d44 100644
--- a/src/main/java/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/BridgeNetworkStatusImpl.java
@@ -45,6 +45,8 @@ public class BridgeNetworkStatusImpl extends NetworkStatusImpl
this.publishedMillis = fileNameFormat.parse(publishedString)
.getTime();
} catch (ParseException e) {
+ throw new DescriptorParseException("Cannot parse published time "
+ + "for status file name '" + fileName + "'.", e);
}
}
if (this.publishedMillis == 0L) {
@@ -69,9 +71,9 @@ public class BridgeNetworkStatusImpl extends NetworkStatusImpl
this.enoughMtbfInfo = -1;
this.ignoringAdvertisedBws = -1;
- Scanner s = new Scanner(new String(headerBytes)).useDelimiter("\n");
- while (s.hasNext()) {
- String line = s.next();
+ Scanner scanner = new Scanner(new String(headerBytes)).useDelimiter("\n");
+ while (scanner.hasNext()) {
+ String line = scanner.next();
String[] parts = line.split("[ \t]+");
String keyword = parts[0];
switch (keyword) {
@@ -146,7 +148,7 @@ public class BridgeNetworkStatusImpl extends NetworkStatusImpl
}
} catch (NumberFormatException ex) {
throw new DescriptorParseException("Illegal value in line '"
- + line + "'.");
+ + line + "'.", ex);
}
}
diff --git a/src/main/java/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java b/src/main/java/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java
index 75451a2..c4f04cf 100644
--- a/src/main/java/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/BridgePoolAssignmentImpl.java
@@ -48,10 +48,10 @@ public class BridgePoolAssignmentImpl extends DescriptorImpl
}
private void parseDescriptorBytes() throws DescriptorParseException {
- Scanner s = new Scanner(new String(this.rawDescriptorBytes))
+ Scanner scanner = new Scanner(new String(this.rawDescriptorBytes))
.useDelimiter("\n");
- while (s.hasNext()) {
- String line = s.next();
+ while (scanner.hasNext()) {
+ String line = scanner.next();
if (line.startsWith("bridge-pool-assignment ")) {
this.parseBridgePoolAssignmentLine(line);
} else {
diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorCollectorImpl.java b/src/main/java/org/torproject/descriptor/impl/DescriptorCollectorImpl.java
index fb6aa2e..9aa3e62 100644
--- a/src/main/java/org/torproject/descriptor/impl/DescriptorCollectorImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/DescriptorCollectorImpl.java
@@ -111,12 +111,12 @@ public class DescriptorCollectorImpl implements DescriptorCollector {
return fetchedDirectoryListings;
}
- String fetchRemoteDirectory(String url) {
+ String fetchRemoteDirectory(String urlString) {
StringBuilder sb = new StringBuilder();
HttpURLConnection huc = null;
try {
- URL u = new URL(url);
- huc = (HttpURLConnection) u.openConnection();
+ URL url = new URL(urlString);
+ huc = (HttpURLConnection) url.openConnection();
huc.setRequestMethod("GET");
huc.connect();
int responseCode = huc.getResponseCode();
@@ -139,7 +139,7 @@ public class DescriptorCollectorImpl implements DescriptorCollector {
return sb.toString();
}
- final Pattern DIRECTORY_LISTING_LINE_PATTERN =
+ final Pattern directoryListingLinePattern =
Pattern.compile(".* href=\"([^\"/]+)\"" /* filename */
+ ".*>(\\d{2}-\\w{3}-\\d{4} \\d{2}:\\d{2})\\s*<.*"); /* dateTime */
@@ -149,11 +149,11 @@ public class DescriptorCollectorImpl implements DescriptorCollector {
DateFormat dateTimeFormat = ParseHelper.getDateFormat(
"dd-MMM-yyyy HH:mm");
try {
- Scanner s = new Scanner(directoryListing);
- s.useDelimiter("\n");
- while (s.hasNext()) {
- String line = s.next();
- Matcher matcher = DIRECTORY_LISTING_LINE_PATTERN.matcher(line);
+ Scanner scanner = new Scanner(directoryListing);
+ scanner.useDelimiter("\n");
+ while (scanner.hasNext()) {
+ String line = scanner.next();
+ Matcher matcher = directoryListingLinePattern.matcher(line);
if (matcher.matches()) {
String filename = matcher.group(1);
long lastModifiedMillis = dateTimeFormat.parse(
@@ -161,7 +161,7 @@ public class DescriptorCollectorImpl implements DescriptorCollector {
remoteFiles.put(remoteDirectory + filename, lastModifiedMillis);
}
}
- s.close();
+ scanner.close();
} catch (ParseException e) {
e.printStackTrace();
return null;
@@ -187,7 +187,7 @@ public class DescriptorCollectorImpl implements DescriptorCollector {
}
}
- void fetchRemoteFile(String url, File destinationFile,
+ void fetchRemoteFile(String urlString, File destinationFile,
long lastModifiedMillis) {
HttpURLConnection huc = null;
try {
@@ -197,10 +197,10 @@ public class DescriptorCollectorImpl implements DescriptorCollector {
+ destinationFile.getName());
BufferedOutputStream bos = new BufferedOutputStream(
new FileOutputStream(tempDestinationFile));
- URL u = new URL(url);
- huc = (HttpURLConnection) u.openConnection();
+ URL url = new URL(urlString);
+ huc = (HttpURLConnection) url.openConnection();
huc.setRequestMethod("GET");
- if (!url.endsWith(".xz")) {
+ if (!urlString.endsWith(".xz")) {
huc.addRequestProperty("Accept-Encoding", "gzip");
}
huc.connect();
diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/DescriptorImpl.java
index e16e1ee..718321a 100644
--- a/src/main/java/org/torproject/descriptor/impl/DescriptorImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/DescriptorImpl.java
@@ -235,9 +235,9 @@ public abstract class DescriptorImpl implements Descriptor {
throw new DescriptorParseException("Blank lines are not allowed.");
}
boolean skipCrypto = false;
- Scanner s = new Scanner(descriptorString).useDelimiter("\n");
- while (s.hasNext()) {
- String line = s.next();
+ Scanner scanner = new Scanner(descriptorString).useDelimiter("\n");
+ while (scanner.hasNext()) {
+ String line = scanner.next();
if (line.startsWith("-----BEGIN")) {
skipCrypto = true;
} else if (line.startsWith("-----END")) {
diff --git a/src/main/java/org/torproject/descriptor/impl/DescriptorParseException.java b/src/main/java/org/torproject/descriptor/impl/DescriptorParseException.java
index 22959c9..0ac4d2c 100644
--- a/src/main/java/org/torproject/descriptor/impl/DescriptorParseException.java
+++ b/src/main/java/org/torproject/descriptor/impl/DescriptorParseException.java
@@ -14,5 +14,10 @@ package org.torproject.descriptor.impl;
protected DescriptorParseException(String message) {
super(message);
}
+
+ protected DescriptorParseException(String message, Exception ex) {
+ super(message, ex);
+ }
+
}
diff --git a/src/main/java/org/torproject/descriptor/impl/DirSourceEntryImpl.java b/src/main/java/org/torproject/descriptor/impl/DirSourceEntryImpl.java
index 2898f3d..f053a9d 100644
--- a/src/main/java/org/torproject/descriptor/impl/DirSourceEntryImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/DirSourceEntryImpl.java
@@ -83,11 +83,11 @@ public class DirSourceEntryImpl implements DirSourceEntry {
private void parseDirSourceEntryBytes()
throws DescriptorParseException {
- Scanner s = new Scanner(new String(this.dirSourceEntryBytes))
+ Scanner scanner = new Scanner(new String(this.dirSourceEntryBytes))
.useDelimiter("\n");
boolean skipCrypto = false;
- while (s.hasNext()) {
- String line = s.next();
+ while (scanner.hasNext()) {
+ String line = scanner.next();
String[] parts = line.split(" ");
switch (parts[0]) {
case "dir-source":
diff --git a/src/main/java/org/torproject/descriptor/impl/DirectoryDownloader.java b/src/main/java/org/torproject/descriptor/impl/DirectoryDownloader.java
index 89cf721..5d7d4a9 100644
--- a/src/main/java/org/torproject/descriptor/impl/DirectoryDownloader.java
+++ b/src/main/java/org/torproject/descriptor/impl/DirectoryDownloader.java
@@ -63,13 +63,13 @@ public class DirectoryDownloader implements Runnable {
DescriptorRequestImpl request =
this.downloadCoordinator.createRequest(this.nickname);
if (request != null) {
- String url = "http://" + this.ipPort
+ String urlString = "http://" + this.ipPort
+ request.getRequestedResource();
request.setRequestStart(System.currentTimeMillis());
HttpURLConnection huc = null;
try {
- URL u = new URL(url);
- huc = (HttpURLConnection) u.openConnection();
+ URL url = new URL(urlString);
+ huc = (HttpURLConnection) url.openConnection();
huc.setConnectTimeout((int) this.connectTimeout);
huc.setReadTimeout((int) this.readTimeout);
huc.setRequestMethod("GET");
diff --git a/src/main/java/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java b/src/main/java/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
index 28bc65d..21a992d 100644
--- a/src/main/java/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/DirectoryKeyCertificateImpl.java
@@ -59,12 +59,12 @@ public class DirectoryKeyCertificateImpl extends DescriptorImpl
}
private void parseDescriptorBytes() throws DescriptorParseException {
- Scanner s = new Scanner(new String(this.rawDescriptorBytes))
+ Scanner scanner = new Scanner(new String(this.rawDescriptorBytes))
.useDelimiter("\n");
String nextCrypto = "";
StringBuilder crypto = null;
- while (s.hasNext()) {
- String line = s.next();
+ while (scanner.hasNext()) {
+ String line = scanner.next();
String[] parts = line.split("[ \t]+");
String keyword = parts[0];
switch (keyword) {
diff --git a/src/main/java/org/torproject/descriptor/impl/DirectorySignatureImpl.java b/src/main/java/org/torproject/descriptor/impl/DirectorySignatureImpl.java
index b2fa705..744bc51 100644
--- a/src/main/java/org/torproject/descriptor/impl/DirectorySignatureImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/DirectorySignatureImpl.java
@@ -35,11 +35,11 @@ public class DirectorySignatureImpl implements DirectorySignature {
private void parseDirectorySignatureBytes()
throws DescriptorParseException {
- Scanner s = new Scanner(new String(this.directorySignatureBytes))
+ Scanner scanner = new Scanner(new String(this.directorySignatureBytes))
.useDelimiter("\n");
StringBuilder crypto = null;
- while (s.hasNext()) {
- String line = s.next();
+ while (scanner.hasNext()) {
+ String line = scanner.next();
String[] parts = line.split(" ", -1);
String keyword = parts[0];
switch (keyword) {
diff --git a/src/main/java/org/torproject/descriptor/impl/ExitListEntryImpl.java b/src/main/java/org/torproject/descriptor/impl/ExitListEntryImpl.java
index 1f92afd..5e4bbd2 100644
--- a/src/main/java/org/torproject/descriptor/impl/ExitListEntryImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/ExitListEntryImpl.java
@@ -94,10 +94,10 @@ public class ExitListEntryImpl implements ExitListEntry, ExitList.Entry {
private void parseExitListEntryBytes()
throws DescriptorParseException {
- Scanner s = new Scanner(new String(this.exitListEntryBytes))
+ Scanner scanner = new Scanner(new String(this.exitListEntryBytes))
.useDelimiter(ExitList.EOL);
- while (s.hasNext()) {
- String line = s.next();
+ while (scanner.hasNext()) {
+ String line = scanner.next();
String[] parts = line.split(" ");
String keyword = parts[0];
switch (keyword) {
diff --git a/src/main/java/org/torproject/descriptor/impl/ExitListImpl.java b/src/main/java/org/torproject/descriptor/impl/ExitListImpl.java
index 6470130..9afee31 100644
--- a/src/main/java/org/torproject/descriptor/impl/ExitListImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/ExitListImpl.java
@@ -52,16 +52,16 @@ public class ExitListImpl extends DescriptorImpl implements ExitList {
throw new DescriptorParseException("Descriptor is empty.");
}
String descriptorString = new String(rawDescriptorBytes);
- Scanner s = new Scanner(descriptorString).useDelimiter(EOL);
+ Scanner scanner = new Scanner(descriptorString).useDelimiter(EOL);
StringBuilder sb = new StringBuilder();
boolean firstEntry = true;
- while (s.hasNext()) {
- String line = s.next();
+ while (scanner.hasNext()) {
+ String line = scanner.next();
if (line.startsWith("@")) { /* Skip annotation. */
- if (!s.hasNext()) {
+ if (!scanner.hasNext()) {
throw new DescriptorParseException("Descriptor is empty.");
} else {
- line = s.next();
+ line = scanner.next();
}
}
String[] parts = line.split(" ");
diff --git a/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
index 586d385..154c86b 100644
--- a/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/ExtraInfoDescriptorImpl.java
@@ -78,12 +78,12 @@ public abstract class ExtraInfoDescriptorImpl extends DescriptorImpl
}
private void parseDescriptorBytes() throws DescriptorParseException {
- Scanner s = new Scanner(new String(this.rawDescriptorBytes))
+ Scanner scanner = new Scanner(new String(this.rawDescriptorBytes))
.useDelimiter("\n");
String nextCrypto = "";
List<String> cryptoLines = null;
- while (s.hasNext()) {
- String line = s.next();
+ while (scanner.hasNext()) {
+ String line = scanner.next();
String lineNoOpt = line.startsWith("opt ")
? line.substring("opt ".length()) : line;
String[] partsNoOpt = lineNoOpt.split("[ \t]+");
diff --git a/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java
index c1f607b..ab859a0 100644
--- a/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/MicrodescriptorImpl.java
@@ -56,12 +56,12 @@ public class MicrodescriptorImpl extends DescriptorImpl
}
private void parseDescriptorBytes() throws DescriptorParseException {
- Scanner s = new Scanner(new String(this.rawDescriptorBytes))
+ Scanner scanner = new Scanner(new String(this.rawDescriptorBytes))
.useDelimiter("\n");
String nextCrypto = "";
StringBuilder crypto = null;
- while (s.hasNext()) {
- String line = s.next();
+ while (scanner.hasNext()) {
+ String line = scanner.next();
if (line.startsWith("@")) {
continue;
}
diff --git a/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java b/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
index b21bb60..807dd76 100644
--- a/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/NetworkStatusEntryImpl.java
@@ -71,17 +71,17 @@ public class NetworkStatusEntryImpl implements NetworkStatusEntry {
}
private void parseStatusEntryBytes() throws DescriptorParseException {
- Scanner s = new Scanner(new String(this.statusEntryBytes))
+ Scanner scanner = new Scanner(new String(this.statusEntryBytes))
.useDelimiter("\n");
String line = null;
- if (!s.hasNext() || !(line = s.next()).startsWith("r ")) {
+ if (!scanner.hasNext() || !(line = scanner.next()).startsWith("r ")) {
throw new DescriptorParseException("Status entry must start with "
+ "an r line.");
}
- String[] rLineParts = line.split("[ \t]+");
- this.parseRLine(line, rLineParts);
- while (s.hasNext()) {
- line = s.next();
+ String[] rlineParts = line.split("[ \t]+");
+ this.parseRLine(line, rlineParts);
+ while (scanner.hasNext()) {
+ line = scanner.next();
String[] parts = !line.startsWith("opt ") ? line.split("[ \t]+")
: line.substring("opt ".length()).split("[ \t]+");
String keyword = parts[0];
diff --git a/src/main/java/org/torproject/descriptor/impl/NetworkStatusImpl.java b/src/main/java/org/torproject/descriptor/impl/NetworkStatusImpl.java
index c458961..b6c274d 100644
--- a/src/main/java/org/torproject/descriptor/impl/NetworkStatusImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/NetworkStatusImpl.java
@@ -34,30 +34,28 @@ public abstract class NetworkStatusImpl extends DescriptorImpl {
throw new DescriptorParseException("Descriptor is empty.");
}
String descriptorString = new String(rawDescriptorBytes);
- int startIndex = 0;
- int firstDirSourceIndex = !containsDirSourceEntries ? -1
- : this.findFirstIndexOfKeyword(descriptorString, "dir-source");
int firstRIndex = this.findFirstIndexOfKeyword(descriptorString, "r");
- int directoryFooterIndex = this.findFirstIndexOfKeyword(
- descriptorString, "directory-footer");
+ int endIndex = descriptorString.length();
int firstDirectorySignatureIndex = this.findFirstIndexOfKeyword(
descriptorString, "directory-signature");
- int endIndex = descriptorString.length();
if (firstDirectorySignatureIndex < 0) {
firstDirectorySignatureIndex = endIndex;
}
+ int directoryFooterIndex = this.findFirstIndexOfKeyword(
+ descriptorString, "directory-footer");
if (directoryFooterIndex < 0) {
directoryFooterIndex = firstDirectorySignatureIndex;
}
if (firstRIndex < 0) {
firstRIndex = directoryFooterIndex;
}
+ int firstDirSourceIndex = !containsDirSourceEntries ? -1
+ : this.findFirstIndexOfKeyword(descriptorString, "dir-source");
if (firstDirSourceIndex < 0) {
firstDirSourceIndex = firstRIndex;
}
- if (firstDirSourceIndex > startIndex) {
- this.parseHeaderBytes(descriptorString, startIndex,
- firstDirSourceIndex);
+ if (firstDirSourceIndex > 0) {
+ this.parseHeaderBytes(descriptorString, 0, firstDirSourceIndex);
}
if (firstRIndex > firstDirSourceIndex) {
this.parseDirSourceBytes(descriptorString, firstDirSourceIndex,
diff --git a/src/main/java/org/torproject/descriptor/impl/ParseHelper.java b/src/main/java/org/torproject/descriptor/impl/ParseHelper.java
index fb57e93..86d53a1 100644
--- a/src/main/java/org/torproject/descriptor/impl/ParseHelper.java
+++ b/src/main/java/org/torproject/descriptor/impl/ParseHelper.java
@@ -285,9 +285,9 @@ public class ParseHelper {
return nickname;
}
- protected static boolean parseBoolean(String b, String line)
+ protected static boolean parseBoolean(String boolString, String line)
throws DescriptorParseException {
- switch (b) {
+ switch (boolString) {
case "1":
return true;
case "0":
diff --git a/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java b/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java
index 69709ad..4f29a90 100644
--- a/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/RelayDirectoryImpl.java
@@ -20,8 +20,6 @@ import java.util.Set;
import javax.xml.bind.DatatypeConverter;
-/* TODO Write unit tests. */
-
public class RelayDirectoryImpl extends DescriptorImpl
implements RelayDirectory {
@@ -189,14 +187,14 @@ public class RelayDirectoryImpl extends DescriptorImpl
private void parseHeader(byte[] headerBytes)
throws DescriptorParseException {
- Scanner s = new Scanner(new String(headerBytes)).useDelimiter("\n");
+ Scanner scanner = new Scanner(new String(headerBytes)).useDelimiter("\n");
String publishedLine = null;
String nextCrypto = "";
String runningRoutersLine = null;
String routerStatusLine = null;
StringBuilder crypto = null;
- while (s.hasNext()) {
- String line = s.next();
+ while (scanner.hasNext()) {
+ String line = scanner.next();
if (line.isEmpty() || line.startsWith("@")) {
continue;
}
@@ -309,12 +307,12 @@ public class RelayDirectoryImpl extends DescriptorImpl
private void parseDirectorySignature(byte[] directorySignatureBytes)
throws DescriptorParseException {
- Scanner s = new Scanner(new String(directorySignatureBytes))
+ Scanner scanner = new Scanner(new String(directorySignatureBytes))
.useDelimiter("\n");
String nextCrypto = "";
StringBuilder crypto = null;
- while (s.hasNext()) {
- String line = s.next();
+ while (scanner.hasNext()) {
+ String line = scanner.next();
String lineNoOpt = line.startsWith("opt ")
? line.substring("opt ".length()) : line;
String[] partsNoOpt = lineNoOpt.split("[ \t]+");
diff --git a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
index 87971a4..66ab776 100644
--- a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusConsensusImpl.java
@@ -91,9 +91,9 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl
protected void parseHeader(byte[] headerBytes)
throws DescriptorParseException {
- Scanner s = new Scanner(new String(headerBytes)).useDelimiter("\n");
- while (s.hasNext()) {
- String line = s.next();
+ Scanner scanner = new Scanner(new String(headerBytes)).useDelimiter("\n");
+ while (scanner.hasNext()) {
+ String line = scanner.next();
String[] parts = line.split("[ \t]+");
String keyword = parts[0];
switch (keyword) {
@@ -167,9 +167,9 @@ public class RelayNetworkStatusConsensusImpl extends NetworkStatusImpl
protected void parseFooter(byte[] footerBytes)
throws DescriptorParseException {
- Scanner s = new Scanner(new String(footerBytes)).useDelimiter("\n");
- while (s.hasNext()) {
- String line = s.next();
+ Scanner scanner = new Scanner(new String(footerBytes)).useDelimiter("\n");
+ while (scanner.hasNext()) {
+ String line = scanner.next();
String[] parts = line.split("[ \t]+");
String keyword = parts[0];
switch (keyword) {
diff --git a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
index 1807b33..308c1b2 100644
--- a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusImpl.java
@@ -86,11 +86,11 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
protected void parseHeader(byte[] headerBytes)
throws DescriptorParseException {
- Scanner s = new Scanner(new String(headerBytes)).useDelimiter("\n");
+ Scanner scanner = new Scanner(new String(headerBytes)).useDelimiter("\n");
String nextCrypto = "";
StringBuilder crypto = null;
- while (s.hasNext()) {
- String line = s.next();
+ while (scanner.hasNext()) {
+ String line = scanner.next();
if (line.isEmpty()) {
continue;
}
@@ -165,12 +165,12 @@ public class RelayNetworkStatusImpl extends NetworkStatusImpl
protected void parseDirectorySignature(byte[] directorySignatureBytes)
throws DescriptorParseException {
- Scanner s = new Scanner(new String(directorySignatureBytes))
+ Scanner scanner = new Scanner(new String(directorySignatureBytes))
.useDelimiter("\n");
String nextCrypto = "";
StringBuilder crypto = null;
- while (s.hasNext()) {
- String line = s.next();
+ while (scanner.hasNext()) {
+ String line = scanner.next();
String[] parts = line.split("[ \t]+");
String keyword = parts[0];
switch (keyword) {
diff --git a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
index 8735017..2bf8e88 100644
--- a/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/RelayNetworkStatusVoteImpl.java
@@ -79,11 +79,11 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
this.enoughMtbfInfo = -1;
this.ignoringAdvertisedBws = -1;
- Scanner s = new Scanner(new String(headerBytes)).useDelimiter("\n");
+ Scanner scanner = new Scanner(new String(headerBytes)).useDelimiter("\n");
String nextCrypto = "";
StringBuilder crypto = null;
- while (s.hasNext()) {
- String line = s.next();
+ while (scanner.hasNext()) {
+ String line = scanner.next();
String[] parts = line.split("[ \t]+");
String keyword = parts[0];
switch (keyword) {
@@ -500,9 +500,9 @@ public class RelayNetworkStatusVoteImpl extends NetworkStatusImpl
protected void parseFooter(byte[] footerBytes)
throws DescriptorParseException {
- Scanner s = new Scanner(new String(footerBytes)).useDelimiter("\n");
- while (s.hasNext()) {
- String line = s.next();
+ Scanner scanner = new Scanner(new String(footerBytes)).useDelimiter("\n");
+ while (scanner.hasNext()) {
+ String line = scanner.next();
if (!line.equals("directory-footer")) {
if (this.failUnrecognizedDescriptorLines) {
throw new DescriptorParseException("Unrecognized line '"
diff --git a/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java b/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java
index c75d5a0..08b9271 100644
--- a/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/ServerDescriptorImpl.java
@@ -54,12 +54,12 @@ public abstract class ServerDescriptorImpl extends DescriptorImpl
}
private void parseDescriptorBytes() throws DescriptorParseException {
- Scanner s = new Scanner(new String(this.rawDescriptorBytes))
+ Scanner scanner = new Scanner(new String(this.rawDescriptorBytes))
.useDelimiter("\n");
String nextCrypto = "";
List<String> cryptoLines = null;
- while (s.hasNext()) {
- String line = s.next();
+ while (scanner.hasNext()) {
+ String line = scanner.next();
if (line.startsWith("@")) {
continue;
}
diff --git a/src/main/java/org/torproject/descriptor/impl/TorperfResultImpl.java b/src/main/java/org/torproject/descriptor/impl/TorperfResultImpl.java
index 71c762f..33ca328 100644
--- a/src/main/java/org/torproject/descriptor/impl/TorperfResultImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/TorperfResultImpl.java
@@ -27,10 +27,10 @@ public class TorperfResultImpl extends DescriptorImpl
}
List<Descriptor> parsedDescriptors = new ArrayList<>();
String descriptorString = new String(rawDescriptorBytes);
- Scanner s = new Scanner(descriptorString).useDelimiter("\r?\n");
+ Scanner scanner = new Scanner(descriptorString).useDelimiter("\r?\n");
String typeAnnotation = "";
- while (s.hasNext()) {
- String line = s.next();
+ while (scanner.hasNext()) {
+ String line = scanner.next();
if (line.startsWith("@type torperf ")) {
String[] parts = line.split(" ");
if (parts.length != 3) {
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits