Copies the contents of the specified buffer into this buffer at the current position.
500630
public void write(ByteArrayBuffer buf) {
        data.copy(buf.data, 0, pointer, buf.length());
        pointer += buf.length();
    }
1180425
private static void copy(ByteBuffer dst, ByteBuffer src) {
    if (dst.hasRemaining() && src.hasRemaining()) {
      // Avoid an allocation if possible.
      if (dst.remaining() >= src.remaining()) {
        dst.put(src);
      } else {
        int count = Math.min(dst.remaining(), src.remaining());
        ByteBuffer slice = src.slice();
        slice.limit(count);
        dst.put(slice);
        src.position(src.position() + count);
      }
    }
  }
1268969
public static void copy(Reader in,
                            Writer out,
                            long byteCount)
         throws IOException
    {  
        char buffer[] = new char[bufferSize];
        int len=bufferSize;
        
        if (byteCount>=0)
        {
            while (byteCount>0)
            {
                if (byteCount<bufferSize)
                    len=in.read(buffer,0,(int)byteCount);
                else
                    len=in.read(buffer,0,bufferSize);                   
                
                if (len==-1)
                    break;
                
                byteCount -= len;
                out.write(buffer,0,len);
            }
        }
        else
        {
            while (true)
            {
                len=in.read(buffer,0,bufferSize);
                if (len==-1)
                    break;
                out.write(buffer,0,len);
            }
        }
    }
885796
public static ByteBuf copiedBuffer(ByteBuffer buffer) {
        int length = buffer.remaining();
        if (length == 0) {
            return EMPTY_BUFFER;
        }
        byte[] copy = PlatformDependent.allocateUninitializedArray(length);
        // Duplicate the buffer so we not adjust the position during our get operation.
        // See https://github.com/netty/netty/issues/3896
        ByteBuffer duplicate = buffer.duplicate();
        duplicate.get(copy);
        return wrappedBuffer(copy).order(duplicate.order());
    }
636508
public Buffer copyTo(OutputStream out, long offset, long byteCount) throws IOException {
    if (out == null) throw new IllegalArgumentException("out == null");
    checkOffsetAndCount(size, offset, byteCount);
    if (byteCount == 0) return this;

    // Skip segments that we aren't copying from.
    Segment s = head;
    for (; offset >= (s.limit - s.pos); s = s.next) {
      offset -= (s.limit - s.pos);
    }

    // Copy from one segment at a time.
    for (; byteCount > 0; s = s.next) {
      int pos = (int) (s.pos + offset);
      int toCopy = (int) Math.min(s.limit - pos, byteCount);
      out.write(s.data, pos, toCopy);
      byteCount -= toCopy;
      offset = 0;
    }

    return this;
  }
650308
private void copy() {
        if (elems.nonEmpty()) {
            List<A> orig = elems;

            elems = last = List.of(orig.head);

            while ((orig = orig.tail).nonEmpty()) {
                last.tail = List.of(orig.head);
                last = last.tail;
            }
        }
    }
