Class FileServlet

  • All Implemented Interfaces:
    Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig
    Direct Known Subclasses:
    ImageTransformServlet

    public class FileServlet
    extends javax.servlet.http.HttpServlet
    A file servlet supporting resume of downloads and client-side caching and GZIP of text content. This servlet can also be used for images, client-side caching would become more efficient. This servlet can also be used for text files, GZIP would decrease network bandwidth.
    Author:
    BalusC
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected class  FileServlet.Range
      This class represents a byte range.
    • Constructor Summary

      Constructors 
      Constructor Description
      FileServlet()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void doGet​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Process GET request.
      protected void doHead​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
      Process HEAD request.
      static boolean matches​(String matchHeader, String toMatch)
      Returns true if the given match header matches the given value.
      protected void processRequest​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, boolean content)  
      protected void processRequest​(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, File file, boolean content)
      Process the actual request.
      • Methods inherited from class javax.servlet.http.HttpServlet

        doDelete, doOptions, doPost, doPut, doTrace, getLastModified, service, service
      • Methods inherited from class javax.servlet.GenericServlet

        destroy, getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, init, log, log
    • Constructor Detail

      • FileServlet

        public FileServlet()
    • Method Detail

      • doHead

        protected void doHead​(javax.servlet.http.HttpServletRequest request,
                              javax.servlet.http.HttpServletResponse response)
                       throws javax.servlet.ServletException,
                              IOException
        Process HEAD request. This returns the same headers as GET request, but without content.
        Overrides:
        doHead in class javax.servlet.http.HttpServlet
        Throws:
        javax.servlet.ServletException
        IOException
      • doGet

        protected void doGet​(javax.servlet.http.HttpServletRequest request,
                             javax.servlet.http.HttpServletResponse response)
                      throws javax.servlet.ServletException,
                             IOException
        Process GET request.
        Overrides:
        doGet in class javax.servlet.http.HttpServlet
        Throws:
        javax.servlet.ServletException
        IOException
      • processRequest

        protected void processRequest​(javax.servlet.http.HttpServletRequest request,
                                      javax.servlet.http.HttpServletResponse response,
                                      boolean content)
                               throws IOException
        Throws:
        IOException
      • processRequest

        protected void processRequest​(javax.servlet.http.HttpServletRequest request,
                                      javax.servlet.http.HttpServletResponse response,
                                      File file,
                                      boolean content)
                               throws IOException
        Process the actual request.
        Parameters:
        request - The request to be processed.
        response - The response to be created.
        content - Whether the request body should be written (GET) or not (HEAD).
        Throws:
        IOException - If something fails at I/O level.
      • matches

        public static boolean matches​(String matchHeader,
                                      String toMatch)
        Returns true if the given match header matches the given value.
        Parameters:
        matchHeader - The match header.
        toMatch - The value to be matched.
        Returns:
        True if the given match header matches the given value.