Search in sources :

Example 36 with Joiner

use of com.google.common.base.Joiner in project graylog2-server by Graylog2.

the class JsonExtractor method parseValue.

private Collection<Entry> parseValue(String key, Object value) {
    final String processedKey = parseKey(key);
    if (value instanceof Boolean) {
        return Collections.singleton(Entry.create(processedKey, value));
    } else if (value instanceof Number) {
        return Collections.singleton(Entry.create(processedKey, value));
    } else if (value instanceof String) {
        return Collections.singleton(Entry.create(processedKey, value));
    } else if (value instanceof Map) {
        @SuppressWarnings("unchecked") final Map<String, Object> map = (Map<String, Object>) value;
        final Map<String, Object> withoutNull = Maps.filterEntries(map, REMOVE_NULL_PREDICATE);
        if (flatten) {
            final Joiner.MapJoiner joiner = Joiner.on(listSeparator).withKeyValueSeparator(kvSeparator);
            return Collections.singleton(Entry.create(processedKey, joiner.join(withoutNull)));
        } else {
            final List<Entry> result = new ArrayList<>(map.size());
            for (Map.Entry<String, Object> entry : map.entrySet()) {
                result.addAll(parseValue(processedKey + keySeparator + entry.getKey(), entry.getValue()));
            }
            return result;
        }
    } else if (value instanceof List) {
        final List values = (List) value;
        final Joiner joiner = Joiner.on(listSeparator).skipNulls();
        return Collections.singleton(Entry.create(processedKey, joiner.join(values)));
    } else if (value == null) {
        // Ignore null values so we don't try to create fields for that in the message.
        return Collections.emptySet();
    } else {
        LOG.debug("Unknown type \"{}\" in key \"{}\"", value.getClass(), key);
        return Collections.emptySet();
    }
}
Also used : Joiner(com.google.common.base.Joiner) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 37 with Joiner

use of com.google.common.base.Joiner in project Cloud9 by lintool.

the class IntegrationUtils method exec.

// How to properly shell out: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
public static PairOfStrings exec(String cmd) throws IOException, InterruptedException {
    System.out.println("Executing command: " + cmd);
    Runtime rt = Runtime.getRuntime();
    Process proc = rt.exec(cmd);
    // any error message?
    StreamGobbler errorGobbler = new StreamGobbler(proc.getErrorStream(), "STDERR");
    // any output?
    StreamGobbler outputGobbler = new StreamGobbler(proc.getInputStream(), "STDOUT");
    // kick them off
    errorGobbler.start();
    outputGobbler.start();
    // any error???
    int exitVal = proc.waitFor();
    System.out.println("ExitValue: " + exitVal);
    Joiner joiner = Joiner.on("\n");
    return Pair.of(joiner.join(outputGobbler.getLines()), joiner.join(errorGobbler.getLines()));
}
Also used : Joiner(com.google.common.base.Joiner)

Example 38 with Joiner

use of com.google.common.base.Joiner in project alluxio by Alluxio.

the class URIUtils method generateQueryString.

/**
   * Generates a query string from a {@link Map <String, String>} of key/value pairs.
   *
   * @param queryMap the map of query key/value pairs
   * @return the generated query string, null if the input map is null or empty
   */
public static String generateQueryString(Map<String, String> queryMap) {
    if (queryMap == null || queryMap.isEmpty()) {
        return null;
    }
    ArrayList<String> pairs = new ArrayList<>(queryMap.size());
    try {
        for (Map.Entry<String, String> entry : queryMap.entrySet()) {
            pairs.add(URLEncoder.encode(entry.getKey(), "UTF-8") + QUERY_KEY_VALUE_SEPARATOR + URLEncoder.encode(entry.getValue(), "UTF-8"));
        }
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
    Joiner joiner = Joiner.on(QUERY_SEPARATOR);
    return joiner.join(pairs);
}
Also used : Joiner(com.google.common.base.Joiner) ArrayList(java.util.ArrayList) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 39 with Joiner

use of com.google.common.base.Joiner in project google-cloud-java by GoogleCloudPlatform.

the class ResourceManagerExample method addUsage.

private static void addUsage(String actionName, ResourceManagerAction action, StringBuilder usage) {
    usage.append(actionName);
    Joiner joiner = Joiner.on(" ");
    String[] requiredParams = action.getRequiredParams();
    if (requiredParams.length > 0) {
        usage.append(' ');
        joiner.appendTo(usage, requiredParams);
    }
    String[] optionalParams = action.getOptionalParams();
    if (optionalParams.length > 0) {
        usage.append(" [");
        joiner.appendTo(usage, optionalParams);
        usage.append(']');
    }
}
Also used : Joiner(com.google.common.base.Joiner)

Example 40 with Joiner

use of com.google.common.base.Joiner in project jackrabbit-oak by apache.

the class DataStoreCheckCommand method retrieveBlobReferences.

private static void retrieveBlobReferences(GarbageCollectableBlobStore blobStore, BlobReferenceRetriever marker, File marked) throws IOException {
    final BufferedWriter writer = Files.newWriter(marked, Charsets.UTF_8);
    final AtomicInteger count = new AtomicInteger();
    boolean threw = true;
    try {
        final Joiner delimJoiner = Joiner.on(DELIM).skipNulls();
        final GarbageCollectableBlobStore finalBlobStore = blobStore;
        System.out.println("Starting dump of blob references");
        Stopwatch watch = createStarted();
        marker.collectReferences(new ReferenceCollector() {

            @Override
            public void addReference(String blobId, String nodeId) {
                try {
                    Iterator<String> idIter = finalBlobStore.resolveChunks(blobId);
                    while (idIter.hasNext()) {
                        String id = delimJoiner.join(idIter.next(), nodeId);
                        count.getAndIncrement();
                        writeAsLine(writer, id, true);
                    }
                } catch (Exception e) {
                    throw new RuntimeException("Error in retrieving references", e);
                }
            }
        });
        writer.flush();
        sort(marked, new Comparator<String>() {

            @Override
            public int compare(String s1, String s2) {
                return s1.split(DELIM)[0].compareTo(s2.split(DELIM)[0]);
            }
        });
        System.out.println(count.get() + " blob references found");
        System.out.println("Finished in " + watch.elapsed(TimeUnit.SECONDS) + " seconds");
        threw = false;
    } finally {
        close(writer, threw);
    }
}
Also used : Joiner(com.google.common.base.Joiner) Stopwatch(com.google.common.base.Stopwatch) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GarbageCollectableBlobStore(org.apache.jackrabbit.oak.spi.blob.GarbageCollectableBlobStore) Iterator(java.util.Iterator) FileLineDifferenceIterator(org.apache.jackrabbit.oak.commons.FileIOUtils.FileLineDifferenceIterator) ReferenceCollector(org.apache.jackrabbit.oak.plugins.blob.ReferenceCollector)

Aggregations

Joiner (com.google.common.base.Joiner)47 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)6 IOException (java.io.IOException)5 Map (java.util.Map)4 BufferedWriter (java.io.BufferedWriter)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 ResultSet (com.google.cloud.spanner.ResultSet)2 Statement (com.google.cloud.spanner.Statement)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 DBException (com.yahoo.ycsb.DBException)2 File (java.io.File)2 URI (java.net.URI)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)2 FileLineDifferenceIterator (org.apache.jackrabbit.oak.commons.FileIOUtils.FileLineDifferenceIterator)2 CConfiguration (co.cask.cdap.common.conf.CConfiguration)1