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();
}
}
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()));
}
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);
}
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(']');
}
}
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);
}
}
Aggregations