Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Print out the results using an appropriate ResultsReader for the passed
* output mode.
*
* Using incremental streaming , data is parsed and returned in key-value
* pairs
*
* The JSON and CSV results readers requires an external jar (gson-2.1.jar,
* opencsv-2.3.jar) for json and csv parsing and is not part of the base
* Splunk Java SDK. These readers are found in the "com.splunk.external"
* module. If you include the splunk-external.jar and the both gson-2.1.jar
* and opencsv-2.3.jar, you can use any -- just like this sample.
*
* @param stream
* @param outputMode
* xml,json,csv
*/
private static void processInputStream(InputStream stream,
OutputMode outputMode) {
try {
HashMap<String, String> map;
try {
ResultsReader resultsReader = null;
if (outputMode.equals(OutputMode.XML))
resultsReader = new ResultsReaderXml(stream);
else if (outputMode.equals(OutputMode.JSON)) {
resultsReader = new ResultsReaderJson(stream);
} else {
resultsReader = new ResultsReaderCsv(stream);
}
while ((map = resultsReader.getNextEvent()) != null) {
System.out.println("EVENT:********");
for (String key : map.keySet())
System.out.println(" " + key + " --> " + map.get(key));
}
resultsReader.close();
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.