public class HttpResponse extends Response
Constructor and Description |
---|
HttpResponse()
构造 HTTP 响应对象
|
HttpResponse(Response response,
String characterSet,
IoSession socketSession)
构造 HTTP 响应对象
|
HttpResponse(String characterSet,
IoSession socketSession)
构造 HTTP 响应对象
|
Modifier and Type | Method and Description |
---|---|
HttpResponse |
copyFrom(HttpResponse response) |
HttpResponse |
copyFrom(HttpResponse response,
boolean useForSend) |
void |
flush()
将数据发送到 Socket 缓存
|
HttpResponse |
getAsyncResponse() |
String |
getCharacterSet()
获取当前默认字符集
|
IoSession |
getSocketSession()
获取 socket 会话对象
|
void |
init(String characterSet,
IoSession socketSession) |
void |
redirct(String path)
重定向
|
void |
send()
发送响应
|
int |
send(ByteBuffer byteBuffer)
追加形式发送数据
|
void |
setCharacterSet(String characterSet)
设置当前默认字符集
|
protected void |
setSocketSession(IoSession socketSession)
设置 socket 会话对象
|
void |
write(byte[] bytes)
写入一个 byte 数组
|
void |
write(byte[] bytes,
int offset,
int length)
写入一个 byte 数组
|
void |
write(String strs)
写入一个字符串
|
void |
writeObject(Object obj)
写入 body 对象, 自动转换为 json,默认 UTF-8
|
void |
writeObject(Object obj,
String charset)
写入 body 字符串 自动转换为 json
|
public HttpResponse()
public HttpResponse(Response response, String characterSet, IoSession socketSession)
response
- 响应对象socketSession
- Socket会话对象characterSet
- 字符集public IoSession getSocketSession()
protected void setSocketSession(IoSession socketSession)
socketSession
- socket 会话对象public String getCharacterSet()
public void setCharacterSet(String characterSet)
characterSet
- 默认字符集public HttpResponse getAsyncResponse()
public void write(byte[] bytes)
bytes
- byte 数组public void write(byte[] bytes, int offset, int length)
bytes
- byte 数组offset
- 偏移量length
- 写入长度public void write(String strs)
strs
- 字符串public void writeObject(Object obj)
obj
- body 对象public void writeObject(Object obj, String charset)
obj
- body 对象charset
- 字符集public void send() throws IOException
IOException
- IO 异常public int send(ByteBuffer byteBuffer) throws IOException
byteBuffer
- 发送的缓冲区IOException
- IOException IO 异常public void flush()
public void redirct(String path)
path
- 重定向路径public HttpResponse copyFrom(HttpResponse response, boolean useForSend)
public HttpResponse copyFrom(HttpResponse response)
Copyright © 2020 Voovan. All rights reserved.