Package org.htmlunit.attachment
Class DownloadingAttachmentHandler
java.lang.Object
org.htmlunit.attachment.DownloadingAttachmentHandler
- All Implemented Interfaces:
Serializable
,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:
-
Constructor Summary
ConstructorsConstructorDescriptionCreates 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 TypeMethodDescriptionvoid
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
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
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
Handles the specified attached page. This is some kind of information that the page was handled as attachment. This method will only be called ifAttachmentHandler.handleAttachment(WebResponse, String)
has returned false for the response.- Specified by:
handleAttachment
in interfaceAttachmentHandler
- Parameters:
page
- an attached page, which doesn't get loaded inlineattachmentFilename
- the filename to use for the attachment ornull
if unspecified
-