private class ReportProtocol.ResponseWriter
extends java.io.Writer
BufferedWriter
to stream the JSON to the enpoint in chunks. This prevents huge JSON strings from being
created that would consume too much memory.Modifier and Type | Field and Description |
---|---|
private org.eclipse.jetty.websocket.api.RemoteEndpoint |
endpoint
Remote endpoint to which JSON is streamed as it is generated
|
private java.lang.String |
pending
Next string or partial string of JSON output to be written to the remote endpoint
|
Constructor and Description |
---|
ResponseWriter(org.eclipse.jetty.websocket.api.RemoteEndpoint endpoint)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Send any pending response as the last in the series.
|
void |
flush()
No-op.
|
private void |
sendPendingResponse(boolean isLast)
Send the pending response, if any, to the remote endpoint.
|
void |
write(char[] buf,
int off,
int len)
Write method invoked when the next string or partial string of JSON output has been
generated.
|
private final org.eclipse.jetty.websocket.api.RemoteEndpoint endpoint
private java.lang.String pending
ResponseWriter(org.eclipse.jetty.websocket.api.RemoteEndpoint endpoint)
endpoint
- Remote endpoint to which JSON is streamed as it is generated.public void write(char[] buf, int off, int len) throws java.io.IOException
pending
field, to be sent on the next
call to this method or when the writer is closed.
We don't send the current buffer's contents immediately, because we don't yet know whether the current chunk is the last one to be sent. The jetty API to send partial strings to the remote endpoint needs to be told whether the string being sent is the last one in a series. We only know this when this method is called with a 0-length string or upon the writer being closed.
write
in class java.io.Writer
java.io.IOException
- if there is an error writing the pending response data to the endpoint.public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class java.io.Writer
java.io.IOException
- never.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.Writer
java.io.IOException
- if there is an error writing the pending response data to the endpoint.private void sendPendingResponse(boolean isLast) throws java.io.IOException
isLast
- true
if the response to be sent is the last in the series;
false
if additional reponses are expected after this one.java.io.IOException
- if there is an error writing the pending response data to the endpoint.