Skip to content

Commit

Permalink
fix: remove the inputstream.ready() check on the XmlReader
Browse files Browse the repository at this point in the history
This check fails in GCS even for all input streams.
  • Loading branch information
loicmathieu committed Dec 19, 2023
1 parent 4d457bd commit c898a09
Showing 1 changed file with 22 additions and 24 deletions.
46 changes: 22 additions & 24 deletions src/main/java/io/kestra/plugin/serdes/xml/XmlReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,31 +74,29 @@ public Output run(RunContext runContext) throws Exception {
BufferedReader input = new BufferedReader(new InputStreamReader(runContext.uriToInputStream(from), charset));
OutputStream output = new FileOutputStream(tempFile);
) {
if(input.ready()) {
XMLParserConfiguration xmlParserConfiguration = new XMLParserConfiguration();
if (parserConfiguration != null) {
xmlParserConfiguration = xmlParserConfiguration.withForceList(parserConfiguration.getForceList());
}
JSONObject jsonObject = XML.toJSONObject(input, xmlParserConfiguration);

Object result = result(jsonObject);

if (result instanceof JSONObject) {
Map<String, Object> map = ((JSONObject) result).toMap();
FileSerde.write(output, map);
runContext.metric(Counter.of("records", map.size()));
} else if (result instanceof JSONArray) {
List<Object> list = ((JSONArray) result).toList();
list.forEach(throwConsumer(o -> {
FileSerde.write(output, o);
}));
runContext.metric(Counter.of("records", list.size()));
} else {
FileSerde.write(output, result);
}

output.flush();
XMLParserConfiguration xmlParserConfiguration = new XMLParserConfiguration();
if (parserConfiguration != null) {
xmlParserConfiguration = xmlParserConfiguration.withForceList(parserConfiguration.getForceList());
}
JSONObject jsonObject = XML.toJSONObject(input, xmlParserConfiguration);

Object result = result(jsonObject);

if (result instanceof JSONObject) {
Map<String, Object> map = ((JSONObject) result).toMap();
FileSerde.write(output, map);
runContext.metric(Counter.of("records", map.size()));
} else if (result instanceof JSONArray) {
List<Object> list = ((JSONArray) result).toList();
list.forEach(throwConsumer(o -> {
FileSerde.write(output, o);
}));
runContext.metric(Counter.of("records", list.size()));
} else {
FileSerde.write(output, result);
}

output.flush();
}

return Output
Expand Down

0 comments on commit c898a09

Please sign in to comment.