Class StreamDataBodyPart


  • 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: 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.

    See Also:
    FileDataBodyPart
    • Field Detail

      • streamEntity

        private java.io.InputStream streamEntity
        Underlying input stream entity to be sent.
      • filename

        private java.lang.String filename
        Filename of the attachment (stream) set by the user.
    • Constructor Detail

      • StreamDataBodyPart

        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.

        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 the mediaType (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 of content-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 of content-disposition).
        mediaType - MIME type of the streamEntity attachment.
        Throws:
        java.lang.IllegalArgumentException - if name or streamEntity are null.
    • 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 class FormDataBodyPart
        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 class FormDataBodyPart
        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 class BodyPart
        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 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.

        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 or setStreamEntity(InputStream) must be invoked if the default constructor was called.

        Parameters:
        streamEntity - entity to be set as a body part.
        mediaType - MIME type of the streamEntity 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 default MediaType 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.