Class AbstractMultipartFormat

java.lang.Object
org.apache.hc.client5.http.entity.mime.AbstractMultipartFormat
Direct Known Subclasses:
HttpRFC6532Multipart, HttpRFC7578Multipart, HttpStrictMultipart, LegacyMultipart

abstract class AbstractMultipartFormat extends Object
HttpMultipart represents a collection of MIME multipart encoded content bodies.
Since:
4.3
  • Field Details

    • preamble

      private String preamble
      The preamble to be included before the multipart content.
    • epilogue

      private String epilogue
      The epilogue to be included after the multipart content.
    • FIELD_SEP

      static final org.apache.hc.core5.util.ByteArrayBuffer FIELD_SEP
    • CR_LF

      static final org.apache.hc.core5.util.ByteArrayBuffer CR_LF
    • TWO_HYPHENS

      static final org.apache.hc.core5.util.ByteArrayBuffer TWO_HYPHENS
    • charset

      final Charset charset
    • boundary

      final String boundary
  • Constructor Details

    • AbstractMultipartFormat

      public AbstractMultipartFormat(Charset charset, String boundary)
      Creates an instance with the specified settings.
      Parameters:
      charset - the character set to use. May be null, in which case StandardCharsets.ISO_8859_1 is used.
      boundary - to use - must not be null
      Throws:
      IllegalArgumentException - if charset is null or boundary is null
    • AbstractMultipartFormat

      public AbstractMultipartFormat(Charset charset, String boundary, String preamble, String epilogue)
      Constructs a new instance of AbstractMultipartFormat with the given charset, boundary, preamble, and epilogue.
      Parameters:
      charset - the charset to use.
      boundary - the boundary string to use.
      preamble - the preamble string to use. Can be null.
      epilogue - the epilogue string to use. Can be null.
      Throws:
      IllegalArgumentException - if the boundary string is null.
    • AbstractMultipartFormat

      public AbstractMultipartFormat(String boundary)
  • Method Details

    • encode

      static org.apache.hc.core5.util.ByteArrayBuffer encode(Charset charset, CharSequence string)
    • writeBytes

      static void writeBytes(org.apache.hc.core5.util.ByteArrayBuffer b, OutputStream out) throws IOException
      Throws:
      IOException
    • writeBytes

      static void writeBytes(CharSequence s, Charset charset, OutputStream out) throws IOException
      Throws:
      IOException
    • writeBytes

      static void writeBytes(CharSequence s, OutputStream out) throws IOException
      Throws:
      IOException
    • isLineBreak

      static boolean isLineBreak(char ch)
    • stripLineBreaks

      static CharSequence stripLineBreaks(CharSequence s)
    • writeField

      static void writeField(MimeField field, OutputStream out) throws IOException
      Throws:
      IOException
    • writeField

      static void writeField(MimeField field, Charset charset, OutputStream out) throws IOException
      Throws:
      IOException
    • getParts

      public abstract List<MultipartPart> getParts()
    • doWriteTo

      void doWriteTo(OutputStream out, boolean writeContent) throws IOException
      Writes the multipart message to the specified output stream.

      If writeContent is true, the content of each part will also be written.

      If preamble is not null, it will be written before the first boundary. If epilogue is not null, it will be written after the last boundary.

      Parameters:
      out - the output stream to write the message to.
      writeContent - whether to write the content of each part.
      Throws:
      IOException - if an I/O error occurs.
    • formatMultipartHeader

      protected abstract void formatMultipartHeader(MultipartPart part, OutputStream out) throws IOException
      Write the multipart header fields; depends on the style.
      Throws:
      IOException
    • writeTo

      public void writeTo(OutputStream out) throws IOException
      Writes out the content in the multipart/form encoding. This method produces slightly different formatting depending on its compatibility mode.
      Throws:
      IOException
    • getTotalLength

      public long getTotalLength()
      Determines the total length of the multipart content (content length of individual parts plus that of extra elements required to delimit the parts from one another). If any of the @{link BodyPart}s contained in this object is of a streaming entity of unknown length the total length is also unknown.

      This method buffers only a small amount of data in order to determine the total length of the entire entity. The content of individual parts is not buffered.

      Returns:
      total length of the multipart entity if known, -1 otherwise.