Interface TypedData

  • All Known Subinterfaces:
    UploadedFile

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

      • getContentType

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

        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
      • 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​(OutputStream outputStream)
              throws 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(Factory) This method does not flush or close the stream.

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

        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