Copy the contents of this buffer begginning from the srcOffset to a destination byte array
@param srcOffset
@param destArray
@param destOffset
@param size
431113
public void copyTo(int srcOffset, byte[] destArray, int destOffset, int size) {
        int cursor = destOffset;
        for (ByteBuffer bb : toDirectByteBuffers(srcOffset, size)) {
            int bbSize = bb.remaining();
            if ((cursor + bbSize) > destArray.length)
                throw new ArrayIndexOutOfBoundsException(String.format("cursor + bbSize = %,d", cursor + bbSize));
            bb.get(destArray, cursor, bbSize);
            cursor += bbSize;
        }
    }
988683
public static int putBytes(byte[] tgtBytes, int tgtOffset, byte[] srcBytes,
      int srcOffset, int srcLength) {
    System.arraycopy(srcBytes, srcOffset, tgtBytes, tgtOffset, srcLength);
    return tgtOffset + srcLength;
  }
855697
private void transfer(Entry[] src, Entry[] dest)
    {
        for (int j = 0; j < src.length; ++j)
        {
            Entry e = src[j];
            src[j] = null;
            while (e != null)
            {
                Entry next = e.getState().next;
                Object key = e.get();
                if (key == null)
                {
                    e.setNext(null);  // Help GC
                    size--;
                }
                else
                {
                    int i = indexFor(e.getHash(), dest.length);
                    e.setNext(dest[i]);
                    dest[i] = e;
                }
                e = next;
            }
        }
    }
1328705
private void expandIfNecessary(int size) {
    if (bytes.length >= size) {
      // no need to expand
      return;
    }
    // either double, or expand to fit size
    int newlength = Math.max(2 * bytes.length, size);
    bytes = Arrays.copyOf(bytes, newlength);
  }
559818
private byte[] shrinkBuffer(byte[] buffer, int size)
    {
        if (size == 0) {
            return null;
        }

        if (size == buffer.length) {
            return buffer;
        }

        byte[] output = new byte[size];
        System.arraycopy(buffer, 0, output, 0, size);
        return output;
    }
430023
protected static byte[] getDataCopy(byte[] data, int size) {
        if (data == null) {
            return NO_DATA;
        }
        byte[] newData = new byte[size];
        System.arraycopy(data, 0, newData, 0, size);
        return newData;
    }
1215582
public static void copy(File source, File dest) throws IOException {
        if (dest.isDirectory()) {
            dest = new File(dest + File.separator + source.getName());
        }

        FileChannel in = null, out = null;
        try {
            in = new FileInputStream(source).getChannel();
            out = new FileOutputStream(dest).getChannel();

            long size = in.size();
            MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);

            out.write(buf);
        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        }
    }
1186341
public static void copyFile(File src, File dest) throws IOException {

        if (src == null)
            throw new NullPointerException("Source must not be null");
        if (dest == null)
            throw new NullPointerException("Destination must not be null");
        if (!src.exists())
            throw new FileNotFoundException("Source '" + src + "' does not exist");
        if (!src.isFile())
            throw new IOException("Source '" + src + "' is not a file");
        if (dest.exists())
            throw new IOException("Destination '" + dest + "' is already exists");

        FileChannel in = null, out = null;
        try {
            in = new FileInputStream(src).getChannel();
            out = new FileOutputStream(dest).getChannel();

            in.transferTo(0, in.size(), out);
        } finally {
            try {
                in.close();
                out.close();
            } catch (IOException e) {
                // Ignore.
            }
        }

        if (src.length() != dest.length()) {
            throw new IOException("Failed to copy full contents from '" +
                src + "' to '" + dest + "'");
        }

        dest.setLastModified(src.lastModified());
    }
1250106
public static byte decodeByteDesc(byte[] src, int srcOffset)
        throws CorruptEncodingException
    {
        try {
            return (byte)(src[srcOffset] ^ 0x7f);
        } catch (IndexOutOfBoundsException e) {
            throw new CorruptEncodingException(null, e);
        }
    }
148258
public static Object copy(Object src, int srcPos, Object dest, int destPos, int length) {
		System.arraycopy(src, srcPos, dest, destPos, length);
		return dest;
	}
449872
static public void copyStream(Reader reader, Writer writer, int transferBufferSize) throws IOException {
		if( transferBufferSize < 1 ) {
			throw new IOException("Transfer buffer size can not be smaller than 1");
		}

		char[] buffer = new char[transferBufferSize];

		int bytesRead = reader.read(buffer);
		while( bytesRead >= 0 ) {
			writer.write(buffer, 0, bytesRead);

			bytesRead = reader.read(buffer);
		}
	}
173669
private void setAndAllocateBuffer(int sizeToAllocate) {
        
        if(_buffer == null){
            if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){
                Tr.debug(tc, "setAndAllocateBuffer, Buffer is null, size to allocate is : " + sizeToAllocate);
            }
            _buffer = allocateBuffer(sizeToAllocate);
        }
        
        configurePreReadBuffer(sizeToAllocate);
        
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()){  
          Tr.debug(tc, "setAndAllocateBuffer, Setting the buffer : " + _buffer );         
        }
        
        _tcpContext.getReadInterface().setBuffer(_buffer);
    }
