Class HttpFileServer

  • All Implemented Interfaces:
    java.lang.Runnable, EventSubscriber, Fiber.Worker

    public class HttpFileServer
    extends HttpSession
    A simple file server over http Usage: Run java kilim.examples.HttpFileServer [base directory name] From a browser, go to "http://localhost:7262". A HttpFileServer object is a SessionTask, and is thus a thin wrapper over the socket connection. Its execute() method is called once on connection establishment. The HttpRequest and HttpResponse objects are wrappers over a bytebuffer, and unrelated to the socket. The request object is "filled in" by HttpSession.readRequest() and the response object is sent by HttpSession.sendResponse(). The rest of the code is related to the mechanics of file serving, common to Kilim and non-Kilim approaches alike. The objective of this example is merely to demonstrate Kilim API, not to have a fully functioning file server.
    • Field Detail

      • baseDirectory

        public static java.io.File baseDirectory
      • baseDirectoryName

        public static java.lang.String baseDirectoryName
      • mimeTypes

        public static java.util.HashMap<java.lang.String,​java.lang.String> mimeTypes
    • Constructor Detail

      • HttpFileServer

        public HttpFileServer()
    • Method Detail

      • main

        public static void main​(java.lang.String[] args)
                         throws java.io.IOException
        Throws:
        java.io.IOException
      • usage

        public static void usage()
      • urlToPath

        private java.io.File urlToPath​(HttpRequest req)
      • check

        public boolean check​(HttpResponse resp,
                             java.io.File file)
                      throws java.io.IOException,
                             Pausable
        Throws:
        java.io.IOException
        Pausable
      • sendFile

        public void sendFile​(HttpResponse resp,
                             java.io.File file,
                             boolean headOnly)
                      throws java.io.IOException,
                             Pausable
        Throws:
        java.io.IOException
        Pausable
      • sendDirectory

        public void sendDirectory​(HttpResponse resp,
                                  java.io.File file,
                                  boolean headOnly)
                           throws Pausable,
                                  java.io.IOException
        Throws:
        Pausable
        java.io.IOException
      • problem

        public void problem​(java.io.File file,
                            HttpResponse resp,
                            byte[] statusCode,
                            java.lang.String msg)
                     throws java.io.IOException,
                            Pausable
        Throws:
        java.io.IOException
        Pausable
      • getRelPath

        private java.lang.String getRelPath​(java.io.File file)
                                     throws java.io.IOException
        Throws:
        java.io.IOException
      • mimeType

        public static java.lang.String mimeType​(java.io.File file)