close JsonParser where applicable to release internal jackson resources

This commit is contained in:
kimchy 2010-02-12 14:49:08 +02:00
parent ade36f026b
commit bc217d99ce
5 changed files with 38 additions and 6 deletions

View File

@ -5,6 +5,11 @@
<root url="jar://$GRADLE_REPOSITORY$/org.codehaus.jackson/jackson-mapper-asl/jars/jackson-mapper-asl-1.4.2.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
<SOURCES>
<root url="file://$PROJECT_DIR$/../../../opt/jackson/1.4.2/src/java" />
<root url="file://$PROJECT_DIR$/../../../opt/jackson/1.4.2/src/mapper/java" />
<root url="file://$PROJECT_DIR$/../../../opt/jackson/1.4.2/src/xc/java" />
<root url="file://$PROJECT_DIR$/../../../opt/jackson/1.4.2/src/jaxrs/java" />
</SOURCES>
</library>
</component>

View File

@ -252,8 +252,9 @@ public class JsonDocumentMapper implements DocumentMapper {
}
type = this.type;
JsonParser jp = null;
try {
JsonParser jp = jsonFactory.createJsonParser(new FastStringReader(source));
jp = jsonFactory.createJsonParser(new FastStringReader(source));
jsonContext.reset(jp, new Document(), type, source);
// will result in JsonToken.START_OBJECT
@ -301,6 +302,14 @@ public class JsonDocumentMapper implements DocumentMapper {
}
} catch (IOException e) {
throw new MapperParsingException("Failed to parse", e);
} finally {
if (jp != null) {
try {
jp.close();
} catch (IOException e) {
// ignore
}
}
}
return new ParsedDocument(jsonContext.uid(), jsonContext.id(), jsonContext.type(), jsonContext.doc(), source);
}

View File

@ -123,12 +123,22 @@ public class JsonIndexQueryParser extends AbstractIndexComponent implements Inde
}
@Override public Query parse(String source) throws QueryParsingException {
JsonParser jp = null;
try {
return parse(cache.get(), source, jsonFactory.createJsonParser(new FastStringReader(source)));
jp = jsonFactory.createJsonParser(new FastStringReader(source));
return parse(cache.get(), source, jp);
} catch (QueryParsingException e) {
throw e;
} catch (Exception e) {
throw new QueryParsingException(index, "Failed to parse [" + source + "]", e);
} finally {
if (jp != null) {
try {
jp.close();
} catch (IOException e) {
// ignore
}
}
}
}

View File

@ -360,7 +360,11 @@ public class JsonBuilder {
return result;
}
public void close() throws IOException {
generator.close();
public void close() {
try {
generator.close();
} catch (IOException e) {
// ignore
}
}
}

View File

@ -43,7 +43,11 @@ public class JsonSettingsLoader implements SettingsLoader {
@Override public Map<String, String> load(String source) throws IOException {
JsonParser jp = jsonFactory.createJsonParser(new FastStringReader(source));
return load(jp);
try {
return load(jp);
} finally {
jp.close();
}
}
public Map<String, String> load(JsonParser jp) throws IOException {