{"action":"opened","issue":{"url":"https://api.github.com/repos/perwendel/spark/issues/284","labels_url":"https://api.github.com/repos/perwendel/spark/issues/284/labels{/name}","comments_url":"https://api.github.com/repos/perwendel/spark/issues/284/comments","events_url":"https://api.github.com/repos/perwendel/spark/issues/284/events","html_url":"https://github.com/perwendel/spark/issues/284","id":82434650,"number":284,"title":"Uploading large files causes java.lang.OutOfMemoryError","user":{"login":"JacoBriers","id":1818218,"avatar_url":"https://avatars.githubusercontent.com/u/1818218?v=3","gravatar_id":"","url":"https://api.github.com/users/JacoBriers","html_url":"https://github.com/JacoBriers","followers_url":"https://api.github.com/users/JacoBriers/followers","following_url":"https://api.github.com/users/JacoBriers/following{/other_user}","gists_url":"https://api.github.com/users/JacoBriers/gists{/gist_id}","starred_url":"https://api.github.com/users/JacoBriers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JacoBriers/subscriptions","organizations_url":"https://api.github.com/users/JacoBriers/orgs","repos_url":"https://api.github.com/users/JacoBriers/repos","events_url":"https://api.github.com/users/JacoBriers/events{/privacy}","received_events_url":"https://api.github.com/users/JacoBriers/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-05-29T13:46:27Z","updated_at":"2015-05-29T13:46:27Z","closed_at":null,"body":"When uploading a large file and requesting the ServletInputStream from the raw HttpServletRequest:  \r\n\r\n```  \r\nHttpServletRequest req = request.raw();  \r\nstream = req.getInputStream();  \r\n```  \r\n\r\nI get the following error: \r\n```  \r\njava.lang.OutOfMemoryError: Java heap space  \r\nat java.util.Arrays.copyOf(Arrays.java:3236)   \r\nat java.io.ByteArrayOutputStream.grow(ByteArrayOutputStream.java:118)   \r\nat java.io.ByteArrayOutputStream.ensureCapacity(ByteArrayOutputStream.java:93)  \r\nat java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:153)  \r\nat spark.utils.IOUtils.toByteArray(IOUtils.java:134)  \r\nat spark.webserver.JettyHandler$HttpRequestWrapper.cacheInputStream(JettyHandler.java:84)  \r\nat spark.webserver.JettyHandler$HttpRequestWrapper.getInputStream(JettyHandler.java:78)  \r\n```  \r\n\r\nInternally it looks like spark caches the input stream and causes the memory usage to spike. A solution could be to provide access to the raw uncached input stream with some utility function?  \r\n\r\n```  \r\nHttpServletRequest req = request.raw();  \r\nstream = req.getUncachedInputStream();  \r\n```  \r\n\r\nI could raise the amount of heap space, but that would lead to high memory usage and not solve the underlying problem.  "}}