Return a buffer of {@code size} bytes containing the {@code size} first byte of {@code buffer}.

@param buffer the buffer.
@param size the size.
@return null if size is 0, the buffer if it has the right size, or a new truncated copy of buffer.
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;
    }
734173
public byte[] getFullBBuffer(int minSize)
    {
        byte[] result = null;
        if (mFullBBuffer != null && mFullBBuffer.length >= minSize) {
            result = mFullBBuffer;
            mFullBBuffer = null;
        }
//System.err.println("DEBUG: Alloc BFull: "+result);
        return result;
    }
797645
function(size) {
    var buffers;
    // read min(buffer, size || infinity)
    if (size) {
      buffers = [];
      while (size && this.buffers.length && !this.buffers[0].eod) {
        var first = this.buffers[0];
        var buffer = first.read(size);
        size -= buffer.length;
        buffers.push(buffer);
        if (first.eod && first.full) {
          this.buffers.shift();
        }
      }
      return Buffer.concat(buffers);
    }

    buffers = this.buffers.map(buf => buf.toBuffer())
      .filter(Boolean);
    this.buffers = [];
    return Buffer.concat(buffers);
  }
947765
public WrappedByteBuffer fillWith(byte b, int size) {
        _autoExpand(size);
        while (size-- > 0) {
            _buf.put(b);
        }
        return this;
    }
1126294
public static LinkedBuffer allocate(int size, LinkedBuffer previous)
    {
        if (size < MIN_BUFFER_SIZE)
            throw new IllegalArgumentException(MIN_BUFFER_SIZE + " is the minimum buffer size.");

        return new LinkedBuffer(size, previous);
    }
1067078
def read_into_buffer(buffer, size)
      tmp = read_all(size)
      i = 0
      tmp.each_byte do |byte|
        Bytes.set_string_byte(buffer, i, byte)
        i += 1
      end
      i
    end
1058909
private byte[] resizeBuffer(final Context context) {
        if (context.buffer == null) {
            context.buffer = new byte[getDefaultBufferSize()];
            context.pos = 0;
            context.readPos = 0;
        } else {
            final byte[] b = new byte[context.buffer.length * DEFAULT_BUFFER_RESIZE_FACTOR];
            System.arraycopy(context.buffer, 0, b, 0, context.buffer.length);
            context.buffer = b;
        }
        return context.buffer;
    }
768523
public static Buffer wrap(final byte[] buffer) {
        if (buffer == null || buffer.length == 0) {
            throw new IllegalArgumentException("the buffer cannot be null or empty");
        }

        return new ByteBuffer(buffer);
    }
916198
public ByteArray create( int size )
    {
        if ( size < 1 )
        {
            throw new IllegalArgumentException( "Buffer size must be at least 1: " + size );
        }
        int bits = bits( size );
        synchronized ( this )
        {
            if ( !freeBuffers.isEmpty() )
            {
                DirectBufferByteArray ba = freeBuffers.get( bits ).pop();
                ba.setFreed( false );
                ba.getSingleIoBuffer().limit( size );
                return ba;
            }
        }
        IoBuffer bb;
        int bbSize = 1 << bits;
        bb = IoBuffer.allocate( bbSize, direct );
        bb.limit( size );
        DirectBufferByteArray ba = new DirectBufferByteArray( bb );
        ba.setFreed( false );
        return ba;
    }
860502
public static long sizeOnHeapOf(ByteBuffer buffer)
    {
        if (buffer.isDirect())
            return BUFFER_EMPTY_SIZE;
        // if we're only referencing a sub-portion of the ByteBuffer, don't count the array overhead (assume it's slab
        // allocated, so amortized over all the allocations the overhead is negligible and better to undercount than over)
        if (buffer.capacity() > buffer.remaining())
            return buffer.remaining();
        return BUFFER_EMPTY_SIZE + sizeOfArray(buffer.capacity(), 1);
    }
1025239
public static long sizeToLong(String size) {
        size = size.trim();
        if (Checker.isNotEmpty(size)) {
            String num;
            if (size.contains(ValueConsts.SPACE)) {
                num = size.split(ValueConsts.SPACE)[0];
            } else {
                num = Utils.extractDigit(size);
            }
            double result;
            if (size.contains(SIZE_TB)) {
                result = stringToDouble(num) * ValueConsts.TB;
            } else if (size.contains(SIZE_GB)) {
                result = stringToDouble(num) * ValueConsts.GB;
            } else if (size.contains(SIZE_MB)) {
                result = stringToDouble(num) * ValueConsts.MB;
            } else if (size.contains(SIZE_KB)) {
                result = stringToDouble(num) * ValueConsts.KB;
            } else {
                result = stringToDouble(num);
            }
            return (long) result;
        }
        return -1;
    }
244553
public void truncate(int size) {

        m_buffer.truncate(size);
        m_position = Math.min(size, m_position);
    }
113208
public ByteBuffer[] toDirectByteBuffers(long offset, long size) {
        long pos = offset;
        long blockSize = Integer.MAX_VALUE;
        long limit = offset + size;
        int numBuffers = (int) ((size + (blockSize - 1)) / blockSize);
        ByteBuffer[] result = new ByteBuffer[numBuffers];
        int index = 0;
        while (pos < limit) {
            long blockLength = Math.min(limit - pos, blockSize);
            result[index++] = UnsafeUtil.newDirectByteBuffer(address() + pos, (int) blockLength, this)
                    .order(ByteOrder.nativeOrder());
            pos += blockLength;
        }
        return result;

    }
1348573
public static ByteBuffer sliceAndSkip(ByteBuffer buffer, int size) {
        ByteBuffer buf = buffer.slice().order(ByteOrder.LITTLE_ENDIAN);
        ByteBuffer slice = (ByteBuffer) ((Buffer) buf).limit(buf.position() + size);
        skip(buffer, size);
        return slice;
    }
64267
public static AreaF area(final AreaSizeF size)
  {
    Objects.requireNonNull(size, "Size");
    return AreaF.of(0.0f, size.sizeX(), 0.0f, size.sizeY());
  }
1114606
def _read_from_buffer(self, size=-1):
        """"""
        # logger.debug('reading %r bytes from %r byte-long buffer', size, len(self._buffer))
        size = size if size >= 0 else len(self._buffer)
        part = self._buffer.read(size)
        self._current_pos += len(part)
        # logger.debug('part: %r', part)
        return part
716174
@Override
    public byte readByte(final boolean unsigned, final int size) throws IOException {
        return (byte) readInt(unsigned, requireValidSizeByte(unsigned, size));
    }