1515import java .nio .file .Path ;
1616import java .nio .file .StandardOpenOption ;
1717import java .util .List ;
18+ import java .util .logging .Level ;
19+ import java .util .logging .Logger ;
1820
1921/**
2022 * @author Simon Reinisch
@@ -25,6 +27,7 @@ public class Response {
2527 private final HttpExchange HTTP_EXCHANGE ;
2628 private final OutputStream BODY ;
2729 private final Headers HEADER ;
30+ private final Logger LOGGER ;
2831
2932 private String contentType ;
3033 private boolean isClose ;
@@ -37,6 +40,7 @@ public class Response {
3740 isClose = false ;
3841 contentLength = 0 ;
3942 status = 200 ;
43+ LOGGER = Logger .getLogger (getClass ().getSimpleName ());
4044 }
4145
4246 public Response (HttpExchange exchange ) {
@@ -174,8 +178,7 @@ public void send(String s) {
174178 try {
175179 this .BODY .write (s .getBytes ());
176180 } catch (IOException e ) {
177- // TODO: Handle error
178- e .printStackTrace ();
181+ LOGGER .log (Level .INFO , "Failed to write charsequence to client." , e );
179182 }
180183
181184 close ();
@@ -212,8 +215,7 @@ public void send(@NotNull Path file) {
212215 fis .close ();
213216
214217 } catch (IOException e ) {
215- // TODO: Handle error
216- e .printStackTrace ();
218+ LOGGER .log (Level .INFO , "Failed to pipe file to outputstream." , e );
217219 }
218220
219221 close ();
@@ -236,8 +238,7 @@ private void sendHeaders() {
236238 this .HEADER .set ("Content-Type" , contentType );
237239 this .HTTP_EXCHANGE .sendResponseHeaders (status , contentLength );
238240 } catch (IOException e ) {
239- // TODO: Handle error
240- e .printStackTrace ();
241+ LOGGER .log (Level .INFO , "Failed to send headers." , e );
241242 }
242243 }
243244
@@ -246,8 +247,7 @@ private void close() {
246247 this .BODY .close ();
247248 this .isClose = true ;
248249 } catch (IOException e ) {
249- // TODO: Handle error
250- e .printStackTrace ();
250+ LOGGER .log (Level .INFO , "Failed to close outputstream." , e );
251251 }
252252 }
253253
0 commit comments