public class StreamDataBodyPart extends FormDataBodyPart
Represents an InputStream based file submission as a part of the
multipart/form-data.
It sets the InputStream as a body part with the default
MediaType.APPLICATION_OCTET_STREAM_TYPE (if not specified by the
user).
Note that the MIME type of the entity cannot be
automatically predicted as in case of FileDataBodyPart.
The filename of the attachment is set by the user or defaults to the part's name.
FileDataBodyPart| Constructor and Description |
|---|
StreamDataBodyPart()
Default constructor which forces user to manually set
the required (
name and streamEntity)
properties. |
StreamDataBodyPart(java.lang.String name,
java.io.InputStream streamEntity)
Convenience constructor which assumes the defaults for:
filename (part's name) and mediaType (
MediaType.APPLICATION_OCTET_STREAM_TYPE). |
StreamDataBodyPart(java.lang.String name,
java.io.InputStream streamEntity,
java.lang.String filename)
Convenience constructor which assumes the defaults for the
mediaType (MediaType.APPLICATION_OCTET_STREAM_TYPE). |
StreamDataBodyPart(java.lang.String name,
java.io.InputStream streamEntity,
java.lang.String filename,
MediaType mediaType)
All-arguments constructor with all requested parameters set by the
caller.
|
| Modifier and Type | Method and Description |
|---|---|
protected FormDataContentDisposition |
buildContentDisposition()
Builds the body part content-disposition header which the specified
filename (or the default one if unspecified).
|
protected static MediaType |
getDefaultMediaType()
Gets the default
MediaType to be used if the user didn't specify
any. |
java.lang.String |
getFilename()
Gets the filename value which is to be used in the content-disposition
header of this body part entity.
|
java.io.InputStream |
getStreamEntity()
Gets the underlying stream entity which will form the body part entity.
|
void |
setEntity(java.lang.Object entity)
This operation is not supported from this implementation.
|
void |
setFilename(java.lang.String filename)
Sets the body part entity filename value to be used in the
content-disposition header.
|
void |
setStreamEntity(java.io.InputStream streamEntity)
Allows to explicitly set the body part entity.
|
void |
setStreamEntity(java.io.InputStream streamEntity,
MediaType mediaType)
Allows to explicitly set the value and the MIME type of the body part
entity.
|
void |
setValue(MediaType mediaType,
java.lang.Object value)
This operation is not supported from this implementation.
|
void |
setValue(java.lang.String value)
This operation is not supported from this implementation.
|
getContentDisposition, getFormDataContentDisposition, getName, getValue, getValueAs, isSimple, setContentDisposition, setFormDataContentDisposition, setNamecleanup, contentDisposition, entity, getEntity, getEntityAs, getHeaders, getMediaType, getParameterizedHeaders, getParent, getProviders, setMediaType, setParent, setProviders, typepublic StreamDataBodyPart()
Default constructor which forces user to manually set
the required (name and streamEntity)
properties.
setFilename(String) can be used to set
user-specified attachment filename instead of the default one.
public StreamDataBodyPart(java.lang.String name,
java.io.InputStream streamEntity)
Convenience constructor which assumes the defaults for:
filename (part's name) and mediaType (
MediaType.APPLICATION_OCTET_STREAM_TYPE).
It builds the requested body part and makes the part ready for submission.
name - name of the form-data fieldstreamEntity - entity to be set as a body partpublic StreamDataBodyPart(java.lang.String name,
java.io.InputStream streamEntity,
java.lang.String filename)
Convenience constructor which assumes the defaults for the
mediaType (MediaType.APPLICATION_OCTET_STREAM_TYPE).
It builds the requested body part and makes the part ready for submission.
name - name of the form-data fieldstreamEntity - entity to be set as a body partfilename - filename of the sent attachment (to be set as a part of
content-disposition)public StreamDataBodyPart(java.lang.String name,
java.io.InputStream streamEntity,
java.lang.String filename,
MediaType mediaType)
All-arguments constructor with all requested parameters set by the caller.
It builds the requested body part and makes the part ready for submission.
name - name of the form-data fieldstreamEntity - entity to be set as a body partfilename - filename of the sent attachment (to be set as a part of
content-disposition)mediaType - MIME type of the streamEntity attachmentjava.lang.IllegalArgumentException - if name or streamEntity are null.public void setValue(MediaType mediaType, java.lang.Object value) throws java.lang.UnsupportedOperationException
setValue in class FormDataBodyPartmediaType - the media type for this field valuevalue - the field value as a Java objectjava.lang.UnsupportedOperationException - Operation not supported.setStreamEntity(InputStream, MediaType)public void setValue(java.lang.String value)
setValue in class FormDataBodyPartvalue - the field valuejava.lang.UnsupportedOperationException - Operation not supported.setStreamEntity(InputStream)public void setEntity(java.lang.Object entity)
throws java.lang.UnsupportedOperationException
setEntity in class BodyPartentity - The new entity objectjava.lang.UnsupportedOperationException - Operation not supported.setStreamEntity(InputStream, MediaType)public void setStreamEntity(java.io.InputStream streamEntity)
Allows to explicitly set the body part entity. This method assumes the
default MediaType.APPLICATION_OCTET_STREAM MIME type and doesn't
have to be invoked if one of the non-default constructors was already
called.
Either this method or
setStreamEntity(InputStream, MediaType)
must be invoked if the default constructor was called.
streamEntity - entity to be set as a body partpublic void setStreamEntity(java.io.InputStream streamEntity,
MediaType mediaType)
Allows to explicitly set the value and the MIME type of the body part entity. This method doesn't have to be invoked if one of the non-default constructors was already called.
Either this method or
setStreamEntity(InputStream)
must be invoked if the default constructor was called.
streamEntity - entity to be set as a body partmediaType - MIME type of the streamEntity attachmentprotected FormDataContentDisposition buildContentDisposition()
protected static MediaType getDefaultMediaType()
MediaType to be used if the user didn't specify
any.MediaType for this body part entity.public void setFilename(java.lang.String filename)
filename - name to be usedpublic java.io.InputStream getStreamEntity()
public java.lang.String getFilename()
Copyright © 2016 Oracle Corporation. All Rights Reserved.