Class AbstractMultipartFormat

    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.lang.String boundary  
      (package private) java.nio.charset.Charset charset  
      (package private) static org.apache.hc.core5.util.ByteArrayBuffer CR_LF  
      private java.lang.String epilogue
      The epilogue to be included after the multipart content.
      (package private) static org.apache.hc.core5.util.ByteArrayBuffer FIELD_SEP  
      private java.lang.String preamble
      The preamble to be included before the multipart content.
      (package private) static org.apache.hc.core5.util.ByteArrayBuffer TWO_HYPHENS  
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractMultipartFormat​(java.lang.String boundary)  
      AbstractMultipartFormat​(java.nio.charset.Charset charset, java.lang.String boundary)
      Creates an instance with the specified settings.
      AbstractMultipartFormat​(java.nio.charset.Charset charset, java.lang.String boundary, java.lang.String preamble, java.lang.String epilogue)
      Constructs a new instance of AbstractMultipartFormat with the given charset, boundary, preamble, and epilogue.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) void doWriteTo​(java.io.OutputStream out, boolean writeContent)
      Writes the multipart message to the specified output stream.
      (package private) static org.apache.hc.core5.util.ByteArrayBuffer encode​(java.nio.charset.Charset charset, java.lang.CharSequence string)  
      protected abstract void formatMultipartHeader​(MultipartPart part, java.io.OutputStream out)
      Write the multipart header fields; depends on the style.
      abstract java.util.List<MultipartPart> getParts()  
      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).
      (package private) static boolean isLineBreak​(char ch)  
      (package private) static java.lang.CharSequence stripLineBreaks​(java.lang.CharSequence s)  
      (package private) static void writeBytes​(java.lang.CharSequence s, java.io.OutputStream out)  
      (package private) static void writeBytes​(java.lang.CharSequence s, java.nio.charset.Charset charset, java.io.OutputStream out)  
      (package private) static void writeBytes​(org.apache.hc.core5.util.ByteArrayBuffer b, java.io.OutputStream out)  
      (package private) static void writeField​(MimeField field, java.io.OutputStream out)  
      (package private) static void writeField​(MimeField field, java.nio.charset.Charset charset, java.io.OutputStream out)  
      void writeTo​(java.io.OutputStream out)
      Writes out the content in the multipart/form encoding.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • preamble

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

        private java.lang.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 java.nio.charset.Charset charset
      • boundary

        final java.lang.String boundary
    • Constructor Detail

      • AbstractMultipartFormat

        public AbstractMultipartFormat​(java.nio.charset.Charset charset,
                                       java.lang.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:
        java.lang.IllegalArgumentException - if charset is null or boundary is null
      • AbstractMultipartFormat

        public AbstractMultipartFormat​(java.nio.charset.Charset charset,
                                       java.lang.String boundary,
                                       java.lang.String preamble,
                                       java.lang.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:
        java.lang.IllegalArgumentException - if the boundary string is null.
      • AbstractMultipartFormat

        public AbstractMultipartFormat​(java.lang.String boundary)
    • Method Detail

      • encode

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

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

        static void writeBytes​(java.lang.CharSequence s,
                               java.nio.charset.Charset charset,
                               java.io.OutputStream out)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • writeBytes

        static void writeBytes​(java.lang.CharSequence s,
                               java.io.OutputStream out)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • isLineBreak

        static boolean isLineBreak​(char ch)
      • stripLineBreaks

        static java.lang.CharSequence stripLineBreaks​(java.lang.CharSequence s)
      • writeField

        static void writeField​(MimeField field,
                               java.io.OutputStream out)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • writeField

        static void writeField​(MimeField field,
                               java.nio.charset.Charset charset,
                               java.io.OutputStream out)
                        throws java.io.IOException
        Throws:
        java.io.IOException
      • getParts

        public abstract java.util.List<MultipartPart> getParts()
      • doWriteTo

        void doWriteTo​(java.io.OutputStream out,
                       boolean writeContent)
                throws java.io.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:
        java.io.IOException - if an I/O error occurs.
      • formatMultipartHeader

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

        public void writeTo​(java.io.OutputStream out)
                     throws java.io.IOException
        Writes out the content in the multipart/form encoding. This method produces slightly different formatting depending on its compatibility mode.
        Throws:
        java.io.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.