Copies into the given ByteBuffer.

@param toFill The ByteBuffer to fill into.
@return the number of bytes put into toFill
547009
public int read(ByteBuffer toFill) {
        int originalPos = toFill.position();
        while (dataAvailable() > 0 && toFill.hasRemaining()) {
            readHelper(toFill);
        }
        return toFill.position() - originalPos;
    }
1161118
protected int writeTo(SparseBufferOperator<B> op, Splitter<SparseBufferOperator<B>> splitter) throws IOException
    {
        return writeTo(op, splitter, mark, marked);
    }
835480
public static void copyFillableProperties(HasFill fillableOriginal, HasFill fillableCopy) {
		fillableCopy.setFillOpacity(fillableOriginal.getFillOpacity());
		fillableCopy.setFillColor(fillableOriginal.getFillColor());
	}
260597
public int fill(ByteBuffer bb) throws IOException
    {
        return fill((dsts, offset, length)->ByteBuffers.move(bb, dsts, offset, length), fillSplitter);
    }
224764
public static int copyWsByteBuffer(WsByteBuffer src, WsByteBuffer dst, int amount)
   {
      int amountCopied = amount;
      int dstRemaining = dst.remaining();
      int srcRemaining = src.remaining();

      if (amountCopied > dstRemaining) amountCopied = dstRemaining;
      if (amountCopied > srcRemaining) amountCopied = srcRemaining;

      if (amountCopied > 0)
      {
         int srcLimit = src.limit();
         src.limit(src.position()+amountCopied);
         dst.put(src);
         src.limit(srcLimit);
      }

      return amountCopied;
   }
1306059
@Override
	protected void serializeTo(RawDataBuffer out)
    {
        super.serializeTo(out);
    	out.writeByteArray(SerializationTools.toByteArray(error));
    }
568085
public static ByteBuffer allocate(int capacity) {
        ByteBuffer buf = ByteBuffer.allocate(capacity);
        buf.limit(0);
        return buf;
    }
1072747
public void write(int b) {
        int newcount = count + 1;
        if (newcount > buffer.length) buffer = copyOf(buffer, Math.max(buffer.length << 1, newcount));
        buffer[count] = (byte) b;
        count = newcount;
    }
973096
@Override
  public int write(ByteBuffer src) {
    int toTransfer = Math.min(src.remaining(), data.length - offset);
    src.get(data, offset, toTransfer);
    offset += toTransfer;
    return toTransfer;
  }
399802
public ByteBuffer toThrift() {
    Buffer buffer = Buffer.allocate(sizeInBytes());
    write(buffer);
    return ByteBuffer.wrap(buffer.toByteArray());
  }
666317
public static int copyAllBytes(InputStream in, OutputStream out) throws IOException {
        int byteCount = 0;
        byte[] buffer = new byte[BUFFER_SIZE];
        while (true) {
            int read = in.read(buffer);
            if (read == -1) {
                break;
            }
            out.write(buffer, 0, read);
            byteCount += read;
        }
        return byteCount;
    }
243756
public static <T> T toUnpooled(T o) {
        if (o instanceof ByteBufHolder) {
            o = copyAndRelease((ByteBufHolder) o);
        } else if (o instanceof ByteBuf) {
            o = copyAndRelease((ByteBuf) o);
        }
        return o;
    }
462084
@SuppressWarnings("unchecked")
    public final T duplicate() {
        if (backing instanceof ByteBuffer) {
            return (T) ((ByteBuffer) backing).duplicate();
        }
        if (backing instanceof CharBuffer) {
            return (T) ((CharBuffer) backing).duplicate();
        }
        throw new IllegalArgumentException("Backing buffer of unknown type.");
    }
1141209
public boolean fillIfLive(long timeout)
    throws IOException
  {
    StreamImpl source = _source;
    byte []readBuffer = _readBuffer;

    if (readBuffer == null || source == null) {
      _readOffset = 0;
      _readLength = 0;
      return false;
    }

    if (_readOffset > 0) {
      System.arraycopy(readBuffer, _readOffset, readBuffer, 0,
                       _readLength - _readOffset);
      _readLength -= _readOffset;
      _readOffset = 0;
    }

    if (_readLength == readBuffer.length)
      return true;

    int readLength
      = source.readTimeout(_readBuffer, _readLength,
                           _readBuffer.length - _readLength, timeout);

    if (readLength >= 0) {
      _readLength += readLength;
      _position += readLength;

      if (_isEnableReadTime)
        _readTime = CurrentTime.currentTime();
      return true;
    }
    else if (readLength == READ_TIMEOUT) {
      // timeout

      return true;
    }
    else {
      // return false on end of file

      return false;
    }
  }
143054
public static ByteBuffer copyBuffer(final ByteBuffer buf) {
        if(buf == null)
            return null;
        int offset=buf.hasArray()? buf.arrayOffset() + buf.position() : buf.position(), len=buf.remaining();
        byte[] tmp=new byte[len];
        if(!buf.isDirect())
            System.arraycopy(buf.array(), offset, tmp, 0, len);
        else {
         //   buf.get(tmp, 0, len);
            for(int i=0; i < len; i++)
                tmp[i]=buf.get(i+offset);
        }
        return ByteBuffer.wrap(tmp);
    }
968980
public final void copyTo(AbstractCoalescingBufferQueue dest) {
        dest.bufAndListenerPairs.addAll(bufAndListenerPairs);
        dest.incrementReadableBytes(readableBytes);
    }
1077089
public static int copyWriterCount(final Reader in, final Writer out) throws IOException {
        final char[] buffer = new char[10240];
        int tot=0;
        int c;
        c = in.read(buffer);
        while (c >= 0) {
            if (c > 0) {
                out.write(buffer, 0, c);
                tot += c;
            }
            c = in.read(buffer);
        }
        return tot;
    }