use of org.apache.storm.hdfs.spout.ParseException in project streamline by hortonworks.
the class JsonFileReader method next.
// returns null when EOF is reached
public List<Object> next() throws IOException, ParseException {
List<Object> lineTuple = super.next();
if (lineTuple == null)
return null;
String jsonLine = (String) lineTuple.get(0);
if (jsonLine.trim().isEmpty())
return next();
try {
// 1- convert Json to Map<>
HashMap<String, Object> jsonMap = new ObjectMapper().readValue(jsonLine, HashMap.class);
// 2- make StreamlineEvent from map
StreamlineEventImpl slEvent = StreamlineEventImpl.builder().putAll(jsonMap).dataSourceId("HdfsSpout").build();
// 3- create tuple from StreamlineEvent
return Collections.singletonList(slEvent);
} catch (JsonProcessingException e) {
throw new ParseException("Json parsing error at location : " + getFileOffset().toString(), e);
}
}
Aggregations