Browse Source

dropwizard/plaintext now returns precomputed byte array

zloster 10 years ago
parent
commit
a405a2fd0d

+ 14 - 4
frameworks/Java/dropwizard/src/main/java/com/example/helloworld/resources/TextResource.java

@@ -8,9 +8,19 @@ import javax.ws.rs.core.MediaType;
 @Path("/plaintext")
 @Produces(MediaType.TEXT_PLAIN)
 public class TextResource {
+	private static final String MESSAGE = "Hello, World!";
+	private static final byte[] buffer;
 
-    @GET
-    public String sayHello() {
-        return "Hello, World!";
-    }
+	static {
+		try {
+			buffer = MESSAGE.getBytes("US-ASCII");
+		} catch (Exception e) {
+			throw new RuntimeException(e);
+		}
+	}
+
+	@GET
+	public byte[] sayHello() {
+		return buffer;
+	}
 }