Browse files

Ensure parser is closed at the end.

  • Loading branch information...
1 parent 6fed3ee commit 09f2a0bf9442e6d2b19b02e0c326de0f1971427e @pgelinas pgelinas committed Dec 12, 2012
Showing with 11 additions and 3 deletions.
  1. +11 −3 org.ektorp/src/main/java/org/ektorp/impl/QueryResultParser.java
View
14 org.ektorp/src/main/java/org/ektorp/impl/QueryResultParser.java
@@ -52,9 +52,17 @@ public QueryResultParser(Class<T> type, ObjectMapper mapper) {
}
public void parseResult(InputStream json) throws IOException {
- JsonParser jp = mapper.getFactory().createJsonParser(json);
+ JsonParser jp = mapper.getFactory().createParser(json);
- if (jp.nextToken() != JsonToken.START_OBJECT) {
+ try {
+ parseResult(jp);
+ } finally {
+ jp.close();
+ }
+ }
+
+ private void parseResult(JsonParser jp) throws IOException {
+ if (jp.nextToken() != JsonToken.START_OBJECT) {
throw new DbAccessException("Expected data to start with an Object");
}
@@ -79,7 +87,7 @@ public void parseResult(InputStream json) throws IOException {
JsonNode error = mapper.convertValue(errorFields, JsonNode.class);
throw new DbAccessException(error.toString());
}
- }
+ }
private void parseRows(JsonParser jp) throws IOException{
if (jp.getCurrentToken() != JsonToken.START_ARRAY) {

0 comments on commit 09f2a0b

Please sign in to comment.