Interface HttpData

All Superinterfaces:
AutoCloseable, Bytes, HttpObject, SafeCloseable

public interface HttpData extends HttpObject, Bytes
HTTP/2 data that contains a chunk of bytes.
  • Method Details

    • empty

      static HttpData empty()
      Returns an empty HttpData.
    • wrap

      static HttpData wrap(byte[] data)
      Creates a new instance from the specified byte array. The array is not copied; any changes made in the array later will be visible to HttpData.
      Returns:
      a new HttpData. empty() if the length of the specified array is 0.
    • wrap

      static HttpData wrap(byte[] data, int offset, int length)
      Creates a new instance from the specified byte array, offset and length. The array is not copied; any changes made in the array later will be visible to HttpData.
      Returns:
      a new HttpData. empty() if length is 0.
      Throws:
      IndexOutOfBoundsException - if offset and length are out of bounds
    • wrap

      @UnstableApi static HttpData wrap(io.netty.buffer.ByteBuf buf)
      (Advanced users only) Converts the specified Netty ByteBuf into a pooled HttpData. The buffer is not copied; any changes made to it will be visible to HttpData. The ownership of the buffer is transferred to the HttpData. If you still need to use it after calling this method, make sure to call ByteBuf.retain() first.
      Returns:
      a new HttpData. empty() if the readable bytes of buf is 0.
      See Also:
    • copyOf

      static HttpData copyOf(byte[] data)
      Creates a new instance from the specified byte array by first copying it.
      Returns:
      a new HttpData. empty() if the length of the specified array is 0.
    • copyOf

      static HttpData copyOf(byte[] data, int offset, int length)
      Creates a new instance from the specified byte array, offset and length by first copying it.
      Returns:
      a new HttpData. empty() if length is 0.
      Throws:
      ArrayIndexOutOfBoundsException - if offset and length are out of bounds
    • copyOf

      static HttpData copyOf(io.netty.buffer.ByteBuf data)
      Creates a new instance from the specified ByteBuf by first copying its content. The reference count of ByteBuf will not be changed.
      Returns:
      a new HttpData. empty() if the length of the specified array is 0.
    • of

      static HttpData of(Charset charset, CharSequence text)
      Converts the specified text into an HttpData.
      Parameters:
      charset - the Charset to use for encoding text
      text - the String to convert
      Returns:
      a new HttpData. empty() if the length of text is 0.
    • of

      static HttpData of(Charset charset, String text)
      Converts the specified text into an HttpData.
      Parameters:
      charset - the Charset to use for encoding text
      text - the String to convert
      Returns:
      a new HttpData. empty() if the length of text is 0.
    • of

      @FormatMethod static HttpData of(Charset charset, @FormatString String format, Object... args)
      Converts the specified formatted string into an HttpData. The string is formatted by String.format(Locale, String, Object...) with English locale.
      Parameters:
      charset - the Charset to use for encoding string
      format - the format string of the response content
      args - the arguments referenced by the format specifiers in the format string
      Returns:
      a new HttpData. empty() if format is empty.
    • ofUtf8

      static HttpData ofUtf8(CharSequence text)
      Converts the specified text into a UTF-8 HttpData.
      Parameters:
      text - the String to convert
      Returns:
      a new HttpData. empty() if the length of text is 0.
    • ofUtf8

      static HttpData ofUtf8(String text)
      Converts the specified text into a UTF-8 HttpData.
      Parameters:
      text - the String to convert
      Returns:
      a new HttpData. empty() if the length of text is 0.
    • ofUtf8

      @FormatMethod static HttpData ofUtf8(@FormatString String format, Object... args)
      Converts the specified formatted string into a UTF-8 HttpData. The string is formatted by String.format(Locale, String, Object...) with English locale.
      Parameters:
      format - the format string of the response content
      args - the arguments referenced by the format specifiers in the format string
      Returns:
      a new HttpData. empty() if format is empty.
    • ofAscii

      static HttpData ofAscii(CharSequence text)
      Converts the specified text into a US-ASCII HttpData.
      Parameters:
      text - the String to convert
      Returns:
      a new HttpData. empty() if the length of text is 0.
    • ofAscii

      static HttpData ofAscii(String text)
      Converts the specified text into a US-ASCII HttpData.
      Parameters:
      text - the String to convert
      Returns:
      a new HttpData. empty() if the length of text is 0.
    • ofAscii

      @FormatMethod static HttpData ofAscii(@FormatString String format, Object... args)
      Converts the specified formatted string into a US-ASCII HttpData. The string is formatted by String.format(Locale, String, Object...) with English locale.
      Parameters:
      format - the format string of the response content
      args - the arguments referenced by the format specifiers in the format string
      Returns:
      a new HttpData. empty() if format is empty.
    • withEndOfStream

      default HttpData withEndOfStream()
      Returns the HttpData that has the same content with this data and its HTTP/2 endOfStream flag set. If this data already has endOfStream set, this will be returned.
    • withEndOfStream

      HttpData withEndOfStream(boolean endOfStream)
      Returns the HttpData that has the same content with this data and its HTTP/2 endOfStream flag set with the specified value. If this data already has the same endOfStream value set, this will be returned.