Class MultiPart.Part

java.lang.Object
org.eclipse.jetty.http.MultiPart.Part
Direct Known Subclasses:
MultiPart.ByteBufferPart, MultiPart.ChunksPart, MultiPart.ContentSourcePart, MultiPart.PathPart, MultiPartByteRanges.Part
Enclosing class:
MultiPart

public abstract static class MultiPart.Part extends Object

A single part of a multipart content.

A part has an optional name, an optional fileName, optional headers and an optional content.

  • Constructor Details

  • Method Details

    • getName

      public String getName()

      Returns the name of this part, as specified by the HttpHeader.CONTENT_DISPOSITION's name parameter.

      While the name parameter is mandatory per RFC 7578, older HTTP clients may not send it.

      Returns:
      the name of this part, or null if there is no name
    • getFileName

      public String getFileName()

      Returns the file name of this part, as specified by the HttpHeader.CONTENT_DISPOSITION's filename parameter.

      While the filename parameter is mandatory per RFC 7578 when uploading files, older HTTP clients may not send it.

      The file name may be absent if the part is not a file upload.

      Returns:
      the file name of this part, or null if there is no file name
    • getContent

      public abstract org.eclipse.jetty.io.Content.Source getContent()

      Returns the content of this part.

      The content type and content encoding are specified in this part's headers.

      The content encoding may be specified by the part named _charset_, as specified in RFC 7578, section 4.6.

      Returns:
      the content of this part
    • getContentAsString

      public String getContentAsString(Charset defaultCharset)

      Returns the content of this part as a string.

      The charset used to decode the bytes is:

      • the charset parameter of the HttpHeader.CONTENT_TYPE header, if non-null;
      • otherwise, the given defaultCharset parameter, if non-null;
      • otherwise, UTF-8.
      Parameters:
      defaultCharset - the charset to use to decode the bytes, if the charset parameter of the Content-Type header is missing
      Returns:
      the content of this part as a string
    • getHeaders

      public HttpFields getHeaders()
      Returns:
      the headers associated with this part
    • writeTo

      public void writeTo(Path path) throws IOException

      Writes the content of this part to the given path.

      Parameters:
      path - the Path to write this part's content to
      Throws:
      IOException - if the write fails