return rootFuture.finishOrThrowException();
}
public void webSocketWrite(Request request, Object object, Object data) throws IOException {
WebSocketTransport webSocketTransport = WebSocketTransport.class.cast(transport);
if (InputStream.class.isAssignableFrom(object.getClass())) {
InputStream is = (InputStream) object;
ByteArrayOutputStream bs = new ByteArrayOutputStream();
//TODO: We need to stream directly, in AHC!
byte[] buffer = new byte[8192];
int n = 0;
while (-1 != (n = is.read(buffer))) {
bs.write(buffer, 0, n);
}
webSocketTransport.sendMessage(bs.toByteArray());
} else if (Reader.class.isAssignableFrom(object.getClass())) {
Reader is = (Reader) object;
StringWriter bs = new StringWriter();
//TODO: We need to stream directly, in AHC!
char[] chars = new char[8192];
int n = 0;
while (-1 != (n = is.read(chars))) {
bs.write(chars, 0, n);
}
webSocketTransport.sendMessage(bs.getBuffer().toString());
} else if (String.class.isAssignableFrom(object.getClass())) {
webSocketTransport.sendMessage(object.toString());
} else if (byte[].class.isAssignableFrom(object.getClass())) {
webSocketTransport.sendMessage((byte[]) object);
} else {
throw new IllegalStateException("No Encoder for " + data);
}
}