public interface TypedData
Modifier and Type | Method and Description |
---|---|
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.
|
MediaType getContentType()
java.lang.String getText()
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.
java.lang.String getText(java.nio.charset.Charset charset)
byte[] getBytes()
ByteBuf getBuffer()
void writeTo(java.io.OutputStream outputStream) throws java.io.IOException
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.
outputStream
- The stream to write tojava.io.IOException
- any thrown when writing to the output streamjava.io.InputStream getInputStream()
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.