Add a segment to the buffer list.

@param buf byte array
@param offset offset into buf
@param len length of segment, starting at offset
503728
public void add(final byte[] buf, final int offset, final int len) {
    segments.add(new BufferSegment(buf, offset, len));
    total_length += len;
  }
764247
@Override
    public void write(String str, int off, int len) {
        buf.append(str, off, off + len);
    }
1048247
public static void setBytes(long address, byte[] buffer, int bufferOffset, int count)
    {
        assert buffer != null;
        assert !(bufferOffset < 0 || count < 0 || bufferOffset + count > buffer.length);
        setBytes(buffer, bufferOffset, address, count);
    }
739773
@Override
  public void writePart(byte []buffer, int offset, int length)
  {
    write(buffer, offset, length, false);
  }
28612
@Override
  public void write(byte []buf, int offset, int length, boolean isEnd)
    throws IOException
  {
    while (length > 0) {
      if (_tail == null) {
        addBuffer(TempBuffer.create());
      }
      else if (_tail.buffer().length <= _tail.length()) {
        addBuffer(TempBuffer.create());
      }
      
      TempBuffer tail = _tail;

      int sublen = Math.min(length, tail.buffer().length - tail.length());

      System.arraycopy(buf, offset, tail.buffer(), tail.length(), sublen);

      length -= sublen;
      offset += sublen;
      _tail.length(_tail.length() + sublen);
    }
  }
394005
public void write(byte[] buffer, int offset, int length)
        throws IOException
    {
        OutputStream os = getOutputStream();

        for (; length > 0x8000; length -= 0x8000) {
            os.write('D');
            os.write(0x80);
            os.write(0x00);
            os.write(buffer, offset, 0x8000);

            offset += 0x8000;
        }

        os.write('D');
        os.write(length >> 8);
        os.write(length);
        os.write(buffer, offset, length);
    }
119043
private static int get(byte[] block, int offset, ByteBuffer buf, int len) {
    buf.put(block, offset, len);
    return len;
  }
44659
public static void append(StringBuffer buf,byte b,int base)
    {
        int bi=0xff&b;
        int c='0'+(bi/base)%base;
        if (c>'9')
            c= 'a'+(c-'0'-10);
        buf.append((char)c);
        c='0'+bi%base;
        if (c>'9')
            c= 'a'+(c-'0'-10);
        buf.append((char)c);
    }
500630
public void write(ByteArrayBuffer buf) {
        data.copy(buf.data, 0, pointer, buf.length());
        pointer += buf.length();
    }
186446
public void update(byte[] buf, int off, int len) {
        int c = ~crc;
        while (--len >= 0)
            c = crc_table[(c ^ buf[off++]) & 0xff] ^ (c >>> 8);
        crc = ~c;
    }
617494
public void write(io.netty.buffer.ByteBuf buf, int off, int len) throws IOException {
    if (len == 0) {
      return;
    }

    while (len > 0) {
      updateCurrentChunk(false);
      int toWrite = Math.min(len, mCurrentChunk.writableBytes());
      mCurrentChunk.writeBytes(buf, off, toWrite);
      off += toWrite;
      len -= toWrite;
    }
    updateCurrentChunk(false);
  }
1280484
protected void addBuffer() {
        if (buffers == null) {
            buffers = new LinkedList<byte[]>();
        }

        buffers.addLast(buffer);

        buffer = new byte[blockSize];
        size += index;
        index = 0;
    }
1161512
public void write(ByteBuffer buffer, int len) {
        if (len < 1) return;
        if (count >= content.length - len) {
            byte[] ns = new byte[content.length + len];
            System.arraycopy(content, 0, ns, 0, count);
            this.content = ns;
        }
        buffer.get(content, count, len);
        count += len;
    }
1349720
@Override
	public void write(byte[] buffer, int offset, int len) throws IOException {
		this.out.write(buffer, offset, len);
	}
778232
@Override
  public synchronized int read(byte[] buf, int offset, int length) throws IOException {
    if (buf == null) {
      throw new IllegalArgumentException("buf must not be null");
    }

    if (!(offset >= 0 && length > 0 && offset < buf.length && length <= (buf.length - offset))) {
      throw new IllegalArgumentException("invalid offset and lengeth");
    }

    // Return early if closed is true; throw the saved exception if needed.
    if (closed) {
      if (exception != null) {
        throw exception;
      }
      return -1;
    }

    // Check if there is already a chunk that hasn't been exhausted; call take() if not.
    if (currentChunk == null) {
      if (currentChunkReadPos != -1) {
        throw new IllegalStateException("currentChunk is null but currentChunkReadPos is not -1");
      }

      byte[] next = null;
      try {
        if (timeoutMillis >= 0) {
          next = queue.poll(timeoutMillis, TimeUnit.MILLISECONDS);
        } else {
          next = queue.take();
        }
      } catch (InterruptedException e) {
        // Unlikely to happen.
        throw new AssertionError(e);
      }
      if (next == null) {
        closed = true;
        SocketTimeoutException timeoutException = new SocketTimeoutException();

        if (exception == null) {
          exception = timeoutException;
          // It is still possible that an endOffer(Exception) races and set exception at this point,
          // but timeoutException is still being thrown, and it's ok for subsequent reads to
          // throw the exception set by endOffer(Exception).
        }

        throw timeoutException;
      }

      // If it's the end marker, acknowledge that so that the buffer will mark itself as closed
      // for reading.
      if (next == CLOSED) {
        closed = true;
        if (exception != null) {
          throw exception;
        }
        return -1;
      }
      currentChunk = next;
      currentChunkReadPos = 0;
    }

    int available = currentChunk.length - currentChunkReadPos;
    if (length < available) {
      // Copy from the currentChunk.
      System.arraycopy(currentChunk, currentChunkReadPos, buf, offset, length);
      currentChunkReadPos += length;
      return length;
    } else {
      // Copy the entire currentChunk.
      System.arraycopy(currentChunk, currentChunkReadPos, buf, offset, available);
      currentChunk = null;
      currentChunkReadPos = -1;
      return available;
    }
  }
1010270
private void initializeBufferQueue(int segmentFileSizeMB) {
        int bufferLength = 
            (segmentFileSizeMB < Segment.maxSegmentFileSizeMB) ?
            (segmentFileSizeMB * 1024 * 1024) : Integer.MAX_VALUE;
            
        lazyCount = 3;
        for (int i = 0; i < lazyCount; i++) {
            ByteBuffer buffer = ByteBuffer.wrap(new byte[bufferLength]);
            _bufferQueue.add(buffer);
        }
    }
106927
public void writeBytes(byte value, int len) throws IOException {
    if (len > buf.length - pos) {
      //not enough space remaining
      byte[] arr = new byte[len];
      Arrays.fill(arr, value);
      write(arr, 0, len);
      return;
    }

    for (int i = pos; i < pos + len; i++) {
      buf[i] = value;
    }
    pos += len;
  }