Class FileDownloader

  • All Implemented Interfaces:
    net.lightbody.bmp.filters.ResponseFilter

    public class FileDownloader
    extends java.lang.Object
    implements net.lightbody.bmp.filters.ResponseFilter
    ResponseFilter that intercepts and downloads files. Inspired from https://github.com/selenide/selenide/issues/196#issuecomment-168674086
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String CONFIG_DEFAULT_DOWNLOAD_PATH
      Default download path for temporarily downloaded files
    • Constructor Summary

      Constructors 
      Constructor Description
      FileDownloader()  
    • Field Detail

      • CONFIG_DEFAULT_DOWNLOAD_PATH

        public static final java.lang.String CONFIG_DEFAULT_DOWNLOAD_PATH
        Default download path for temporarily downloaded files
        See Also:
        Constant Field Values
    • Constructor Detail

      • FileDownloader

        public FileDownloader()
    • Method Detail

      • addContentType

        public FileDownloader addContentType​(java.lang.String contentType)
        Adds a new Content-Type header value that should be intercepted.
        Parameters:
        contentType - The Content-Type header value that should be intercepted
        Returns:
        Self, for fluent method calls
      • deleteTempFiles

        public FileDownloader deleteTempFiles​(boolean deleteTempFiles)
        Sets if temporarily downloaded files should be deleted on process exit.
        Parameters:
        deleteTempFiles - true if temporary files should be deleted, false otherwise
        Returns:
        Self, for fluent method calls
      • setDownloadPath

        public FileDownloader setDownloadPath​(java.lang.String path)
        Sets the desired temporary files download path.
        Parameters:
        path - The desired download path
        Returns:
        Self, for fluent method calls
      • withContent

        public static FileDownloader withContent​(java.lang.String contentType)
        Creates a FileDownloader that intercepts specified Content-Type
        Parameters:
        contentType - The Content-Type to be intercepted
        Returns:
        Self, for fluent method calls
      • withContents

        public static FileDownloader withContents​(java.lang.String... contentType)
        Creates a FileDownloader that intercepts specified Content-Types.
        Parameters:
        contentType - The Content-Types to be intercepted
        Returns:
        Self, for fluent method calls
      • filterResponse

        public void filterResponse​(io.netty.handler.codec.http.HttpResponse response,
                                   net.lightbody.bmp.util.HttpMessageContents contents,
                                   net.lightbody.bmp.util.HttpMessageInfo messageInfo)
        Filtering method that intercepts and downloads the files.
        Specified by:
        filterResponse in interface net.lightbody.bmp.filters.ResponseFilter
        See Also:
        ResponseFilter.filterResponse(HttpResponse, HttpMessageContents, HttpMessageInfo)