Package de.aristaflow.adept2.ui.htmlgui
Class HTMLContext.Attachment
java.lang.Object
de.aristaflow.adept2.ui.htmlgui.HTMLContext.Attachment
- All Implemented Interfaces:
Closeable,AutoCloseable
- Direct Known Subclasses:
HTMLContext.CloseIgnoringAttachment
- Enclosing interface:
- HTMLContext
An
Since attachments need not necessarily be files, the filename may be null. However all other information is guaranteed to be non-null. Note that the header data is not parsed but just provided as-is from the body part.
Attachment represents either binary data or a (text) file uploaded to the
HTTP-service. This data or the uploaded files may be provided as mulitpart-POST-data generated
by appropriate HTML set via the HTMLContext. Attachments provide a
high-level interface for a body part of the multipart by providing the size, the content-type,
the data, the filename, as well as all additional header data of the body part. Since attachments need not necessarily be files, the filename may be null. However all other information is guaranteed to be non-null. Note that the header data is not parsed but just provided as-is from the body part.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Cleanup<IOException>The clean-up for closing the data as post-mortem action of thisAttachment.protected final StringField forgetContentType().protected final RereadableContentField forgetInputStream().protected final StringField forgetFileName().Field forgetHeaderData().protected final longField forgetSize(). -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a newAttachmentwrapping the designated on.Attachment(String contentType, InputStream data, long size, String fileName, Map<String, String> headerData) Creates a newAttachmentwith the designated attributes. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Gets the content type of the data, that is the value of the RFC 822 "Content-Type" header field of the body part.getData()Deprecated, for removal: This API element is subject to removal in a future version.Deprecated, for removal: This API element is subject to removal in a future version.UsegetInputStream()instead.Gets the name of the file (without path information), in case the attachment was a file upload, null otherwise (for non-file binary data).Gets all header data which is sent with the body part of the multipart this attachment stems from.Gets the actual data as input stream.longgetSize()Gets the size of the attachment as number of bytes.
-
Field Details
-
contentType
Field forgetContentType(). -
size
protected final long sizeField forgetSize(). -
data
Field forgetInputStream(). -
fileName
Field forgetFileName(). -
headerData
Field forgetHeaderData(). -
cleanup
The clean-up for closing the data as post-mortem action of thisAttachment.
-
-
Constructor Details
-
Attachment
public Attachment(String contentType, InputStream data, long size, String fileName, Map<String, String> headerData) throws IOExceptionCreates a newAttachmentwith the designated attributes. The header data is stored as unmodifiable map. Do not modify it after calling this constructor to prevent unwanted side-effects since it is not copied.If the designated size is is invalid (negative) a
RereadableContentwill be created to determine the size. This allows to reread the designateddata. Also if the first data retrieval is for rereading, aRereadableContentwill be used.- Parameters:
contentType- The value of the RFC 822 "Content-Type" header field of the body part, which indicates how to interpret the data of this attachment. This must neither be null nor the empty string.data- The data of this attachment which is the content of the corresponding body part. This must not benull. The InputStream will be coupled to thisHTTPReply, so do not close it; clone it if required longer than thisAttachment.size- The size in bytes of the data/content of the body part.fileName- The name of the file in case the body part contains a file, null otherwise.headerData- The map containing the complete and unparsed headers of the corresponding body part. This must not be null.- Throws:
IOException- If there are problems reading from the designated stream or creating the correspondingRereadableContent, anIOExceptionwill be thrown.
-
Attachment
Creates a newAttachmentwrapping the designated on. This is only for wrapping subclasses. The subclasses need to override all methods except forgetContentType(),getSize()andgetFileName().- Parameters:
att- The wrappedAttachment.
-
-
Method Details
-
getContentType
Gets the content type of the data, that is the value of the RFC 822 "Content-Type" header field of the body part.- Returns:
- The content type of the data, e.g.
text/html.
-
getSize
public long getSize()Gets the size of the attachment as number of bytes.- Returns:
- The size of the attachment (number of bytes).
-
getData
Deprecated, for removal: This API element is subject to removal in a future version.UsegetInputStream()instead.Gets the actual data as input stream; this is the content of the corresponding body part of the multipart.- Returns:
- The actual data of this attachment as provided as content of the body part.
- Throws:
UncheckedIOException- If there are problems creating a newInputStreamfor the attachment data, anUncheckedIOExceptionwill be thrown.
-
getDataRereadable
@Deprecated(since="15.0.0", forRemoval=true) public InputStream getDataRereadable() throws IOExceptionDeprecated, for removal: This API element is subject to removal in a future version.UsegetInputStream()instead.Gets the actual data as input stream. This method can be called several times returning the same input for every call.
Users have toInputStream.close()the returned stream!- Returns:
- The actual data of this attachment as provided as content of the body part. The caller is responsible for closing.
- Throws:
IOException- If there are problems creating a newInputStreamfor the attachment data, anIOExceptionwill be thrown.
-
getInputStream
Gets the actual data as input stream. This method can be called several times returning the same input for every call.
Users have toInputStream.close()the returned stream!- Returns:
- The actual data of this attachment as provided as content of the body part. The caller is responsible for closing.
- Throws:
IOException- If there are problems creating a newInputStreamfor the attachment data, anIOExceptionwill be thrown.
-
getFileName
Gets the name of the file (without path information), in case the attachment was a file upload, null otherwise (for non-file binary data).- Returns:
- The file name in case of a file upload, null otherwise (for non-file binary data).
-
getHeaderData
Gets all header data which is sent with the body part of the multipart this attachment stems from. The values of the header data may be arbitrary strings even containing key-value-pairs again. However, they are just provided as from the body part.- Returns:
- All header data (mapping from header name to value) which is sent with the body part of the multipart this attachment stems from.
- See Also:
-
javax.mail.Header
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
getInputStream()instead.