Class MultiPartRepresentation


public class MultiPartRepresentation extends InputRepresentation
Input representation that can either parse or generate a multipart form data representation depending on which constructor is invoked.
Author:
Jerome Louvel
  • Constructor Details

    • MultiPartRepresentation

      public MultiPartRepresentation(List<org.eclipse.jetty.http.MultiPart.Part> parts)
      Constructor that wraps multiple parts, set a random boundary, then GENERATES the content via getStream() as a MediaType.MULTIPART_FORM_DATA.
      Parameters:
      parts - The source parts to use when generating the representation.
    • MultiPartRepresentation

      public MultiPartRepresentation(MediaType mediaType, String boundary, List<org.eclipse.jetty.http.MultiPart.Part> parts)
      Constructor that wraps multiple parts, set a media type with a boundary, then GENERATES the content via getStream() as a MediaType.MULTIPART_FORM_DATA.
      Parameters:
      mediaType - The media type to set.
      boundary - The boundary to add as a parameter.
      parts - The source parts to use when generating the representation.
    • MultiPartRepresentation

      public MultiPartRepresentation(org.eclipse.jetty.http.MultiPart.Part... parts)
      Constructor that wraps multiple parts, set a random boundary, then GENERATES the content via getStream() as a MediaType.MULTIPART_FORM_DATA.
      Parameters:
      parts - The source parts to use when generating the representation.
    • MultiPartRepresentation

      public MultiPartRepresentation(Representation multiPartEntity, org.eclipse.jetty.http.MultiPartConfig config) throws IOException
      Constructor that PARSES the content based on a given configuration into getParts().
      Parameters:
      multiPartEntity - The multipart entity to parse which should have a media type based on MediaType.MULTIPART_FORM_DATA, with a "boundary" parameter.
      config - The multipart configuration.
      Throws:
      IOException
    • MultiPartRepresentation

      public MultiPartRepresentation(Representation multiPartEntity, Path storageLocation) throws IOException
      Constructor that PARSES the content based on a given configuration into getParts(). Uses a default MultiPartConfig.
      Parameters:
      multiPartEntity - The multipart entity to parse which should have a media type based on MediaType.MULTIPART_FORM_DATA, with a "boundary" parameter.
      storageLocation - The location where parsed files are stored for easier access.
      Throws:
      IOException
    • MultiPartRepresentation

      public MultiPartRepresentation(MediaType mediaType, InputStream multiPartEntity, org.eclipse.jetty.http.MultiPartConfig config) throws IOException
      Constructor that PARSES the content based on a given configuration into getParts().
      Parameters:
      mediaType - The media type that should be based on MediaType.MULTIPART_FORM_DATA, with a "boundary" parameter.
      multiPartEntity - The multipart entity to parse.
      config - The multipart configuration.
      Throws:
      IOException
    • MultiPartRepresentation

      public MultiPartRepresentation(String boundary, List<org.eclipse.jetty.http.MultiPart.Part> parts)
      Constructor that wraps multiple parts, set a boundary, then GENERATES the content via getStream() as a MediaType.MULTIPART_FORM_DATA.
      Parameters:
      boundary - The boundary to add as a parameter.
      parts - The source parts to use when generating the representation.
    • MultiPartRepresentation

      public MultiPartRepresentation(String boundary, org.eclipse.jetty.http.MultiPart.Part... parts)
      Constructor that wraps multiple parts, set a boundary, then GENERATES the content via getStream() as a MediaType.MULTIPART_FORM_DATA.
      Parameters:
      parts - The source parts to use when generating the representation.
  • Method Details

    • createPart

      public static org.eclipse.jetty.http.MultiPart.Part createPart(String name, String fileName, Representation partContent) throws IOException
      Creates a #MultiPart.Part object based on a Representation plus metadata.
      Parameters:
      name - The name of the part.
      fileName - The client suggests file name for storing the part.
      partContent - The part content.
      Returns:
      The Jetty #MultiPart.Part object created.
      Throws:
      IOException
    • getBoundary

      public static String getBoundary(MediaType mediaType)
      Returns the value of the first media-type parameter with "boundary" name.
      Parameters:
      mediaType - The media type that might contain a "boundary" parameter.
      Returns:
      The value of the first media-type parameter with "boundary" name.
    • setBoundary

      public static MediaType setBoundary(MediaType mediaType, String boundary)
      Sets a boundary to an existing media type. If the original mediatype already has a "boundary" parameter, it will be erased. *
      Parameters:
      mediaType - The media type to update.
      boundary - The boundary to add as a parameter.
      Returns:
      The updated media type.
    • getBoundary

      public String getBoundary()
      Returns the boundary used to separate each part for the parsed or generated form.
      Returns:
      The boundary used to separate each part for the parsed or generated form.
    • getParts

      public List<org.eclipse.jetty.http.MultiPart.Part> getParts()
      Returns the wrapped multipart form data either parsed or to be generated.
      Returns:
      The wrapped multipart form data either parsed or to be generated.
    • getStream

      public InputStream getStream() throws IOException
      Returns an input stream that generates the multipart form data serialization for the wrapped getParts() object. The "boundary" must be non-null when invoking this method.
      Overrides:
      getStream in class InputRepresentation
      Returns:
      An input stream that generates the multipart form data.
      Throws:
      IOException
    • setBoundary

      public void setBoundary(String boundary)
      Sets the boundary used to separate each part for the parsed or generated form. It will also update the MediaType's "boundary" attribute.
      Parameters:
      boundary - The boundary used to separate each part for the parsed or generated form.