Package de.aristaflow.adept2.ui.htmlgui
Class HTMLContext.Attachment
- java.lang.Object
-
- de.aristaflow.adept2.ui.htmlgui.HTMLContext.Attachment
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
- Enclosing interface:
- HTMLContext
public static class HTMLContext.Attachment extends Object implements Closeable
AnAttachment
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 theHTMLContext
.Attachment
s 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.The data of this attachment may be read several times if required. However, it will only be able to be used once if the first request is
non-rereadable
.
-
-
Field Summary
Fields Modifier and Type Field Description protected String
contentType
Field forgetContentType()
.protected InputStream
data
Field forgetData()
.protected String
fileName
Field forgetFileName()
.protected Map<String,String>
headerData
Field forgetHeaderData()
.protected long
size
Field forgetSize()
.
-
Constructor Summary
Constructors Constructor Description Attachment(String contentType, InputStream data, long size, String fileName, Map<String,String> headerData)
Creates a newAttachment
with the designated attributes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
String
getContentType()
Gets the content type of the data, that is the value of the RFC 822 "Content-Type" header field of the body part.InputStream
getData()
Gets the actual data as input stream; this is the content of the corresponding body part of the multipart.InputStream
getDataRereadable()
Gets the actual data as input stream.String
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).Map<String,String>
getHeaderData()
Gets all header data which is sent with the body part of the multipart this attachment stems from.long
getSize()
Gets the size of the attachment as number of bytes.
-
-
-
Field Detail
-
contentType
protected final String contentType
Field forgetContentType()
.
-
size
protected final long size
Field forgetSize()
.
-
data
protected final InputStream data
Field forgetData()
.
-
fileName
protected final String fileName
Field forgetFileName()
.
-
headerData
protected final Map<String,String> headerData
Field forgetHeaderData()
.
-
-
Constructor Detail
-
Attachment
public Attachment(String contentType, InputStream data, long size, String fileName, Map<String,String> headerData) throws IOException
Creates a newAttachment
with 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
BufferedRereadableContent
will be created to determine the size. This allows to reread the designateddata
. Also if the first data retrieval is for rereading, aBufferedRereadableContent
will 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 be null.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 aBufferedRereadableContent
is required to determine the size, creating it may throw anIOException
.
-
-
Method Detail
-
getContentType
public String 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
public InputStream getData()
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.
-
getDataRereadable
public InputStream getDataRereadable() throws IOException
Gets the actual data as input stream. This method can be called several times returning the same input for every call.
Users shouldInputStream.close()
the returned stream.- Returns:
- The actual data of this attachment as provided as content of the body part.
- Throws:
IOException
- If there are problems creating theBufferedRereadableContent
allowing for regetting theInputStream
or the data has already been retrieved non-rereadably, anIOException
will be thrown.
-
getFileName
public String 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
public Map<String,String> 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:
Header
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
-