Package io.netty.buffer

Examples of io.netty.buffer.ByteBuf.writableBytes()


  /** Serializes the 'type' byte followed by the message itself. */
  public byte[] toByteArray() {
    ByteBuf buf = Unpooled.buffer(encodedLength());
    buf.writeByte(type().id);
    encode(buf);
    assert buf.writableBytes() == 0 : "Writable bytes remain: " + buf.writableBytes();
    return buf.array();
  }
}
View Full Code Here


  /** Serializes the 'type' byte followed by the message itself. */
  public byte[] toByteArray() {
    ByteBuf buf = Unpooled.buffer(encodedLength());
    buf.writeByte(type().id);
    encode(buf);
    assert buf.writableBytes() == 0 : "Writable bytes remain: " + buf.writableBytes();
    return buf.array();
  }
}
View Full Code Here

    long frameLength = headerLength + bodyLength;
    ByteBuf header = ctx.alloc().heapBuffer(headerLength);
    header.writeLong(frameLength);
    msgType.encode(header);
    in.encode(header);
    assert header.writableBytes() == 0;

    out.add(header);
    if (body != null && bodyLength > 0) {
      out.add(body);
    }
View Full Code Here

    int i = findIndex(index);
    while (length > 0) {
      Component c = components.get(i);
      ByteBuf s = c.buf;
      int adjustment = c.offset;
      int localLength = Math.min(length, s.writableBytes());
      s.setBytes(index - adjustment, src, srcIndex, localLength);
      index += localLength;
      srcIndex += localLength;
      length -= localLength;
      i++;
View Full Code Here

    int i = findIndex(index);
    while (length > 0) {
      Component c = components.get(i);
      ByteBuf s = c.buf;
      int adjustment = c.offset;
      int localLength = Math.min(length, s.writableBytes());
      s.setBytes(index - adjustment, src, srcIndex, localLength);
      index += localLength;
      srcIndex += localLength;
      length -= localLength;
      i++;
View Full Code Here

    try {
      while (length > 0) {
        Component c = components.get(i);
        ByteBuf s = c.buf;
        int adjustment = c.offset;
        int localLength = Math.min(length, s.writableBytes());
        src.limit(src.position() + localLength);
        s.setBytes(index - adjustment, src);
        index += localLength;
        length -= localLength;
        i++;
View Full Code Here

    do {
      Component c = components.get(i);
      ByteBuf s = c.buf;
      int adjustment = c.offset;
      int localLength = Math.min(length, s.writableBytes());
      int localReadBytes = s
          .setBytes(index - adjustment, in, localLength);
      if (localReadBytes < 0) {
        if (readBytes == 0) {
          return -1;
View Full Code Here

    int readBytes = 0;
    do {
      Component c = components.get(i);
      ByteBuf s = c.buf;
      int adjustment = c.offset;
      int localLength = Math.min(length, s.writableBytes());
      int localReadBytes = s
          .setBytes(index - adjustment, in, localLength);

      if (localReadBytes == 0) {
        break;
View Full Code Here

                    byte byteData = data.getByte(i);
                    buf.writeByte(byteData ^ mask[counter++ % 4]);
                }
                out.add(buf);
            } else {
                if (buf.writableBytes() >= data.readableBytes()) {
                    // merge buffers as this is cheaper then a gathering write if the payload is small enough
                    buf.writeBytes(data);
                    out.add(buf);
                } else {
                    out.add(buf);
View Full Code Here

            }

            final long contentLength = contentLength(msg);
            if (state == ST_CONTENT_NON_CHUNK) {
                if (contentLength > 0) {
                    if (buf != null && buf.writableBytes() >= contentLength && msg instanceof HttpContent) {
                        // merge into other buffer for performance reasons
                        buf.writeBytes(((HttpContent) msg).content());
                        out.add(buf);
                    } else {
                        if (buf != null) {
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.