Class MultiPart

java.lang.Object
org.glassfish.jersey.media.multipart.BodyPart
org.glassfish.jersey.media.multipart.MultiPart
All Implemented Interfaces:
Closeable, AutoCloseable
Direct Known Subclasses:
FormDataMultiPart

public class MultiPart extends BodyPart implements Closeable
A mutable model representing a MIME MultiPart entity. This class extends BodyPart because MultiPart entities can be nested inside other MultiPart entities to an arbitrary depth.
  • Field Details

  • Constructor Details

    • MultiPart

      public MultiPart()
      Instantiates a new MultiPart with a mediaType of multipart/mixed.
    • MultiPart

      public MultiPart(javax.ws.rs.core.MediaType mediaType)
      Instantiates a new MultiPart with the specified characteristics.
      Parameters:
      mediaType - the MediaType for this multipart.
  • Method Details

    • getBodyParts

      public List<BodyPart> getBodyParts()
      Return a mutable list of BodyParts nested in this MultiPart.
    • getEntity

      public Object getEntity()
      Disables access to the entity for a MultiPart. Use the list returned by getBodyParts() to access the relevant BodyPart instead.
      Overrides:
      getEntity in class BodyPart
      Returns:
      an entity of this body part.
      Throws:
      IllegalStateException - thrown unconditionally.
    • setEntity

      public void setEntity(Object entity)
      Disables access to the entity for a MultiPart. Use the list returned by getBodyParts() to access the relevant BodyPart instead.
      Overrides:
      setEntity in class BodyPart
      Parameters:
      entity -
    • setMediaType

      public void setMediaType(javax.ws.rs.core.MediaType mediaType)
      Sets the MediaType for this MultiPart. If never set, the default MediaType MUST be multipart/mixed.
      Overrides:
      setMediaType in class BodyPart
      Parameters:
      mediaType - the new MediaType.
      Throws:
      IllegalArgumentException - if the type property is not set to multipart.
    • bodyPart

      public MultiPart bodyPart(BodyPart bodyPart)
      Builder pattern method to add the specified BodyPart to this MultiPart.
      Parameters:
      bodyPart - BodyPart to be added.
    • bodyPart

      public MultiPart bodyPart(Object entity, javax.ws.rs.core.MediaType mediaType)
      Builder pattern method to add a newly configured BodyPart to this MultiPart.
      Parameters:
      entity - entity object for this body part.
      mediaType - content type for this body part.
    • entity

      public BodyPart entity(Object entity)
      Override the entity set operation on a MultiPart to throw IllegalArgumentException.
      Overrides:
      entity in class BodyPart
      Parameters:
      entity - entity to set for this BodyPart.
      Returns:
      body-part instance.
    • type

      public MultiPart type(javax.ws.rs.core.MediaType type)
      Builder pattern method to return this MultiPart after additional configuration.
      Overrides:
      type in class BodyPart
      Parameters:
      type - media type to set for this MultiPart.
      Returns:
      body-part instance.
    • cleanup

      public void cleanup()
      Performs any necessary cleanup at the end of processing this MultiPart.
      Overrides:
      cleanup in class BodyPart
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException