Class HttpContent

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected byte[] content  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static HttpContent bytes​(byte[] content)
      Create a new content from the given bytes.
      static HttpContent bytes​(byte[] content, int offset, int length)
      Create a new content from the given bytes.
      protected abstract byte[] compute()  
      static HttpContent file​(java.io.File file)
      Create a new content from the given file.
      static HttpContent form​(java.lang.String key, java.lang.String value)
      Create a new content from the given form data.
      static HttpContent form​(java.util.Map<java.lang.String,​java.lang.String> form)
      Create a new content from the given form data.
      byte[] getAsBytes()  
      java.lang.String getAsString()  
      java.lang.String getAsString​(java.nio.charset.Charset charset)
      Get the content as a string with the given charset.
      abstract int getContentLength()  
      ContentType getContentType()  
      static HttpContent string​(java.lang.String content)
      Create a new content from the given string.
      static HttpContent string​(java.lang.String content, java.nio.charset.Charset charset)
      Create a new content from the given string.
      • Methods inherited from class java.lang.Object

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

      • content

        protected byte[] content
    • Constructor Detail

      • HttpContent

        public HttpContent​(ContentType contentType)
    • Method Detail

      • bytes

        public static HttpContent bytes​(byte[] content)
        Create a new content from the given bytes.
        Parameters:
        content - The bytes to send
        Returns:
        The created content
      • bytes

        public static HttpContent bytes​(byte[] content,
                                        int offset,
                                        int length)
        Create a new content from the given bytes.
        Parameters:
        content - The bytes to send
        offset - The offset to start reading from
        length - The length of the bytes to read
        Returns:
        The created content
      • string

        public static HttpContent string​(java.lang.String content)
        Create a new content from the given string.
        Parameters:
        content - The string to send
        Returns:
        The created content
      • string

        public static HttpContent string​(java.lang.String content,
                                         java.nio.charset.Charset charset)
        Create a new content from the given string.
        Parameters:
        content - The string to send
        charset - The charset to use
        Returns:
        The created content
      • file

        public static HttpContent file​(java.io.File file)
        Create a new content from the given file.
        Parameters:
        file - The file to send
        Returns:
        The created content
      • form

        public static HttpContent form​(java.lang.String key,
                                       java.lang.String value)
        Create a new content from the given form data.
        Parameters:
        key - The key
        value - The value
        Returns:
        The created content
      • form

        public static HttpContent form​(java.util.Map<java.lang.String,​java.lang.String> form)
        Create a new content from the given form data.
        Parameters:
        form - The form data
        Returns:
        The created content
      • getContentType

        public ContentType getContentType()
        Returns:
        The content type
      • getAsBytes

        @Nonnull
        public byte[] getAsBytes()
                          throws java.io.IOException
        Returns:
        The content as bytes
        Throws:
        java.io.IOException - If an I/O error occurs
      • getAsString

        @Nonnull
        public java.lang.String getAsString()
                                     throws java.io.IOException
        Returns:
        The content as a UTF-8 string
        Throws:
        java.io.IOException - If an I/O error occurs
      • getAsString

        @Nonnull
        public java.lang.String getAsString​(java.nio.charset.Charset charset)
                                     throws java.io.IOException
        Get the content as a string with the given charset.
        Parameters:
        charset - The charset to use
        Returns:
        The content as a string
        Throws:
        java.io.IOException - If an I/O error occurs
      • getContentLength

        public abstract int getContentLength()
        Returns:
        The content length
      • compute

        @Nonnull
        protected abstract byte[] compute()
                                   throws java.io.IOException
        Returns:
        The content
        Throws:
        java.io.IOException - If an I/O error occurs