11package io .quarkus .azure .functions .resteasy .runtime ;
22
33import java .io .ByteArrayOutputStream ;
4+ import java .io .IOException ;
45import java .io .PrintWriter ;
56import java .io .StringWriter ;
67import java .nio .channels .Channels ;
3233import io .quarkus .vertx .http .runtime .VertxHttpRecorder ;
3334
3435public class BaseFunction {
35- private static final Logger log = Logger .getLogger ("io.quarkus.azure" );
36+ private static final Logger LOG = Logger .getLogger ("io.quarkus.azure" );
3637
3738 protected static final String deploymentStatus ;
3839 protected static boolean started = false ;
3940
41+ private static final int BUFFER_SIZE = 8096 ;
42+
4043 static {
4144 StringWriter error = new StringWriter ();
4245 PrintWriter errorWriter = new PrintWriter (error , true );
@@ -106,7 +109,7 @@ protected HttpResponseMessage nettyDispatch(HttpRequestMessage<Optional<byte[]>>
106109
107110 private ByteArrayOutputStream createByteStream () {
108111 ByteArrayOutputStream baos ;
109- baos = new ByteArrayOutputStream (500 );
112+ baos = new ByteArrayOutputStream (BUFFER_SIZE );
110113 return baos ;
111114 }
112115
@@ -136,7 +139,6 @@ public void handleMessage(Object msg) {
136139 if (msg instanceof HttpContent ) {
137140 HttpContent content = (HttpContent ) msg ;
138141 if (baos == null ) {
139- // todo what is right size?
140142 baos = createByteStream ();
141143 }
142144 int readable = content .content ().readableBytes ();
@@ -156,6 +158,11 @@ public void handleMessage(Object msg) {
156158 }
157159 if (msg instanceof LastHttpContent ) {
158160 responseBuilder .body (baos .toByteArray ());
161+ try {
162+ baos .close ();
163+ } catch (IOException e ) {
164+ LOG .warn ("Unable to close the ByteArrayOutputStream" , e );
165+ }
159166 future .complete (responseBuilder .build ());
160167 }
161168 } catch (Throwable ex ) {
0 commit comments