Skip to content

Commit 84fe38d

Browse files
committed
Azure function improvement
1 parent 34034d4 commit 84fe38d

File tree

1 file changed

+10
-3
lines changed
  • extensions/azure-functions-http/runtime/src/main/java/io/quarkus/azure/functions/resteasy/runtime

1 file changed

+10
-3
lines changed

extensions/azure-functions-http/runtime/src/main/java/io/quarkus/azure/functions/resteasy/runtime/BaseFunction.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.quarkus.azure.functions.resteasy.runtime;
22

33
import java.io.ByteArrayOutputStream;
4+
import java.io.IOException;
45
import java.io.PrintWriter;
56
import java.io.StringWriter;
67
import java.nio.channels.Channels;
@@ -32,11 +33,13 @@
3233
import io.quarkus.vertx.http.runtime.VertxHttpRecorder;
3334

3435
public 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

Comments
 (0)