@Override
    public void data(DataInfo dataInfo, Callback handler) {
      try {
        // Data buffer must be copied, as the ByteBuffer is pooled
        ByteBuffer byteBuffer = dataInfo.asByteBuffer(false);

        send(null, byteBuffer, dataInfo.isClose());

        if (dataInfo.isClose()) completed();

        handler.succeeded();
      } catch (IOException x) {
        handler.failed(x);
      }
    }
Ejemplo n.º 2
0
  @Override
  public void onData(Stream stream, DataInfo dataInfo) {
    HttpExchange exchange = getHttpExchange();
    if (exchange == null) return;

    try {
      int length = dataInfo.length();
      // TODO: avoid data copy here
      boolean process = responseContent(exchange, dataInfo.asByteBuffer(false));
      dataInfo.consume(length);

      if (process) {
        if (dataInfo.isClose()) {
          responseSuccess(exchange);
        }
      }
    } catch (Exception x) {
      responseFailure(x);
    }
  }