Class MultipartFormWriter


  • public class MultipartFormWriter
    extends Object
    Represents a form writer capable of sending files and form data as multipart chunks.
    • Constructor Detail

      • MultipartFormWriter

        public MultipartFormWriter​(MultipartFormContentType contentType,
                                   OutputStream os)
        Attaches to the outputstream and allows writing form data or files to it.
        Parameters:
        contentType - The form content type
        os - the output stream
    • Method Detail

      • writeField

        public void writeField​(String name,
                               String value)
                        throws IOException
        Writes a string field value.
        Parameters:
        name - the field name (required)
        value - the field value
        Throws:
        IOException - on input/output errors
      • writeFile

        public void writeFile​(String name,
                              String mimeType,
                              File file)
                       throws IOException
        Writes a file's contents.
        Parameters:
        name - the field name
        mimeType - the file content type (optional, recommended)
        file - the file (the file must exist)
        Throws:
        IOException - on input/output errors
      • writeFile

        public void writeFile​(String name,
                              String mimeType,
                              String fileName,
                              InputStream is)
                       throws IOException
        Writes a input stream's contents.
        Parameters:
        name - The field name
        mimeType - The file content type (optional, recommended)
        fileName - The file name (required)
        is - The input stream
        Throws:
        IOException - on input/output errors
      • writeFile

        public void writeFile​(String name,
                              String mimeType,
                              String fileName,
                              byte[] data)
                       throws IOException
        Writes the given bytes.
        Parameters:
        name - the field name
        mimeType - the file content type (optional, recommended)
        fileName - the file name (required)
        data - the file data
        Throws:
        IOException - on input/output errors
      • close

        public void close()
                   throws IOException
        Closes the writer. This method must be called.
        Throws:
        IOException - on input/output errors