use of com.google.common.base.Splitter in project bitcoin-wallet by bitcoin-wallet.
the class RequestWalletBalanceTask method loadElectrumServers.
private static List<ElectrumServer> loadElectrumServers(final InputStream is) {
final Splitter splitter = Splitter.on(':').trimResults();
final List<ElectrumServer> servers = new LinkedList<>();
String line = null;
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8))) {
while (true) {
line = reader.readLine();
if (line == null)
break;
line = line.trim();
if (line.length() == 0 || line.charAt(0) == '#')
continue;
final Iterator<String> i = splitter.split(line).iterator();
final String type = i.next();
final String host = i.next();
final String port = i.hasNext() ? Strings.emptyToNull(i.next()) : null;
final String fingerprint = i.hasNext() ? Strings.emptyToNull(i.next()) : null;
servers.add(new ElectrumServer(type, host, port, fingerprint));
}
} catch (final Exception x) {
throw new RuntimeException("Error while parsing: '" + line + "'", x);
}
return servers;
}
Aggregations