Skip to content
This repository has been archived by the owner on Jul 31, 2022. It is now read-only.

Commit

Permalink
Memory leak fix (#18)
Browse files Browse the repository at this point in the history
* Fixed memory leak #15 #16

* Update pom.xml

Co-authored-by: Katsute <Katsute@users.noreply.github.com>
  • Loading branch information
Katsute and Katsute authored Apr 8, 2020
1 parent 12e589d commit 8cd7e2d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.kttdevelopment</groupId>
<artifactId>simplehttpserver</artifactId>
<version>DEVELOPMENT</version>
<version>03.00.01</version>
<packaging>jar</packaging>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,10 @@ static SimpleHttpExchange createSimpleHttpExchange(final HttpExchange exchange){

//
String OUT;
final InputStream IN = httpExchange.getRequestBody();

try(final Scanner scanner = new Scanner(IN,StandardCharsets.UTF_8)){
try(InputStream IN = httpExchange.getRequestBody(); final Scanner scanner = new Scanner(IN, StandardCharsets.UTF_8)){
OUT = scanner.useDelimiter("\\A").next();
IN.close();
}catch(IOException | NoSuchElementException e){
}catch(final IOException | NoSuchElementException ignored){
OUT = null;
}

Expand Down Expand Up @@ -361,14 +359,17 @@ public void send(final byte[] response, final int responseCode, final boolean gz
exchange.getResponseHeaders().set("Content-Encoding","gzip");
exchange.getResponseHeaders().set("Connection","keep-alive");
sendResponseHeaders(responseCode, 0);
GZIPOutputStream OUT = new GZIPOutputStream(exchange.getResponseBody());
OUT.write(response);
OUT.finish();
try(GZIPOutputStream OUT = new GZIPOutputStream(exchange.getResponseBody())){
OUT.write(response);
OUT.finish();
OUT.flush();
}
}else{
sendResponseHeaders(responseCode,response.length);
final OutputStream OUT = exchange.getResponseBody();
OUT.write(response);
OUT.flush();
try(final OutputStream OUT = exchange.getResponseBody()){
OUT.write(response);
OUT.flush();
}
}
}

Expand Down

0 comments on commit 8cd7e2d

Please sign in to comment.