Search in sources :

Example 86 with Splitter

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;
}
Also used : Splitter(com.google.common.base.Splitter) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) LinkedList(java.util.LinkedList) ConnectException(java.net.ConnectException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) ExecutionException(java.util.concurrent.ExecutionException) JsonDataException(com.squareup.moshi.JsonDataException) SSLPeerUnverifiedException(javax.net.ssl.SSLPeerUnverifiedException)

Aggregations

Splitter (com.google.common.base.Splitter)86 ArrayList (java.util.ArrayList)19 IOException (java.io.IOException)12 HashSet (java.util.HashSet)10 File (java.io.File)7 HashMap (java.util.HashMap)7 Test (org.junit.Test)5 BufferedReader (java.io.BufferedReader)4 NonNull (com.android.annotations.NonNull)3 URI (java.net.URI)3 URL (java.net.URL)3 ItemStack (net.minecraft.item.ItemStack)3 StringColumn (tech.tablesaw.api.StringColumn)3 CharMatcher (com.google.common.base.CharMatcher)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 CharSource (com.google.common.io.CharSource)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileInputStream (java.io.FileInputStream)2 InputStreamReader (java.io.InputStreamReader)2