JDK-6526165 : sun.net.www.http.ChunkedOutputStream buffers
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 5.0
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2007-02-16
  • Updated: 2013-09-12
  • Resolved: 2011-02-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other JDK 6 JDK 7
5.0u18 b01Fixed 6u2Fixed 7Fixed
Related Reports
Relates :  
Description
HttpURLConnection.getOutputStream() returns ChunkedOutputStream when setChunkedStreamingMode(4k) is called. But ChunkedOutputStream copies when write(byte[], off, len) is called. When ChunkedOutputStream.write(buf[20MB], off, len) is called, it keeps a copy of 20 MB. Thus, applications run of memory. There is no need to keep 20 MB in buf field since the chunk size 4k. This limits severly some of the JAX-WS applications and forces JAX-WS to do chunking before writing to ChunkedOutputStream. The fact that we are using chunking to avoid buffering doesn't help.

Comments
EVALUATION Yes, even though this looks like a strange use case (20MB byte[] call to write), we should support it. Will fix in jdk7 first.
05-03-2007

EVALUATION See the bug report, it does use setChunkedStreamingMode(4k) HttpURLConnection.setChunkedStreamingMode(4k) OutputStream os = HttpURLConnection.getOutputStream() os.write(buf[20MB], 0, 20MB) os.write(buf[40MB], 0, 40MB) In this case, sun.net.www.http.ChunkedOutputStream contains a private field buf with 40MB. There is no need to keep buffer of 40MB. It doesn't keep 60MB and there is no replay of the request in this streaming mode. os.write() method itself should push the data in 4k chunks
28-02-2007

EVALUATION This isn't a bug. The way the HttpURLConnection API is defined, we need to buffer the whole output stream so it can be replayed in some situations. However, in cases where a very large output is being sent, and the overhead of buffering is too great, then the application should use streaming mode. See the apidocs for HttpURLConnection.set{FixedLength,Chunked}StreamingMode()
28-02-2007