예제 #1
0
 @Override
 public void complete() {
   bufferPool.release(buffer);
   IStream stream = getStream();
   dataInfo.consume(size);
   flowControlStrategy.updateWindow(StandardSession.this, stream, -size);
   if (dataInfo.available() > 0) {
     // We have written a frame out of this DataInfo, but there is more to write.
     // We need to keep the correct ordering of frames, to avoid that another
     // DataInfo for the same stream is written before this one is finished.
     prepend(this);
     flush();
   } else {
     super.complete();
     stream.updateCloseState(dataInfo.isClose(), true);
     if (stream.isClosed()) removeStream(stream);
   }
 }
예제 #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);
    }
  }
예제 #3
0
 /**
  * Reads and consumes the content bytes of this {@link DataInfo} into the given byte array,
  * starting from index {@code offset} for {@code length} bytes.
  *
  * @param bytes the byte array to copy the bytes into
  * @param offset the offset of the byte array to start copying
  * @param length the number of bytes to copy
  * @return the number of bytes copied
  */
 public int consumeInto(byte[] bytes, int offset, int length) {
   int read = readInto(bytes, offset, length);
   consume(read);
   return read;
 }
예제 #4
0
 /**
  * Reads and consumes the content bytes of this {@link DataInfo} into the given {@link
  * ByteBuffer}.
  *
  * @param output the {@link ByteBuffer} to copy the bytes into
  * @return the number of bytes copied
  * @see #consume(int)
  */
 public int consumeInto(ByteBuffer output) {
   int read = readInto(output);
   consume(read);
   return read;
 }