Skip to content

Commit

Permalink
Merge pull request #444 from PascalSchumacher/close_JsonGenerator
Browse files Browse the repository at this point in the history
Close JsonGenerators after usage.
  • Loading branch information
philsttr authored Nov 1, 2020
2 parents c6b3af9 + c886112 commit ab1ddcb
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,9 @@ public byte[] writeEventAsBytes(Event event) throws IOException {
}

public void writeEventToOutputStream(Event event, OutputStream outputStream) throws IOException {
JsonGenerator generator = createGenerator(outputStream);
writeEventToGenerator(generator, event);
try (JsonGenerator generator = createGenerator(outputStream)) {
writeEventToGenerator(generator, event);
}
/*
* Do not flush the outputStream.
*
Expand All @@ -179,10 +180,11 @@ public void writeEventToOutputStream(Event event, OutputStream outputStream) thr
public String writeEventAsString(Event event) throws IOException {
SegmentedStringWriter writer = new SegmentedStringWriter(getBufferRecycler());

JsonGenerator generator = createGenerator(writer);
writeEventToGenerator(generator, event);
writer.flush();
return writer.getAndClear();
try (JsonGenerator generator = createGenerator(writer)) {
writeEventToGenerator(generator, event);
writer.flush();
return writer.getAndClear();
}
}

protected void writeEventToGenerator(JsonGenerator generator, Event event) throws IOException {
Expand Down

0 comments on commit ab1ddcb

Please sign in to comment.