summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/server/VaadinServlet.java32
1 files changed, 25 insertions, 7 deletions
diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java
index 4fde870f74..35d5fd7cc1 100644
--- a/server/src/com/vaadin/server/VaadinServlet.java
+++ b/server/src/com/vaadin/server/VaadinServlet.java
@@ -896,14 +896,32 @@ public class VaadinServlet extends HttpServlet implements Constants {
protected void writeStaticResourceResponse(HttpServletRequest request,
HttpServletResponse response, URL resourceUrl) throws IOException {
// Write the resource to the client.
- final OutputStream os = response.getOutputStream();
- final byte buffer[] = new byte[DEFAULT_BUFFER_SIZE];
- int bytes;
- InputStream is = resourceUrl.openStream();
- while ((bytes = is.read(buffer)) >= 0) {
- os.write(buffer, 0, bytes);
+ URLConnection connection = resourceUrl.openConnection();
+ try {
+ int length = connection.getContentLength();
+ if (length >= 0) {
+ response.setContentLength(length);
+ }
+ } catch (Throwable e) {
+ // This can be ignored, content length header is not required.
+ // Need to close the input stream because of
+ // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4257700 to
+ // prevent it from hanging, but that is done below.
+ }
+
+ InputStream is = connection.getInputStream();
+ try {
+ final OutputStream os = response.getOutputStream();
+ final byte buffer[] = new byte[DEFAULT_BUFFER_SIZE];
+ int bytes;
+ while ((bytes = is.read(buffer)) >= 0) {
+ os.write(buffer, 0, bytes);
+ }
+ } finally {
+ if (is != null) {
+ is.close();
+ }
}
- is.close();
}
private URL findResourceURL(String filename, ServletContext sc)