Menu
pushmode

Class FileServer

PushMode » API Reference » pushmode



  • public class FileServer
    extends Object
    Minimalist static content HTTP server for use during development. This is by no means a production HTTP server. It is intended only to ease development in cases where static content is developed together with source code as is usually the case with CSS for example. Once the application is deployed, static content should be served from fully featured web server (nginx, Apache) or from CDN.
    Thread-safety:
    Operations on FileServer are synchronized. It is safe to call them from multiple threads. There can be multiple FileServer instances in the same process as far as they listen on different ports.
    Security:
    FileServer binds to localhost (127.0.0.1) by default. It therefore cannot be queried remotely.
    • Constructor Detail

      • FileServer

        public FileServer(InetAddress ipAddress,
                          int port,
                          Path path)
        Defines new FileServer. Listening port is not opened at this stage.
        Parameters:
        ipAddress - IP address where FileServer should listen.
        port - Port where FileServer should listen.
        path - Relative or absolute path where content is stored. If absolute path is specified, FileServer verifies the path is a directory and uses it as is. If relative path is specified, the path may be relative to current directory or any ancestor directory. If multiple ancestor directories contain this path, the most deep one is used. For example, if current directory is .../app/bin and content can be found under .../app/content, then path can be specified simply as content.
        See Also:
        start()
        Lifecycle:
        FileServer is initially created in inactive state. Use start() to start it.
      • FileServer

        public FileServer(int port,
                          Path path)
        Defines new FileServer. Listening port is not opened at this stage.
        Parameters:
        port - Port where FileServer should listen. FileServer will binds to localhost.
        path - Relative or absolute path where content is stored. If absolute path is specified, FileServer verifies the path is a directory and uses it as is. If relative path is specified, the path may be relative to current directory or any ancestor directory. If multiple ancestor directories contain this path, the most deep one is used. For example, if current directory is .../app/bin and content can be found under .../app/content, then path can be specified simply as content.
        See Also:
        start()
        Lifecycle:
        FileServer is initially created in inactive state. Use start() to start it.
    • Method Detail

      • start

        public FileServer start()
        Starts the FileServer. This method actually opens the listening port specified in constructor. When this method completes, FileServer is ready to serve requests.
        Returns:
        this
        See Also:
        FileServer(int, Path), stop()
        Thread-safety:
        This method is safe to call from any thread.
        Lifecycle:
        FileServer must be in inactive state. This method will transition it to running state. FileServer cannot be restarted once stopped.
      • stop

        public FileServer stop()
        Signals the server to stop. This method returns immediately without waiting for the server to actually stop. The server will stop asynchronously. If already stopped or stopping, calling this method has no effect.
        Returns:
        this
        See Also:
        start(), join()
        Thread-safety:
        This method is safe to call from any thread.
        Lifecycle:
        FileServer must be in running or stopped state. This method causes FileServer to transition asynchronously to stopped state.
      • join

        public FileServer join()
        Waits for the server to stop. If already stopped, this method returns immediately.
        Returns:
        this
        See Also:
        stop()
        Thread-safety:
        This method is safe to call from any thread and from multiple threads at the same time. It does not hold any locks.
        Lifecycle:
        FileServer must be in running or stopped state. FileServer will be in stopped state when this method returns.
      • port

        public int port()
        Port where the FileServer listens. This was specified in constructor.
        Returns:
        Listening port.
        See Also:
        FileServer(int, Path)
        Thread-safety:
        This method only reads immutable data.
      • path

        public Path path()
        Content path as specified in the constructor.
        Returns:
        Content path.
        See Also:
        absolute(), FileServer(int, Path)
        Thread-safety:
        This method only reads immutable data.
      • absolute

        public Path absolute()
        Absolute content path. It is resolved from relative path when FileServer is instantiated. If constructor was invoked with absolute path, this method returns the same absolute path.
        Returns:
        Absolute content path.
        See Also:
        path(), FileServer(int, Path)
        Thread-safety:
        This method only reads immutable data.