Class StreamDataBodyPart
- java.lang.Object
-
- org.glassfish.jersey.media.multipart.BodyPart
-
- org.glassfish.jersey.media.multipart.FormDataBodyPart
-
- org.glassfish.jersey.media.multipart.file.StreamDataBodyPart
-
public class StreamDataBodyPart extends FormDataBodyPart
Represents anInputStream
based file submission as a part of the multipart/form-data. It sets theInputStream
as a body part with the defaultMediaType.APPLICATION_OCTET_STREAM_TYPE
(if not specified by the user). Note: The MIME type of the entity cannot be automatically predicted as in case ofFileDataBodyPart
. The filename of the attachment is set by the user or defaults to the part's name.- See Also:
FileDataBodyPart
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
filename
Filename of the attachment (stream) set by the user.private java.io.InputStream
streamEntity
Underlying input stream entity to be sent.-
Fields inherited from class org.glassfish.jersey.media.multipart.BodyPart
contentDisposition, messageBodyWorkers
-
-
Constructor Summary
Constructors Constructor Description StreamDataBodyPart()
Default constructor which forces user to manually set the required (name
andstreamEntity
) properties.StreamDataBodyPart(java.lang.String name, java.io.InputStream streamEntity)
Convenience constructor which assumes the defaults for:filename
(part's name) andmediaType
(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 themediaType
(MediaType.APPLICATION_OCTET_STREAM_TYPE
).StreamDataBodyPart(java.lang.String name, java.io.InputStream streamEntity, java.lang.String filename, javax.ws.rs.core.MediaType mediaType)
All-arguments constructor with all requested parameters set by the caller.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method 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 defaultMediaType
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, javax.ws.rs.core.MediaType mediaType)
Allows to explicitly set the value and the MIME type of the body part entity.void
setValue(java.lang.String value)
This operation is not supported from this implementation.void
setValue(javax.ws.rs.core.MediaType mediaType, java.lang.Object value)
This operation is not supported from this implementation.-
Methods inherited from class org.glassfish.jersey.media.multipart.FormDataBodyPart
getContentDisposition, getFormDataContentDisposition, getName, getValue, getValueAs, isSimple, setContentDisposition, setFormDataContentDisposition, setName
-
Methods inherited from class org.glassfish.jersey.media.multipart.BodyPart
cleanup, contentDisposition, entity, getEntity, getEntityAs, getHeaders, getMediaType, getParameterizedHeaders, getParent, getProviders, setMediaType, setMessageBodyWorkers, setParent, setProviders, type
-
-
-
-
Constructor Detail
-
StreamDataBodyPart
public StreamDataBodyPart()
Default constructor which forces user to manually set the required (name
andstreamEntity
) properties.setFilename(String)
can be used to set user-specified attachment filename instead of the default one.
-
StreamDataBodyPart
public StreamDataBodyPart(java.lang.String name, java.io.InputStream streamEntity)
Convenience constructor which assumes the defaults for:filename
(part's name) andmediaType
(MediaType.APPLICATION_OCTET_STREAM_TYPE
). It builds the requested body part and makes the part ready for submission.- Parameters:
name
- name of the form-data field.streamEntity
- entity to be set as a body part.
-
StreamDataBodyPart
public StreamDataBodyPart(java.lang.String name, java.io.InputStream streamEntity, java.lang.String filename)
Convenience constructor which assumes the defaults for themediaType
(MediaType.APPLICATION_OCTET_STREAM_TYPE
). It builds the requested body part and makes the part ready for submission.- Parameters:
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 ofcontent-disposition
).
-
StreamDataBodyPart
public StreamDataBodyPart(java.lang.String name, java.io.InputStream streamEntity, java.lang.String filename, javax.ws.rs.core.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.- Parameters:
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 ofcontent-disposition
).mediaType
- MIME type of thestreamEntity
attachment.- Throws:
java.lang.IllegalArgumentException
- ifname
orstreamEntity
arenull
.
-
-
Method Detail
-
setValue
public void setValue(javax.ws.rs.core.MediaType mediaType, java.lang.Object value) throws java.lang.UnsupportedOperationException
This operation is not supported from this implementation.- Overrides:
setValue
in classFormDataBodyPart
- Parameters:
mediaType
- the media type for this field value.value
- the field value as a Java object.- Throws:
java.lang.UnsupportedOperationException
- Operation not supported.- See Also:
setStreamEntity(InputStream, MediaType)
-
setValue
public void setValue(java.lang.String value)
This operation is not supported from this implementation.- Overrides:
setValue
in classFormDataBodyPart
- Parameters:
value
- the field value.- Throws:
java.lang.UnsupportedOperationException
- Operation not supported.- See Also:
setStreamEntity(InputStream)
-
setEntity
public void setEntity(java.lang.Object entity) throws java.lang.UnsupportedOperationException
This operation is not supported from this implementation.- Overrides:
setEntity
in classBodyPart
- Parameters:
entity
- the new entity object.- Throws:
java.lang.UnsupportedOperationException
- Operation not supported.- See Also:
setStreamEntity(InputStream, MediaType)
-
setStreamEntity
public void setStreamEntity(java.io.InputStream streamEntity)
Allows to explicitly set the body part entity. This method assumes the defaultMediaType.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 orsetStreamEntity(InputStream, MediaType)
must be invoked if the default constructor was called.- Parameters:
streamEntity
- entity to be set as a body part.
-
setStreamEntity
public void setStreamEntity(java.io.InputStream streamEntity, javax.ws.rs.core.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 orsetStreamEntity(InputStream)
must be invoked if the default constructor was called.- Parameters:
streamEntity
- entity to be set as a body part.mediaType
- MIME type of thestreamEntity
attachment.
-
buildContentDisposition
protected FormDataContentDisposition buildContentDisposition()
Builds the body part content-disposition header which the specified filename (or the default one if unspecified).- Returns:
- ready to use content-disposition header.
-
getDefaultMediaType
protected static javax.ws.rs.core.MediaType getDefaultMediaType()
Gets the defaultMediaType
to be used if the user didn't specify any.- Returns:
- default
MediaType
for this body part entity.
-
setFilename
public void setFilename(java.lang.String filename)
Sets the body part entity filename value to be used in the content-disposition header.- Parameters:
filename
- name to be used.
-
getStreamEntity
public java.io.InputStream getStreamEntity()
Gets the underlying stream entity which will form the body part entity.- Returns:
- underlying stream.
-
getFilename
public java.lang.String getFilename()
Gets the filename value which is to be used in the content-disposition header of this body part entity.- Returns:
- filename.
-
-