public abstract class AbstractRendererContext extends Object implements Renderer.Context
Constructor and Description |
---|
AbstractRendererContext(List<Renderer> renderers,
List<MediaType> produces,
Charset charset,
Locale locale,
Map<String,Object> locals) |
Modifier and Type | Method and Description |
---|---|
boolean |
accepts(MediaType type)
True if the given type matches the
Accept header. |
Charset |
charset() |
Renderer.Context |
length(long length)
Set the
Content-Length header IF and ONLY IF, no Content-Length was
set yet. |
Locale |
locale()
Request locale or default locale.
|
Map<String,Object> |
locals() |
void |
render(Object value) |
void |
send(byte[] bytes)
Write bytes into the HTTP response body.
|
void |
send(ByteBuffer buffer)
Write byte buffer into the HTTP response body.
|
void |
send(CharBuffer buffer)
Write text into the HTTP response body.
|
void |
send(FileChannel file)
Write file into the HTTP response body, using OS zero-copy transfer (if possible).
|
void |
send(InputStream stream)
Write bytes into the HTTP response body.
|
void |
send(Reader reader)
Write text into the HTTP response body.
|
void |
send(String text)
Write text into the HTTP response body.
|
String |
toString() |
Renderer.Context |
type(MediaType type)
Set the
Content-Type header IF and ONLY IF, no Content-Type was set
yet. |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
accepts, type
public Locale locale()
Renderer.Context
locale
in interface Renderer.Context
public Map<String,Object> locals()
locals
in interface Renderer.Context
public boolean accepts(MediaType type)
Renderer.Context
Accept
header.accepts
in interface Renderer.Context
type
- The type to check for.Accept
header.public Renderer.Context type(MediaType type)
Renderer.Context
Content-Type
header IF and ONLY IF, no Content-Type
was set
yet.type
in interface Renderer.Context
type
- A suggested type to use if one is missing.public Renderer.Context length(long length)
Renderer.Context
Content-Length
header IF and ONLY IF, no Content-Length
was
set yet.length
in interface Renderer.Context
length
- A suggested length to use if one is missing.public Charset charset()
charset
in interface Renderer.Context
public void send(CharBuffer buffer) throws Exception
Renderer.Context
Content-Length
if none was set.
It will set a Content-Type
to MediaType.html
if none was set.send
in interface Renderer.Context
buffer
- A text to write.Exception
- When the operation fails.public void send(Reader reader) throws Exception
Renderer.Context
Content-Length
if the response size is less than the
server.ResponseBufferSize
(default is: 16k). If the response is larger than the
buffer size, it will set a Transfer-Encoding: chunked
header.
It will set a Content-Type
to MediaType.html
if none was set.send
in interface Renderer.Context
reader
- Text to write.Exception
- When the operation fails.public void send(String text) throws Exception
Renderer.Context
Content-Length
if none was set.
It will set a Content-Type
to MediaType.html
if none was set.send
in interface Renderer.Context
text
- A text to write.Exception
- When the operation fails.public void send(byte[] bytes) throws Exception
Renderer.Context
Content-Length
if none was set
It will set a Content-Type
to MediaType.octetstream
if none was set.send
in interface Renderer.Context
bytes
- A bytes to write.Exception
- When the operation fails.public void send(ByteBuffer buffer) throws Exception
Renderer.Context
Content-Length
if none was set.
It will set a Content-Type
to MediaType.octetstream
if none was set.send
in interface Renderer.Context
buffer
- A buffer to write.Exception
- When the operation fails.public void send(FileChannel file) throws Exception
Renderer.Context
Content-Length
if none was set.
It will set a Content-Type
to MediaType.html
if none was set.send
in interface Renderer.Context
file
- A text to write.Exception
- When the operation fails.public void send(InputStream stream) throws Exception
Renderer.Context
Content-Length
if the response size is less than the
server.ResponseBufferSize
(default is: 16k). If the response is larger than the
buffer size, it will set a Transfer-Encoding: chunked
header.
It will set a Content-Type
to MediaType.octetstream
if none was set.
This method will check if the given input stream has a FileChannel
and redirect to
filesend
in interface Renderer.Context
stream
- Bytes to write.Exception
- When the operation fails.Copyright © 2017. All rights reserved.