245794
public void copyFromDirectBuffer(int bytesRead) {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "copyFromDirectBuffer: " + bytesRead);
        }

        int newPosition = this.oWsBBDirect.position();
        int cachePosition = this.oByteBuffer.position();

        if (this.quickBufferAction == NOT_ACTIVATED) {

            // copy the bytes read from the old position
            this.oWsBBDirect.position(cachePosition);

            if (bytesRead == -1) {
                // copy all the bytes up to the limit
                this.oWsBBDirect.get(oByteBuffer.array(), cachePosition + oByteBuffer.arrayOffset(), oByteBuffer.remaining());
            } else if (bytesRead > 0) {
                // copy just the bytes that were read
                this.oWsBBDirect.get(oByteBuffer.array(), cachePosition + oByteBuffer.arrayOffset(), bytesRead);
            }

            // set to the position
            this.oByteBuffer.position(newPosition);

        } else {
            synchronized (wsBBRoot.actionAccess) {
                if (wsBBRoot.actionState == PooledWsByteBufferImpl.COPY_WHEN_NEEDED_STATE1) {

                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "actionState: STATE1 - nothing will be copied");
                    }

                    // don't do the copy now, just update the position pointer
                    this.oByteBuffer.position(newPosition);

                    int min = cachePosition;
                    int max = newPosition - 1;

                    // in STATE1 readMin and readMax keep track of the data that will
                    // need to be moved up to the nonDirect buffer upon entering STATE2.
                    // This area can be expanded to contain some bytes which were not
                    // read into, since nothing has been put into the NonDirect buffer,
                    // so any gaps in the read data will be uninitialized data anyway.
                    if ((wsBBRoot.readMin == -1) || (min < wsBBRoot.readMin)) {
                        wsBBRoot.readMin = min;
                    }
                    if ((wsBBRoot.readMax == -1) || (max > wsBBRoot.readMax)) {
                        wsBBRoot.readMax = max;
                    }

                    // if getMin and getMax are not outside of the new read, then reset them,
                    // so that the next get(...) will pull up the new data.
                    if ((wsBBRoot.getMax >= wsBBRoot.readMin)
                        && (wsBBRoot.getMin <= wsBBRoot.readMax)) {

                        wsBBRoot.getMax = -1;
                        wsBBRoot.getMin = -1;
                    }

                } else {
                    // actionState must equal COPY_WHEN_NEEDED_STATE2 or
                    // BUFFER_MGMT_COPY_ALL_FINAL (if another thread just changed it).
                    //

                    if (wsBBRoot.actionState == PooledWsByteBufferImpl.COPY_WHEN_NEEDED_STATE2) {
                        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                            Tr.debug(tc, "actionState: STATE2, first copy up any previously read data");
                        }
                        // first copy up to the nonDirect buffer any data that was read before
                        // entering STATE 2
                        if ((wsBBRoot.readMin != -1) && (wsBBRoot.readMax != -1)) {
                            moveUpUsingGetMinMax(wsBBRoot.readMin, wsBBRoot.readMax, 0);
                        }
                    }

                    this.wsBBRoot.actionState = PooledWsByteBufferImpl.COPY_ALL_FINAL;
                    this.quickBufferAction = NOT_ACTIVATED;

                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "actionState: COPY_ALL_FINAL, copy currently read data to NonDirect buffer ");
                    }

                    // copy the bytes read from the old position
                    this.oWsBBDirect.position(cachePosition);

                    if (bytesRead == -1) {
                        // copy all the bytes up to the limit
                        this.oWsBBDirect.get(oByteBuffer.array(), cachePosition + oByteBuffer.arrayOffset(), oByteBuffer.remaining());
                    } else if (bytesRead > 0) {
                        // copy just the bytes that were read
                        this.oWsBBDirect.get(oByteBuffer.array(), cachePosition + oByteBuffer.arrayOffset(), bytesRead);
                    }

                    // set to the position
                    this.oByteBuffer.position(newPosition);

                }
            } // end-sync
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "copyFromDirectBuffer");
        }
    }
1225357
private void copy(InputStream is, OutputStream os) throws IOException {
		byte[] buffer = new byte[bufferSize];
		int nRead;
		while((nRead = is.read(buffer)) != -1) {
			os.write(buffer, 0, nRead);
		}
		os.flush();
	}
1154671
@Deprecated // replace with StreamUtil.copyContentIntoOutputStream()
    private static void copyStream(InputStream input, OutputStream output) throws IOException {
        byte[] buffer = new byte[BUFFER_SIZE];
        int len;
        while ((len = input.read(buffer)) != -1) {
            output.write(buffer, 0, len);
        }
    }
968441
public static void copy(Readable from, Appendable to) throws IOException {
     CharBuffer buf = CharBuffer.allocate(2048);
     for (;;) {
       int r = from.read(buf);
       if (r == -1) break;
       buf.flip();
       to.append(buf, 0, r);
     }
  }
