public class StreamDataBodyPart extends FormDataBodyPart
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: 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
contentDisposition, messageBodyWorkers
Constructor and Description |
---|
StreamDataBodyPart()
Default constructor which forces user to manually set
the required (
name and streamEntity )
properties. |
StreamDataBodyPart(String name,
InputStream streamEntity)
Convenience constructor which assumes the defaults for:
filename (part's name) and mediaType (
MediaType.APPLICATION_OCTET_STREAM_TYPE ). |
StreamDataBodyPart(String name,
InputStream streamEntity,
String filename)
Convenience constructor which assumes the defaults for the
mediaType (MediaType.APPLICATION_OCTET_STREAM_TYPE ). |
StreamDataBodyPart(String name,
InputStream streamEntity,
String filename,
javax.ws.rs.core.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 javax.ws.rs.core.MediaType |
getDefaultMediaType()
Gets the default
MediaType to be used if the user didn't specify
any. |
String |
getFilename()
Gets the filename value which is to be used in the content-disposition
header of this body part entity.
|
InputStream |
getStreamEntity()
Gets the underlying stream entity which will form the body part entity.
|
void |
setEntity(Object entity)
This operation is not supported from this implementation.
|
void |
setFilename(String filename)
Sets the body part entity filename value to be used in the
content-disposition header.
|
void |
setStreamEntity(InputStream streamEntity)
Allows to explicitly set the body part entity.
|
void |
setStreamEntity(InputStream streamEntity,
javax.ws.rs.core.MediaType mediaType)
Allows to explicitly set the value and the MIME type of the body part
entity.
|
void |
setValue(javax.ws.rs.core.MediaType mediaType,
Object value)
This operation is not supported from this implementation.
|
void |
setValue(String value)
This operation is not supported from this implementation.
|
getContentDisposition, getFormDataContentDisposition, getName, getValue, getValueAs, isSimple, setContentDisposition, setFormDataContentDisposition, setName
cleanup, contentDisposition, entity, getEntity, getEntityAs, getHeaders, getMediaType, getParameterizedHeaders, getParent, getProviders, setMediaType, setMessageBodyWorkers, setParent, setProviders, type
public StreamDataBodyPart()
name
and streamEntity
)
properties.
setFilename(String)
can be used to set
user-specified attachment filename instead of the default one.public StreamDataBodyPart(String name, InputStream streamEntity)
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 field.streamEntity
- entity to be set as a body part.public StreamDataBodyPart(String name, InputStream streamEntity, String filename)
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 field.streamEntity
- entity to be set as a body part.filename
- filename of the sent attachment (to be set as a part of
content-disposition
).public StreamDataBodyPart(String name, InputStream streamEntity, String filename, javax.ws.rs.core.MediaType mediaType)
name
- name of the form-data field.streamEntity
- entity to be set as a body part.filename
- filename of the sent attachment (to be set as a part of
content-disposition
).mediaType
- MIME type of the streamEntity
attachment.IllegalArgumentException
- if name
or streamEntity
are null
.public void setValue(javax.ws.rs.core.MediaType mediaType, Object value) throws UnsupportedOperationException
setValue
in class FormDataBodyPart
mediaType
- the media type for this field value.value
- the field value as a Java object.UnsupportedOperationException
- Operation not supported.setStreamEntity(InputStream, MediaType)
public void setValue(String value)
setValue
in class FormDataBodyPart
value
- the field value.UnsupportedOperationException
- Operation not supported.setStreamEntity(InputStream)
public void setEntity(Object entity) throws UnsupportedOperationException
setEntity
in class BodyPart
entity
- the new entity object.UnsupportedOperationException
- Operation not supported.setStreamEntity(InputStream, MediaType)
public void setStreamEntity(InputStream streamEntity)
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 part.public void setStreamEntity(InputStream streamEntity, javax.ws.rs.core.MediaType mediaType)
setStreamEntity(InputStream)
must be invoked if the default constructor was called.streamEntity
- entity to be set as a body part.mediaType
- MIME type of the streamEntity
attachment.protected FormDataContentDisposition buildContentDisposition()
protected static javax.ws.rs.core.MediaType getDefaultMediaType()
MediaType
to be used if the user didn't specify
any.MediaType
for this body part entity.public void setFilename(String filename)
filename
- name to be used.public InputStream getStreamEntity()
public String getFilename()
Copyright © 2007-2021, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.