Package org.htmlunit.attachment

# Class DownloadingAttachmentHandler

java.lang.Object
org.htmlunit.attachment.DownloadingAttachmentHandler

All Implemented Interfaces:
  `Serializable`, `AttachmentHandler`

public class DownloadingAttachmentHandler extends Object implements AttachmentHandler
Implementation of an `AttachmentHandler` that mimics how browsers handle attachments, specifically

- download file into a default folder when attachment response is detected
- infer filename from octet stream response and use that when saving file
- if a file already exists, append number to it. Keep incrementing numbers until you find a slot that is free (thats how Chrome handles duplicate filenames).

See Also:
  - Serialized Form

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `DownloadingAttachmentHandler()`
  Creates a new DownloadingAttachmentHandler that stores all downloaded files in the 'temp'-dir (System.getProperty("java.io.tmpdir")).
  `DownloadingAttachmentHandler(Path downloadFolder)`
  Creates a new DownloadingAttachmentHandler that stores all downloaded files in the provided directory.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `handleAttachment(Page page, String attachmentFilename)`
  Handles the specified attached page.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface org.htmlunit.attachment.AttachmentHandler

  `handleAttachment, isAttachment`

- ## Constructor Details

  - ### DownloadingAttachmentHandler

    public DownloadingAttachmentHandler(Path downloadFolder) throws IOException
    Creates a new DownloadingAttachmentHandler that stores all downloaded files in the provided directory. The directory must exist and be writable.
    Parameters:
      `downloadFolder` - the path to the folder for storing all downloaded files
    Throws:
      `IOException` - if the folder does not exist or the folder is not writable

  - ### DownloadingAttachmentHandler

    public DownloadingAttachmentHandler() throws IOException
    Creates a new DownloadingAttachmentHandler that stores all downloaded files in the 'temp'-dir (System.getProperty("java.io.tmpdir")).
    Throws:
      `IOException` - if the folder does not exist or the folder is not writable

- ## Method Details

  - ### handleAttachment

    public void handleAttachment(Page page, String attachmentFilename)
    Handles the specified attached page. This is some kind of information that the page was handled as attachment. This method will only be called if `AttachmentHandler.handleAttachment(WebResponse, String)` has returned false for the response.
    Specified by:
      `handleAttachment` in interface `AttachmentHandler`
    Parameters:
      `page` - an attached page, which doesn't get loaded inline
      `attachmentFilename` - the filename to use for the attachment or `null` if unspecified