445244
public void copyToDirectBuffer() {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.entry(tc, "copyToDirectBuffer");
        }

        if (oByteBuffer.isDirect()) {
            this.oWsBBDirect = this.oByteBuffer;
            if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
                Tr.exit(tc, "copyToDirectBuffer, exit point 1");
            }
            return;
        }

        if (this.quickBufferAction == ACTIVATED) {

            synchronized (wsBBRoot.actionAccess) {
                if (wsBBRoot.actionState == PooledWsByteBufferImpl.COPY_WHEN_NEEDED_STATE1) {

                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "bufferAction in STATE1, do not copy");
                    }

                    // no put activity has been done on the NonDirect Buffer, so
                    // the data in the Direct buffer can be written as is
                    this.oWsBBDirect.limit(oByteBuffer.limit());
                    this.oWsBBDirect.position(oByteBuffer.position());

                    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
                        Tr.exit(tc, "copyToDirectBuffer, exit point 2");
                    }
                    return;
                }

                if (wsBBRoot.actionState == PooledWsByteBufferImpl.COPY_WHEN_NEEDED_STATE2) {

                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
                        Tr.debug(tc, "bufferAction in STATE2, copy only changed data");
                    }

                    // put activity has been done on the NonDirect Buffer, so
                    // the new data in the nonDirect buffer needs to be copied
                    // down to the Direct Buffer
                    if ((wsBBRoot.putMin != -1) && (wsBBRoot.putMax != -1)) {

                        copyRangeToDirectBuffer(wsBBRoot.putMin, wsBBRoot.putMax);
                        wsBBRoot.putMin = -1;
                        wsBBRoot.putMax = -1;
                    }

                    this.oWsBBDirect.limit(oByteBuffer.limit());
                    this.oWsBBDirect.position(oByteBuffer.position());

                    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
                        Tr.exit(tc, "copyToDirectBuffer, exit point 3");
                    }
                    return;
                }
            } // end-sync
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "buffer optimization is off, copy all data");
        }

        // we are here because either Optimization was never on, or it just switched off.
        if (oWsBBDirect == null) {
            this.oWsBBDirect = ByteBuffer.allocateDirect(oByteBuffer.capacity());
        }

        int cachePosition = this.oByteBuffer.position();
        int cacheLimit = this.oByteBuffer.limit();
        int offset = this.oByteBuffer.arrayOffset();

        // set the position and limit for copying
        this.oWsBBDirect.limit(cacheLimit);
        this.oWsBBDirect.position(cachePosition);

        // copy the bytes from position to limit
        this.oWsBBDirect.put(oByteBuffer.array(), cachePosition + offset, cacheLimit - cachePosition);

        // reset the position
        this.oWsBBDirect.position(cachePosition);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) {
            Tr.exit(tc, "copyToDirectBuffer, exit point 4");
        }
    }
1238109
public void putByte(int pos, byte b) {
		adaptSize(pos + 1);
		ByteBuffer bb = getBuffer(pos);
		int i = pos % _bufferSize;
		bb.put(i, b);
	}
426568
public static void copy(InputStream in, OutputStream out, long byteCount) throws IOException {
        byte buffer[] = new byte[bufferSize];
        int len = bufferSize;

        if (byteCount >= 0) {
            while (byteCount > 0) {
                int max = byteCount < bufferSize ? (int) byteCount : bufferSize;
                len = in.read(buffer, 0, max);

                if (len == -1)
                    break;

                byteCount -= len;
                out.write(buffer, 0, len);
            }
        } else {
            while (true) {
                len = in.read(buffer, 0, bufferSize);
                if (len < 0)
                    break;
                out.write(buffer, 0, len);
            }
        }
    }
973450
public static void copyStream(final InputStream src, OutputStream dest) throws IOException {
        byte[] buffer = new byte[1024];
        int read;
        while ((read = src.read(buffer)) > -1) {
            dest.write(buffer, 0, read);
        }
        dest.flush();
    }
777881
@Override
	public SerializationResult copyToBufferBuilder(BufferBuilder targetBuffer) {
		targetBuffer.append(lengthBuffer);
		targetBuffer.append(dataBuffer);
		targetBuffer.commit();

		return getSerializationResult(targetBuffer);
	}
148937
public static void copy(InputStream input, OutputStream output, int bufferSize) throws IOException {
        int availableBytes = input.available();
        log.debug("copy - bufferSize: {} available: {}", bufferSize, availableBytes);
        byte[] buf = null;
        if (availableBytes > 0) {
            if (availableBytes >= bufferSize) {
                buf = new byte[bufferSize];
            } else {
                buf = new byte[availableBytes];
            }
            int bytesRead = input.read(buf);
            while (bytesRead != -1) {
                output.write(buf, 0, bytesRead);
                bytesRead = input.read(buf);
                log.trace("Bytes read: {}", bytesRead);
            }
            output.flush();
        } else {
            log.debug("Available is 0, attempting to read anyway");
            buf = new byte[bufferSize];
            int bytesRead = input.read(buf);
            while (bytesRead != -1) {
                output.write(buf, 0, bytesRead);
                bytesRead = input.read(buf);
                log.trace("Bytes read: {}", bytesRead);
            }
            output.flush();
        }
    }
1016776
public void setData(IoBuffer buffer) {
        if (noCopy) {
            log.trace("Using buffer reference");
            this.data = buffer;
        } else {
            // try the backing array first if it exists
            if (buffer.hasArray()) {
                log.trace("Buffer has backing array, making a copy");
                byte[] copy = new byte[buffer.limit()];
                buffer.mark();
                buffer.get(copy);
                buffer.reset();
                data = IoBuffer.wrap(copy);
            } else {
                log.trace("Buffer has no backing array, using ByteBuffer");
                // fallback to ByteBuffer
                data.put(buffer.buf()).flip();
            }
        }
    }