Skip to content

Commit 1a4445d

Browse files
committed
[HOTFIX] close IO stream
1 parent b2231e5 commit 1a4445d

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

servicebuilder-core-addons/src/main/java/no/obos/util/servicebuilder/log/ServerLogFilter.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,16 @@ public ServerLogFilter(@Context ResourceInfo resourceInfo, ServerLogger serverLo
4949

5050
static String extractRequestEntity(ContainerRequestContext request) {
5151
if (request.hasEntity()) {
52-
InputStream inputStreamOriginal = request.getEntityStream();
53-
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStreamOriginal, MAX_ENTITY_READ);
54-
bufferedInputStream.mark(MAX_ENTITY_READ);
5552
byte[] bytes = new byte[MAX_ENTITY_READ];
56-
int read;
57-
try {
58-
read = bufferedInputStream.read(bytes, 0, MAX_ENTITY_READ);
53+
try (InputStream inputStreamOriginal = request.getEntityStream()) {
54+
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStreamOriginal, MAX_ENTITY_READ);
55+
bufferedInputStream.mark(MAX_ENTITY_READ);
56+
bufferedInputStream.read(bytes, 0, MAX_ENTITY_READ);
5957
bufferedInputStream.reset();
58+
request.setEntityStream(bufferedInputStream);
6059
} catch (IOException e) {
6160
throw new RuntimeException(e);
6261
}
63-
request.setEntityStream(bufferedInputStream);
6462

6563
return new String(bytes, Charsets.UTF_8);
6664
}

0 commit comments

Comments
 (0)