Interface EntityPart.Builder

  • Enclosing interface:
    EntityPart

    public static interface EntityPart.Builder
    Builder for EntityPart instances.
    Since:
    3.1
    • Method Detail

      • mediaType

        EntityPart.Builder mediaType​(MediaType mediaType)
                              throws java.lang.IllegalArgumentException
        Sets the media type for the EntityPart. This will also set the Content-Type header for this part.
        Parameters:
        mediaType - the media type for the part to be built
        Returns:
        the updated builder
        Throws:
        java.lang.IllegalArgumentException - if mediaType is null
      • mediaType

        EntityPart.Builder mediaType​(java.lang.String mediaTypeString)
                              throws java.lang.IllegalArgumentException
        Convenience method for setting the media type for the EntityPart. This will also set the Content-Type header for this part. This call is effectively the same as mediaType(MediaType.valueOf(mediaTypeString)).
        Parameters:
        mediaTypeString - the media type for the part to be built
        Returns:
        the updated builder
        Throws:
        java.lang.IllegalArgumentException - if mediaTypeString cannot be parsed or is null
      • header

        EntityPart.Builder header​(java.lang.String headerName,
                                  java.lang.String... headerValues)
                           throws java.lang.IllegalArgumentException
        Adds a new header or replaces a previously added header and sets the header value(s).
        Parameters:
        headerName - the header name
        headerValues - the header value(s)
        Returns:
        the updated builder
        Throws:
        java.lang.IllegalArgumentException - if headerName is null
      • headers

        EntityPart.Builder headers​(MultivaluedMap<java.lang.String,​java.lang.String> newHeaders)
                            throws java.lang.IllegalArgumentException
        Adds new headers or replaces previously added headers. The behavior of this method would be the same as if iterating over the entry set and invoking the header(String, String...) method.
        Parameters:
        newHeaders - the multivalued map of headers to add to this part
        Returns:
        the updated builder
        Throws:
        java.lang.IllegalArgumentException - if newHeaders is null
      • fileName

        EntityPart.Builder fileName​(java.lang.String fileName)
                             throws java.lang.IllegalArgumentException
        Sets the file name for this part. The file name will be specified as an attribute in the Content-Disposition header of this part. When this method is called, the default media type used for the built part will be "application/octet-stream" if not otherwise specified.
        Parameters:
        fileName - the file name for this part
        Returns:
        the updated builder
        Throws:
        java.lang.IllegalArgumentException - if fileName is null
      • content

        EntityPart.Builder content​(java.io.InputStream content)
                            throws java.lang.IllegalArgumentException
        Sets the content for this part. The content of this builder must be specified before invoking the build() method.

        The InputStream will be closed by the implementation code after sending the multipart data. Closing the stream before it is sent could result in unexpected behavior.

        Parameters:
        content - InputStream of the content of this part
        Returns:
        the updated builder
        Throws:
        java.lang.IllegalArgumentException - if content is null
      • content

        default EntityPart.Builder content​(java.lang.String fileName,
                                           java.io.InputStream content)
                                    throws java.lang.IllegalArgumentException
        Convenience method, equivalent to calling fileName(fileName).content(content).
        Parameters:
        fileName - the filename of the part.
        content - the content stream of the part.
        Returns:
        the updated builder.
        Throws:
        java.lang.IllegalArgumentException - if either parameter is null.
      • content

        <T> EntityPart.Builder content​(T content,
                                       java.lang.Class<? extends T> type)
                                throws java.lang.IllegalArgumentException
        Sets the content for this part. The content of this builder must be specified before invoking the build() method.

        If the content is specified using this method, then the build() method is responsible for finding a registered MessageBodyWriter that is capable of writing the object type specified here using the default MediaType or the MediaType specified in the mediaType(MediaType) or mediaType(String) methods and using any headers specified via the header(String, String...) or headers(MultivaluedMap) methods.

        Type Parameters:
        T - the entity type
        Parameters:
        content - the object to be used as the content
        type - the type of this object which will be used when selecting the appropriate MessageBodyWriter
        Returns:
        the updated builder.
        Throws:
        java.lang.IllegalArgumentException - if content is null
      • content

        default EntityPart.Builder content​(java.lang.Object content)
                                    throws java.lang.IllegalArgumentException
        Sets the content for this part. The content of this builder must be specified before invoking the build() method.

        If the content is specified using this method, then the build() method is responsible for finding a registered MessageBodyWriter that is capable of writing the object's class type specified here using the default MediaType or the MediaType specified in the mediaType(MediaType) or mediaType(String) methods and using any headers specified via the header(String, String...) or headers(MultivaluedMap) methods.

        This is the equivalent of calling content(content, content.getClass()).

        Parameters:
        content - the object to be used as the content
        Returns:
        the updated builder.
        Throws:
        java.lang.IllegalArgumentException - if content is null
      • content

        <T> EntityPart.Builder content​(T content,
                                       GenericType<T> type)
                                throws java.lang.IllegalArgumentException
        Sets the content for this part. The content of this builder must be specified before invoking the build() method.

        If the content is specified using this method, then the build() method is responsible for finding a registered MessageBodyWriter that is capable of writing the object type specified here using the default MediaType or the MediaType specified in the mediaType(MediaType) or mediaType(String) methods and using any headers specified via the header(String, String...) or headers(MultivaluedMap) methods.

        Type Parameters:
        T - the entity type
        Parameters:
        content - the object to be used as the content
        type - the generic type of this object which will be used when selecting the appropriate MessageBodyWriter
        Returns:
        the updated builder.
        Throws:
        java.lang.IllegalArgumentException - if content is null