public abstract class AbstractServerHttpExchange extends Object implements ServerHttpExchange
ServerHttpExchange.| Modifier and Type | Field and Description |
|---|---|
protected Actions<Void> |
closeActions |
protected Actions<Void> |
endActions |
protected Actions<Throwable> |
errorActions |
| Constructor and Description |
|---|
AbstractServerHttpExchange() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract void |
doEnd() |
protected abstract void |
doRead(Action<ByteBuffer> chunkAction) |
protected abstract void |
doSetHeader(String name,
String value) |
protected abstract void |
doSetStatus(HttpStatus status) |
protected abstract void |
doWrite(ByteBuffer byteBuffer) |
ServerHttpExchange |
end()
Completes the response.
|
ServerHttpExchange |
end(ByteBuffer data)
Writes a binary chunk to the response body and completes the response
through
ServerHttpExchange.end(). |
ServerHttpExchange |
end(String data)
Writes a text chunk to the response body using the charset from the
response header,
content-type and completes the response through
ServerHttpExchange.end(). |
ServerHttpExchange |
end(String data,
String charsetName)
Writes a text chunk to the response body using the given charset and
completes the response through
ServerHttpExchange.end(). |
String |
header(String name)
Returns the first request header associated with the given name.
|
ServerHttpExchange |
onbody(Action action)
Attaches an action to be called with the whole request body.
|
ServerHttpExchange |
onchunk(Action action)
Attaches an action to be called with a chunk from the request body.
|
ServerHttpExchange |
onclose(Action<Void> action)
Attaches an action when the underlying connection is aborted for some
reason like an error.
|
ServerHttpExchange |
onend(Action<Void> action)
Attaches an action to be called when the request is fully read.
|
ServerHttpExchange |
onerror(Action<Throwable> action)
Attaches an action to be called when this exchange gets an error.
|
ServerHttpExchange |
onfinish(Action<Void> action)
Attaches an action to be called when the response is fully written.
|
ServerHttpExchange |
read()
Reads the request body.
|
ServerHttpExchange |
readAsBinary()
Reads the request body as binary.
|
ServerHttpExchange |
readAsText()
Reads the request body as text.
|
ServerHttpExchange |
readAsText(String charsetName)
Reads the request body as text using the given charset.
|
ServerHttpExchange |
setHeader(String name,
Iterable<String> value)
Sets response headers.
|
ServerHttpExchange |
setHeader(String name,
String value)
Sets a response header.
|
ServerHttpExchange |
setStatus(HttpStatus status)
Sets the HTTP status for the response.
|
ServerHttpExchange |
write(ByteBuffer byteBuffer)
Writes a binary chunk to the response body.
|
ServerHttpExchange |
write(String data)
Writes a text chunk to the response body using the charset from the
response header,
content-type. |
ServerHttpExchange |
write(String data,
String charsetName)
Writes a text chunk to the response body using the given charset.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitheaderNames, headers, method, unwrap, uripublic String header(String name)
ServerHttpExchangeheader in interface ServerHttpExchangepublic ServerHttpExchange read()
ServerHttpExchangecontent-type,
starts with text/, the body is read as text, and if not, as
binary. In case of text body, the charset is also determined by the same
header. If it's not given, ISO-8859-1 is used by default.
The read data will be passed to event handlers as String if it's
text and ByteBuffer if it's binary attached through
ServerHttpExchange.onchunk(Action).
This method should be called after adding
ServerHttpExchange.onchunk(Action),
ServerHttpExchange.onbody(Action), and
ServerHttpExchange.onend(Action) and has no side effect if called
more than once.read in interface ServerHttpExchangepublic ServerHttpExchange readAsText()
ServerHttpExchangecontent-type. If it's not given, ISO-8859-1 is
used by default.
The read data will be passed to event handlers as String attached
through ServerHttpExchange.onchunk(Action).
This method should be called after adding
ServerHttpExchange.onchunk(Action),
ServerHttpExchange.onbody(Action), and
ServerHttpExchange.onend(Action) and has no side effect if called
more than once.readAsText in interface ServerHttpExchangepublic ServerHttpExchange readAsText(String charsetName)
ServerHttpExchangeString attached
through ServerHttpExchange.onchunk(Action).
This method should be called after adding
ServerHttpExchange.onchunk(Action),
ServerHttpExchange.onbody(Action), and
ServerHttpExchange.onend(Action) and has no side effect if called
more than once.readAsText in interface ServerHttpExchangepublic ServerHttpExchange readAsBinary()
ServerHttpExchangeByteBuffer
attached through ServerHttpExchange.onchunk(Action).
This method should be called after adding
ServerHttpExchange.onchunk(Action),
ServerHttpExchange.onbody(Action), and
ServerHttpExchange.onend(Action) and has no side effect if called
more than once.readAsBinary in interface ServerHttpExchangeprotected abstract void doRead(Action<ByteBuffer> chunkAction)
public ServerHttpExchange onchunk(Action action)
ServerHttpExchangeString for text body and ByteBuffer
for binary body.onchunk in interface ServerHttpExchangepublic ServerHttpExchange onend(Action<Void> action)
ServerHttpExchangeonend in interface ServerHttpExchangepublic ServerHttpExchange onbody(Action action)
ServerHttpExchangeString for text body and ByteBuffer for
binary body. If the body is quite big, it may drain memory quickly. If
that's the case, use ServerHttpExchange.onchunk(Action) and
ServerHttpExchange.onend(Action).onbody in interface ServerHttpExchangepublic ServerHttpExchange setStatus(HttpStatus status)
ServerHttpExchangesetStatus in interface ServerHttpExchangeprotected abstract void doSetStatus(HttpStatus status)
public final ServerHttpExchange setHeader(String name, Iterable<String> value)
ServerHttpExchangesetHeader in interface ServerHttpExchangepublic ServerHttpExchange setHeader(String name, String value)
ServerHttpExchangesetHeader in interface ServerHttpExchangepublic ServerHttpExchange write(String data)
ServerHttpExchangecontent-type. If it's not given,
ISO-8859-1 is used.write in interface ServerHttpExchangepublic ServerHttpExchange write(String data, String charsetName)
ServerHttpExchangewrite in interface ServerHttpExchangepublic ServerHttpExchange write(ByteBuffer byteBuffer)
ServerHttpExchangewrite in interface ServerHttpExchangeprotected abstract void doWrite(ByteBuffer byteBuffer)
public ServerHttpExchange end()
ServerHttpExchangeend in interface ServerHttpExchangeprotected abstract void doEnd()
public ServerHttpExchange end(String data)
ServerHttpExchangecontent-type and completes the response through
ServerHttpExchange.end().end in interface ServerHttpExchangepublic ServerHttpExchange end(String data, String charsetName)
ServerHttpExchangeServerHttpExchange.end().end in interface ServerHttpExchangepublic ServerHttpExchange end(ByteBuffer data)
ServerHttpExchangeServerHttpExchange.end().end in interface ServerHttpExchangepublic ServerHttpExchange onfinish(Action<Void> action)
ServerHttpExchangeonfinish in interface ServerHttpExchangepublic ServerHttpExchange onclose(Action<Void> action)
ServerHttpExchangeonclose in interface ServerHttpExchangepublic ServerHttpExchange onerror(Action<Throwable> action)
ServerHttpExchangeonerror in interface ServerHttpExchangeCopyright © 2015–2018. All rights reserved.