Append bytes to a buffer.

@param to  Buffer is flush mode
@param b   bytes to append
@param off offset into byte
@param len length to append
@throws BufferOverflowException if unable to append buffer due to space limits
972969
public static void append(ByteBuffer to, byte[] b, int off, int len) throws BufferOverflowException {
        int pos = flipToFill(to);
        try {
            to.put(b, off, len);
        } finally {
            flipToFlush(to, pos);
        }
    }
846164
public synchronized void addBuffer(byte[] buf, int off, int len) {
		if (copyBuffers) {
			byte[] b = new byte[len];
			System.arraycopy(buf, off, b, 0, len);
			buf = b;
			off = 0;
		}
		buffers.add(new Triple<>(buf, Integer.valueOf(off), Integer.valueOf(len)));
		totalSize += len;
	}
440205
public void write(final int b)
	{
		buffer[pos] = (byte)b;
		size++;
		if(++pos == buffer.length) flushBuffer();
	}
1353045
public void append(final CharArrayBuffer b) {
        if (b == null) {
            return;
        }
        append(b.array,0, b.len);
    }
378047
@Override
    public void write(int b) throws IOException {
        byte[] bytes = new byte[1];
        bytes[0] = (byte) (b & 0xff);
        buffer = buffer + new String(bytes);

        if (buffer.endsWith("\n")) {
            buffer = buffer.substring(0, buffer.length() - 1);
            flush();
        }
    }
1120740
@Override
    public void write(int b) throws IOException {
        int newcount = count + 1;
        if (newcount > buf.length) {
            buf = Arrays.copyOf(buf, oversize(newcount));
        }
        buf[count] = (byte) b;
        count = newcount;
    }
1195813
public void write(byte[] b, int off, int len) throws IOException {
        out.write(b, off, len);
        cksum.update(b, off, len);
    }
451106
@Override
  public void write(byte []buffer, int offset, int length)
    throws IOException
  {
    while (length > 0) {
      if (_bufferEnd <= _offset) {
        flushBlock(false);
      }

      int sublen = Math.min(_bufferEnd - _offset, length);

      System.arraycopy(buffer, offset, _buffer, _offset, sublen);

      offset += sublen;
      _offset += sublen;

      length -= sublen;
    }
  }
1339289
public void write(byte b[], int off, int len)
        throws IOException
    {     
        len=prepareOutput(len);
        if (!_nulled)
            _out.write(b,off,len);
        if (_bytes==_contentLength)
            flush();
    }
1282777
public void putBytes(byte[] b, int boff, int len) {
        System.arraycopy(b, boff, _buffer, _offset, len);
        skip(len);
    }
102535
public void serializeToBuffer(ByteBuffer b) {
        assert(getSerializedSize() <= b.remaining());
        b.putInt(getSerializedSize() - 4);
        b.put((byte)getExceptionType().ordinal());
        if (m_message != null) {
            final byte messageBytes[] = m_message.getBytes();
            b.putInt(messageBytes.length);
            b.put(messageBytes);
        } else {
            b.putInt(0);
        }
        p_serializeToBuffer(b);
    }
1317762
public void append(Encoder encoder, EncodingState encodingState, char[] b, int off, int len) throws IOException {
        if (b == null || len <= 0) {
            return;
        }
        if (shouldEncode(encoder, encodingState)) {
            EncodingState newEncoders = createNewEncodingState(encoder, encodingState);
            if (encoder instanceof StreamingEncoder) {
                ((StreamingEncoder)encoder).encodeToStream(encoder, CharSequences.createCharSequence(b, off, len), 0, len, this,
                        newEncoders);
            }
            else {
                encodeAndWrite(encoder, newEncoders, String.valueOf(b, off, len));
            }
        }
        else {
            write(encodingState, b, off, len);
        }
    }
279901
public void appendByte(int b) {
        elems = ArrayUtils.ensureCapacity(elems, length);
        elems[length++] = (byte)b;
    }
677449
public void writeBytesEscaped(byte[] bytes, int len, boolean noBackslashEscapes)
      throws IOException {
    if (len * 2 > buf.length - pos) {

      //makes buffer bigger (up to 16M)
      if (buf.length != getMaxPacketLength()) {
        growBuffer(len * 2);
      }

      //data may be bigger than buffer.
      //must flush buffer when full (and reset position to 0)
      if (len * 2 > buf.length - pos) {

        if (mark != -1) {
          growBuffer(len * 2);
          if (mark != -1) {
            flushBufferStopAtMark();
          }

        } else {

          //not enough space in buffer, will fill buffer
          if (noBackslashEscapes) {
            for (int i = 0; i < len; i++) {
              if (QUOTE == bytes[i]) {
                buf[pos++] = QUOTE;
                if (buf.length <= pos) {
                  flushBuffer(false);
                }
              }
              buf[pos++] = bytes[i];
              if (buf.length <= pos) {
                flushBuffer(false);
              }
            }
          } else {
            for (int i = 0; i < len; i++) {
              if (bytes[i] == QUOTE
                  || bytes[i] == BACKSLASH
                  || bytes[i] == DBL_QUOTE
                  || bytes[i] == ZERO_BYTE) {
                buf[pos++] = '\\';
                if (buf.length <= pos) {
                  flushBuffer(false);
                }
              }
              buf[pos++] = bytes[i];
              if (buf.length <= pos) {
                flushBuffer(false);
              }
            }
          }
          return;
        }

      }
    }

    //sure to have enough place filling buffer directly
    if (noBackslashEscapes) {
      for (int i = 0; i < len; i++) {
        if (QUOTE == bytes[i]) {
          buf[pos++] = QUOTE;
        }
        buf[pos++] = bytes[i];
      }
    } else {
      for (int i = 0; i < len; i++) {
        if (bytes[i] == QUOTE
            || bytes[i] == BACKSLASH
            || bytes[i] == '"'
            || bytes[i] == ZERO_BYTE) {
          buf[pos++] = BACKSLASH; //add escape slash
        }
        buf[pos++] = bytes[i];
      }
    }

  }
1037503
private void append(byte[] data) {
    if (storage.position() + data.length >= storage.capacity()) {
      ByteBuffer tmp = ByteBuffer.allocate(storage.limit() + data.length * 2);
      byte[] tmpData = new byte[storage.position()];
      storage.flip();
      storage.get(tmpData);
      tmp.put(tmpData);
      storage = tmp;
      logger.warn("Increase storage size. Current size is {}", storage.array().length);
    }

    try {
      storage.put(data);
    }
    catch (BufferOverflowException boe) {
      logger.error("Buffer overflow occured", boe);
    }
    boolean messageReceived;
    do {
      messageReceived = seekMessage();
    } while (messageReceived);
  }
503728
public void add(final byte[] buf, final int offset, final int len) {
    segments.add(new BufferSegment(buf, offset, len));
    total_length += len;
  }
614314
protected void flushCacheWithAppend(byte[] bufferToAppend, int off, int len) throws IOException {
        byte[] chunkHeader = (Integer.toHexString(cachePosition + len) + "\r\n").getBytes(StandardCharsets.US_ASCII);
        stream.write(chunkHeader, 0, chunkHeader.length);
        stream.write(cache, 0, cachePosition);
        stream.write(bufferToAppend, off, len);
        stream.write(ENDCHUNK, 0, ENDCHUNK.length);
        cachePosition = 0;
    }