Package ratpack.http

Interface TypedData

  • All Known Subinterfaces:
    UploadedFile

    public interface TypedData
    Data that potentially has a content type.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      io.netty.buffer.ByteBuf getBuffer()
      The raw data as a (unmodifiable) buffer.
      byte[] getBytes()
      The raw data as bytes.
      MediaType getContentType()
      The type of the data.
      java.io.InputStream getInputStream()
      An input stream of the data.
      java.lang.String getText()
      The data as text.
      java.lang.String getText​(java.nio.charset.Charset charset)  
      void writeTo​(java.io.OutputStream outputStream)
      Writes the data to the given output stream.
    • Method Detail

      • getContentType

        MediaType getContentType()
        The type of the data.
        Returns:
        The type of the data.
      • getText

        java.lang.String getText()
        The data as text.

        If a content type was provided, and it provided a charset parameter, that charset will be used to decode the text. If no charset was provided, UTF-8 will be assumed.

        This can lead to incorrect results for non text/* type content types. For example, application/json is implicitly UTF-8 but this method will not know that.

        Returns:
        The data decoded as text
      • getText

        java.lang.String getText​(java.nio.charset.Charset charset)
      • getBytes

        byte[] getBytes()
        The raw data as bytes. The returned array should not be modified.
        Returns:
        the raw data as bytes.
      • getBuffer

        io.netty.buffer.ByteBuf getBuffer()
        The raw data as a (unmodifiable) buffer.
        Returns:
        the raw data as bytes.
      • writeTo

        void writeTo​(java.io.OutputStream outputStream)
              throws java.io.IOException
        Writes the data to the given output stream.

        Data is effectively piped from getInputStream() to the given output stream. As such, if the given output stream might block (e.g. is backed by a file or socket) then this should be called from a blocking thread using Blocking.get(ratpack.func.Factory) This method does not flush or close the stream.

        Parameters:
        outputStream - The stream to write to
        Throws:
        java.io.IOException - any thrown when writing to the output stream
      • getInputStream

        java.io.InputStream getInputStream()
        An input stream of the data.

        This input stream is backed by an in memory buffer. Reading from this input stream will never block.

        It is not necessary to close the input stream.

        Returns:
        an input stream of the data