I have a project hosted on Google Apennine, standard runtime. I have defined a servlet which responds to a GET request with up-to 200kb data. Problem is that the servlet attempts to buffer a very large amount of the data before actually writing out.
I tried to put an upper limit on the buffering by doing,
resp.setBufferSize(1024);
But this makes no difference. An immediate log of the buffer size,
LOGGER.info("Using buffer of size " + resp.getBufferSize());
tells me that the buffer is of size 1024, but once the data is written, I again log the buffer size and it has grown to a very large amount depending upon the data written out.
Now, if I increase the output to sufficiently large amount I get an Exception, while writing out that data. The data itself is not stored anywhere, it is generated and written to the "ServletOutputStream" directly.
Error for /sizeTestServlet
java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2271)
at java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:118)
at java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:153)
at java.io.OutputStream.write(OutputStream.java:75)
at com.google.apphosting.runtime.jetty.RpcResponseGenerator.addContent(RpcResponseGenerator.java:65)
at org.mortbay.jetty.AbstractGenerator$Output.write(AbstractGenerator.java:644)
at org.mortbay.jetty.AbstractGenerator$Output.write(AbstractGenerator.java:589)
Is there some way to disable output buffering ?