940366
public static void writeToMemory(byte[] src, Object target, long targetOffset) {
    Platform.copyMemory(src, Platform.BYTE_ARRAY_OFFSET, target, targetOffset, src.length);
  }
894608
public byte[] readRawBytes(final int size) throws IOException
    {
        if (size < 0)
        {
            throw ProtobufException.negativeSize();
        }

        if (totalBytesRetired + bufferPos + size > currentLimit)
        {
            // Read to the end of the stream anyway.
            skipRawBytes(currentLimit - totalBytesRetired - bufferPos);
            // Then fail.
            throw ProtobufException.truncatedMessage();
        }

        if (size <= bufferSize - bufferPos)
        {
            // We have all the bytes we need already.
            final byte[] bytes = new byte[size];
            System.arraycopy(buffer, bufferPos, bytes, 0, size);
            bufferPos += size;
            return bytes;
        }
        else if (size < buffer.length)
        {
            // Reading more bytes than are in the buffer, but not an excessive number
            // of bytes. We can safely allocate the resulting array ahead of time.

            // First copy what we have.
            final byte[] bytes = new byte[size];
            int pos = bufferSize - bufferPos;
            System.arraycopy(buffer, bufferPos, bytes, 0, pos);
            bufferPos = bufferSize;

            // We want to use refillBuffer() and then copy from the buffer into our
            // byte array rather than reading directly into our byte array because
            // the input may be unbuffered.
            refillBuffer(true);

            while (size - pos > bufferSize)
            {
                System.arraycopy(buffer, 0, bytes, pos, bufferSize);
                pos += bufferSize;
                bufferPos = bufferSize;
                refillBuffer(true);
            }

            System.arraycopy(buffer, 0, bytes, pos, size - pos);
            bufferPos = size - pos;

            return bytes;
        }
        else
        {
            // The size is very large. For security reasons, we can't allocate the
            // entire byte array yet. The size comes directly from the input, so a
            // maliciously-crafted message could provide a bogus very large size in
            // order to trick the app into allocating a lot of memory. We avoid this
            // by allocating and reading only a small chunk at a time, so that the
            // malicious message must actually *be* extremely large to cause
            // problems. Meanwhile, we limit the allowed size of a message elsewhere.

            // Remember the buffer markers since we'll have to copy the bytes out of
            // it later.
            final int originalBufferPos = bufferPos;
            final int originalBufferSize = bufferSize;

            // Mark the current buffer consumed.
            totalBytesRetired += bufferSize;
            bufferPos = 0;
            bufferSize = 0;

            // Read all the rest of the bytes we need.
            int sizeLeft = size - (originalBufferSize - originalBufferPos);
            final List<byte[]> chunks = new ArrayList<byte[]>();

            while (sizeLeft > 0)
            {
                final byte[] chunk = new byte[Math.min(sizeLeft, buffer.length)];
                int pos = 0;
                while (pos < chunk.length)
                {
                    final int n = (input == null) ? -1 :
                            input.read(chunk, pos, chunk.length - pos);
                    if (n == -1)
                    {
                        throw ProtobufException.truncatedMessage();
                    }
                    totalBytesRetired += n;
                    pos += n;
                }
                sizeLeft -= chunk.length;
                chunks.add(chunk);
            }

            // OK, got everything. Now concatenate it all into one buffer.
            final byte[] bytes = new byte[size];

            // Start by copying the leftover bytes from this.buffer.
            int pos = originalBufferSize - originalBufferPos;
            System.arraycopy(buffer, originalBufferPos, bytes, 0, pos);

            // And now all the chunks.
            for (final byte[] chunk : chunks)
            {
                System.arraycopy(chunk, 0, bytes, pos, chunk.length);
                pos += chunk.length;
            }

            // Done.
            return bytes;
        }
    }
425627
@Override
    public void setBufferSize(int size) {
        if (this.writing || isClosed()) {
            throw new IllegalStateException("Stream unable to set size");
        }
        this.amountToBuffer = size;
        this.bbSize = (49152 < size) ? 32768 : 8192;

        // make sure we never create larger frames than the max http2 frame size
        Integer h2size = (Integer) this.getVc().getStateMap().get("h2_frame_size");
        if (h2size != null && h2size < bbSize) {
            this.bbSize = h2size;
        }

        int numBuffers = (size / this.bbSize);
        if (0 == size || 0 != (size % this.bbSize)) {
            numBuffers++;
        }
        this.output = new WsByteBuffer[numBuffers];
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "setBufferSize=" + size + "; " + this);
        }
    }
334664
public final void compress(ByteBuffer src, ByteBuffer dest) {
    final int cpLen = compress(src, src.position(), src.remaining(), dest, dest.position(), dest.remaining());
    src.position(src.limit());
    dest.position(dest.position() + cpLen);
  }
76935
public void write(final byte[] srcBytes, final int srcOffset, final int length)
    {
        buffer.putBytes(offset + position, srcBytes, srcOffset, length);
        position += length;
    }