Class StreamDataBodyPart
java.lang.Object
org.glassfish.jersey.media.multipart.BodyPart
org.glassfish.jersey.media.multipart.FormDataBodyPart
org.glassfish.jersey.media.multipart.file.StreamDataBodyPart
- All Implemented Interfaces:
EntityPart
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: 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.- Author:
- Pedro Kowalski (pallipp at gmail.com), Michal Gajdos
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface jakarta.ws.rs.core.EntityPart
EntityPart.Builder -
Field Summary
Fields inherited from class org.glassfish.jersey.media.multipart.FormDataBodyPart
contentReadFields inherited from class org.glassfish.jersey.media.multipart.BodyPart
contentDisposition, messageBodyWorkers -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor which forces user to manually set the required (nameandstreamEntity) properties.StreamDataBodyPart(String name, InputStream streamEntity) Convenience constructor which assumes the defaults for:filename(part's name) andmediaType(MediaType.APPLICATION_OCTET_STREAM_TYPE).StreamDataBodyPart(String name, InputStream streamEntity, String filename) Convenience constructor which assumes the defaults for themediaType(MediaType.APPLICATION_OCTET_STREAM_TYPE).StreamDataBodyPart(String name, InputStream streamEntity, String filename, MediaType mediaType) All-arguments constructor with all requested parameters set by the caller. -
Method Summary
Modifier and TypeMethodDescriptionprotected FormDataContentDispositionBuilds the body part content-disposition header which the specified filename (or the default one if unspecified).protected static MediaTypeGets the defaultMediaTypeto be used if the user didn't specify any.Gets the filename value which is to be used in the content-disposition header of this body part entity.Gets the underlying stream entity which will form the body part entity.voidThis operation is not supported from this implementation.voidsetFilename(String filename) Sets the body part entity filename value to be used in the content-disposition header.voidsetStreamEntity(InputStream streamEntity) Allows to explicitly set the body part entity.voidsetStreamEntity(InputStream streamEntity, MediaType mediaType) Allows to explicitly set the value and the MIME type of the body part entity.voidThis operation is not supported from this implementation.voidThis operation is not supported from this implementation.Methods inherited from class org.glassfish.jersey.media.multipart.FormDataBodyPart
getContent, getContent, getContent, getContentDisposition, getFormDataContentDisposition, getName, getValue, getValueAs, isSimple, setContentDisposition, setFormDataContentDisposition, setNameMethods inherited from class org.glassfish.jersey.media.multipart.BodyPart
cleanup, contentDisposition, entity, getEntity, getEntityAs, getHeaders, getMediaType, getParameterizedHeaders, getParent, getProviders, setMediaType, setMessageBodyWorkers, setParent, setProviders, typeMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jakarta.ws.rs.core.EntityPart
getHeaders, getMediaType
-
Constructor Details
-
StreamDataBodyPart
public StreamDataBodyPart()Default constructor which forces user to manually set the required (nameandstreamEntity) properties.setFilename(String)can be used to set user-specified attachment filename instead of the default one. -
StreamDataBodyPart
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
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(String name, InputStream streamEntity, 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.- 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 thestreamEntityattachment.- Throws:
IllegalArgumentException- ifnameorstreamEntityarenull.
-
-
Method Details
-
setValue
This operation is not supported from this implementation.- Overrides:
setValuein classFormDataBodyPart- Parameters:
mediaType- the media type for this field value.value- the field value as a Java object.- Throws:
UnsupportedOperationException- Operation not supported.- See Also:
-
setValue
This operation is not supported from this implementation.- Overrides:
setValuein classFormDataBodyPart- Parameters:
value- the field value.- Throws:
UnsupportedOperationException- Operation not supported.- See Also:
-
setEntity
This operation is not supported from this implementation.- Overrides:
setEntityin classBodyPart- Parameters:
entity- the new entity object.- Throws:
UnsupportedOperationException- Operation not supported.- See Also:
-
setStreamEntity
Allows to explicitly set the body part entity. This method assumes the defaultMediaType.APPLICATION_OCTET_STREAMMIME 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
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 thestreamEntityattachment.
-
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
Gets the defaultMediaTypeto be used if the user didn't specify any.- Returns:
- default
MediaTypefor this body part entity.
-
setFilename
Sets the body part entity filename value to be used in the content-disposition header.- Parameters:
filename- name to be used.
-
getStreamEntity
Gets the underlying stream entity which will form the body part entity.- Returns:
- underlying stream.
-
getFilename
Gets the filename value which is to be used in the content-disposition header of this body part entity.- Returns:
- filename.
-
getFileName
- Specified by:
getFileNamein interfaceEntityPart- Overrides:
getFileNamein classFormDataBodyPart
-