Author: [email protected]
Date: Tue Oct 25 15:00:13 2011
New Revision: 1586

Log:
AMDATU-458 fixing codestyle first

Modified:
   
trunk/amdatu-web/resource/src/main/java/org/amdatu/web/resource/service/ResourceServlet.java

Modified: 
trunk/amdatu-web/resource/src/main/java/org/amdatu/web/resource/service/ResourceServlet.java
==============================================================================
--- 
trunk/amdatu-web/resource/src/main/java/org/amdatu/web/resource/service/ResourceServlet.java
        (original)
+++ 
trunk/amdatu-web/resource/src/main/java/org/amdatu/web/resource/service/ResourceServlet.java
        Tue Oct 25 15:00:13 2011
@@ -27,10 +27,10 @@
 import javax.servlet.http.HttpServletResponse;
 
 public final class ResourceServlet extends HttpServlet {
-       private static final long serialVersionUID = 1L;
-       private static final int INTERNAL_BUFFER_SIZE = 4096;
+    private static final long serialVersionUID = 1L;
+    private static final int INTERNAL_BUFFER_SIZE = 4096;
 
-       @Override
+    @Override
     protected void doGet(HttpServletRequest request, HttpServletResponse 
response) throws ServletException, IOException {
         String path = getResourcePath(request);
         URL url = getServletContext().getResource(path);
@@ -39,82 +39,82 @@
         }
         else {
             String contentType = getServletContext().getMimeType(path);
-                       if (contentType != null) {
-                           response.setContentType(contentType);
-                       }
-                       URLConnection conn = null;
-                       OutputStream os = null;
-                       InputStream is = null;
-                       try {
-                               conn = url.openConnection();
-                               long lastModified = conn.getLastModified();
-                               if (lastModified != 0) {
-                                   response.setDateHeader("Last-Modified", 
lastModified);
-                               }
-                               // send the whole response, unless there was an 
"if modified since" header and the
-                               // resource is indeed not modified since that 
date
-                               long ifModifiedSince = 
request.getDateHeader("If-Modified-Since");
-                               if ((lastModified == 0 || ifModifiedSince == -1 
|| lastModified > ifModifiedSince)) {
-                                       try {
-                                               is = conn.getInputStream();
-                                           os = response.getOutputStream();
-                                           copy(is, os);
-                                       }
-                                       finally {
-                                           if (is != null) {
-                                               is.close();
-                                           }
-                                           if (os != null) {
-                                               os.close();
-                                           }
-                                       }
-                               }
-                               else {
-                                   
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
-                               }
-                       }
-                       finally {
-                               if (conn != null && is == null) {
-                                       // AMDATU-432 if the connection is open 
(conn != null), but nothing 
-                                       // has been read (is == null), and the 
URL points to a local file,
-                                       // it stays open, so explicitly close 
it.
-                                       conn.getInputStream().close();
-                               }
-                       }
+            if (contentType != null) {
+                response.setContentType(contentType);
+            }
+            URLConnection conn = null;
+            OutputStream os = null;
+            InputStream is = null;
+            try {
+                conn = url.openConnection();
+                long lastModified = conn.getLastModified();
+                if (lastModified != 0) {
+                    response.setDateHeader("Last-Modified", lastModified);
+                }
+                // send the whole response, unless there was an "if modified 
since" header and the
+                // resource is indeed not modified since that date
+                long ifModifiedSince = 
request.getDateHeader("If-Modified-Since");
+                if ((lastModified == 0 || ifModifiedSince == -1 || 
lastModified > ifModifiedSince)) {
+                    try {
+                        is = conn.getInputStream();
+                        os = response.getOutputStream();
+                        copy(is, os);
+                    }
+                    finally {
+                        if (is != null) {
+                            is.close();
+                        }
+                        if (os != null) {
+                            os.close();
+                        }
+                    }
+                }
+                else {
+                    response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+                }
+            }
+            finally {
+                if (conn != null && is == null) {
+                    // AMDATU-432 if the connection is open (conn != null), 
but nothing
+                    // has been read (is == null), and the URL points to a 
local file,
+                    // it stays open, so explicitly close it.
+                    conn.getInputStream().close();
+                }
+            }
         }
     }
 
-       /**
-        * Returns the path to the resource based on the request. This is the
-        * path part of the request URI minus the servlet context path.
-        */
-       private String getResourcePath(HttpServletRequest request) {
-               String path = request.getRequestURI();
+    /**
+     * Returns the path to the resource based on the request. This is the
+     * path part of the request URI minus the servlet context path.
+     */
+    private String getResourcePath(HttpServletRequest request) {
+        String path = request.getRequestURI();
         String contextPath = request.getContextPath();
         if (path == null) {
-               path = "";
+            path = "";
         }
         if (!path.startsWith("/")) {
-               path += "/" + path;
+            path += "/" + path;
         }
         int contextPathLength = contextPath.length();
-               if (contextPathLength > 0) {
+        if (contextPathLength > 0) {
             path = path.substring(contextPathLength);
         }
-               return path;
-       }
+        return path;
+    }
 
-       /**
-        * Copy data from InputStream to OutputStream.
-        */
-       private void copy(InputStream is, OutputStream os) throws IOException {
-               int len = 0;
-               byte[] buf = new byte[INTERNAL_BUFFER_SIZE];
-               int n;
+    /**
+     * Copy data from InputStream to OutputStream.
+     */
+    private void copy(InputStream is, OutputStream os) throws IOException {
+        int len = 0;
+        byte[] buf = new byte[INTERNAL_BUFFER_SIZE];
+        int n;
 
-               while ((n = is.read(buf, 0, buf.length)) >= 0) {
-                   os.write(buf, 0, n);
-                   len += n;
-               }
-       }
+        while ((n = is.read(buf, 0, buf.length)) >= 0) {
+            os.write(buf, 0, n);
+            len += n;
+        }
+    }
 }
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits

Reply via email to