Browse Source

write in end() as slight optimisation

purplefox 12 years ago
parent
commit
2dc1b1ec8a
1 changed files with 3 additions and 7 deletions
  1. 3 7
      vertx/WebServer.java

+ 3 - 7
vertx/WebServer.java

@@ -47,18 +47,15 @@ public class WebServer extends Verticle implements Handler<HttpServerRequest> {
   private void handlePlainText(HttpServerRequest req) {
     req.response().putHeader("Content-Type", "application/json; charset=UTF-8");
     req.response().putHeader("Content-Length", helloWorldContentLength);
-    req.response().write(helloWorldBuffer);
-    req.response().end();
+    req.response().end(helloWorldBuffer);
   }
 
   private void handleJson(HttpServerRequest req) {
     String result = Json.encode(Collections.singletonMap("message", "Hello, world!"));
-
     int contentLength = result.getBytes(StandardCharsets.UTF_8).length;
     req.response().putHeader("Content-Type", "application/json; charset=UTF-8");
     req.response().putHeader("Content-Length", String.valueOf(contentLength));
-    req.response().write(result);
-    req.response().end();
+    req.response().end(result);
   }
 
   private void handleDbMongo(final HttpServerRequest req) {
@@ -105,8 +102,7 @@ public class WebServer extends Verticle implements Handler<HttpServerRequest> {
           final int contentLength = result.getBytes(StandardCharsets.UTF_8).length;
           this.req.response().putHeader("Content-Type", "application/json; charset=UTF-8");
           this.req.response().putHeader("Content-Length", String.valueOf(contentLength));
-          this.req.response().write(result);
-          this.req.response().end();
+          this.req.response().end(result);
         }
       } else {
         System.err.println("Failed to execute query");