public class Response extends Object implements Closeable
| 限定符 | 构造器和说明 |
|---|---|
protected |
Response(IStatus status,
String mimeType,
InputStream data,
long totalBytes)
Creates a fixed length response if totalBytes>=0, otherwise chunked.
|
| 限定符和类型 | 方法和说明 |
|---|---|
void |
addCookieHeader(String cookie)
Adds a cookie header to the list.
|
void |
addHeader(String name,
String value)
Adds given line to the header.
|
void |
close() |
void |
closeConnection(boolean close)
Indicate to close the connection after the Response has been sent.
|
List<String> |
getCookieHeaders()
Should not be called manually.
|
InputStream |
getData() |
String |
getHeader(String name) |
String |
getMimeType() |
Method |
getRequestMethod() |
IStatus |
getStatus() |
boolean |
isCloseConnection() |
static Response |
newChunkedResponse(IStatus status,
String mimeType,
InputStream data)
Create a response with unknown length (using HTTP 1.1 chunking).
|
static Response |
newFixedLengthResponse(IStatus status,
String mimeType,
byte[] data) |
static Response |
newFixedLengthResponse(IStatus status,
String mimeType,
InputStream data,
long totalBytes)
Create a response with known length.
|
static Response |
newFixedLengthResponse(IStatus status,
String mimeType,
String txt)
Create a text response with known length.
|
static Response |
newFixedLengthResponse(String msg)
Create a text response with known length.
|
protected void |
printHeader(PrintWriter pw,
String key,
String value) |
void |
send(OutputStream outputStream)
Sends given response to the socket.
|
protected long |
sendContentLengthHeaderIfNotAlreadyPresent(PrintWriter pw,
long defaultSize) |
void |
setChunkedTransfer(boolean chunkedTransfer) |
void |
setData(InputStream data) |
void |
setKeepAlive(boolean useKeepAlive) |
void |
setMimeType(String mimeType) |
void |
setRequestMethod(Method requestMethod) |
void |
setStatus(IStatus status) |
Response |
setUseGzip(boolean useGzip) |
boolean |
useGzipWhenAccepted() |
protected Response(IStatus status, String mimeType, InputStream data, long totalBytes)
public void close()
throws IOException
close 在接口中 Closeableclose 在接口中 AutoCloseableIOExceptionpublic void addCookieHeader(String cookie)
public List<String> getCookieHeaders()
public void closeConnection(boolean close)
close - true to hint connection closing, false to let
connection be closed by client.public boolean isCloseConnection()
true if connection is to be closed after this Response
has been sent.public InputStream getData()
public String getMimeType()
public Method getRequestMethod()
public IStatus getStatus()
public void setKeepAlive(boolean useKeepAlive)
public void send(OutputStream outputStream)
protected void printHeader(PrintWriter pw, String key, String value)
protected long sendContentLengthHeaderIfNotAlreadyPresent(PrintWriter pw, long defaultSize)
public void setChunkedTransfer(boolean chunkedTransfer)
public void setData(InputStream data)
public void setMimeType(String mimeType)
public void setRequestMethod(Method requestMethod)
public void setStatus(IStatus status)
public static Response newChunkedResponse(IStatus status, String mimeType, InputStream data)
public static Response newFixedLengthResponse(IStatus status, String mimeType, byte[] data)
public static Response newFixedLengthResponse(IStatus status, String mimeType, InputStream data, long totalBytes)
public static Response newFixedLengthResponse(IStatus status, String mimeType, String txt)
public static Response newFixedLengthResponse(String msg)
public Response setUseGzip(boolean useGzip)
public boolean useGzipWhenAccepted()
Copyright © 2012–2020 nanohttpd. All rights reserved.