Grows the current buffer and returns the updated offset.

@param offset the original offset
@return the updated offset
186411
private int growBuffer(int offset)
    {
        assert offset < 0;
        byte[] oldBuf = myBuffer;
        int oldLen = oldBuf.length;
        byte[] newBuf = new byte[(-offset + oldLen) << 1]; // Double the buffer
        int oldBegin = newBuf.length - oldLen;
        System.arraycopy(oldBuf, 0, newBuf, oldBegin, oldLen);
        myBuffer = newBuf;
        myOffset += oldBegin;
        return offset + oldBegin;
    }
353757
@SuppressWarnings("unchecked")
    public synchronized void expand(int additionalCapacity) {
        if (additionalCapacity <= 0) {
            throw new IllegalArgumentException();
        }

        int capacityBefore = buffer.length;
        synchronized (lock) { // D312598
            int capacityAfter = buffer.length;
            //Check that no one was expanding while we waited on this lock
            if (capacityAfter == capacityBefore) {
                final Object[] newBuffer = new Object[buffer.length + additionalCapacity];

                // PK53203 - put() acquires two locks in sequence.  First, it acquires
                // the insert lock to update putIndex.  Then, it drops the insert lock
                // and acquires the extract lock to update numberOfUsedSlots.  As a
                // result, there is a window where putIndex has been updated, but
                // numberOfUsedSlots has not.  Consequently, even though we have
                // acquired both locks in this method, we cannot rely on the values in
                // numberOfUsedSlots; we can only rely on putIndex and takeIndex.

                if (putIndex > takeIndex) {
                    // The contents of the buffer do not wrap round
                    // the end of the array. We can move its contents
                    // into the new expanded buffer in one go.

                    int used = putIndex - takeIndex;
                    System.arraycopy(buffer, takeIndex, newBuffer, 0, used);
                    putIndex = used;

                    // PK53203.1 - If putIndex == takeIndex, then the buffer is either
                    // completely full or completely empty.  If it is completely full, then
                    // we need to copy and adjust putIndex.  Otherwise, we need to set
                    // putIndex to 0.
                } else if (putIndex != takeIndex || buffer[takeIndex] != null) {
                    // The contents of the buffer wrap round the end
                    // of the array. We have to perform two copies to
                    // move its contents into the new buffer.

                    int used = buffer.length - takeIndex;
                    System.arraycopy(buffer, takeIndex, newBuffer, 0, used);
                    System.arraycopy(buffer, 0, newBuffer, used, putIndex);
                    putIndex += used;
                } else {
                    putIndex = 0;
                }

                // The contents of the buffer now begin at 0 - update the head pointer.

                takeIndex = 0;

                // The buffer's capacity has been increased so update the count of the
                // empty slots to reflect this.
                buffer = (T[]) newBuffer;
            }
        } // D312598
    }
857109
private void expandBuffer(int newBufferSize)
    {
        // Allocate a new buffer.
        ByteBuffer newBuffer = ByteBuffer.allocate(newBufferSize);

        // Copy the content of the current buffer to the new buffer.
        int oldPosition = mBuffer.position();
        mBuffer.position(0);
        newBuffer.put(mBuffer);
        newBuffer.position(oldPosition);

        // Replace the buffers.
        mBuffer = newBuffer;
    }
525910
def update_value(self, offset, value):
        

        if offset + len(value) > self.total_size:
            return Error.INPUT_BUFFER_TOO_LONG

        if len(self.current_value) < offset:
            self.current_value += bytearray(offset - len(self.current_value))
        if len(self.current_value) > offset:
            self.current_value = self.current_value[:offset]

        self.current_value += bytearray(value)
        return 0
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;

    }
814965
public InputStream getInputStreamFromOffset(int offset) throws IOException {
        loadFileData();
        return new ByteArrayInputStream(data, offset, data.length - offset);
    }
1029916
function(target, targetOffset, offset, length) {
    return this.toBuffer().copy(target, targetOffset, offset, length);
  }
698708
protected final int readBytesAt(int offset)
        throws IOException
    {
        // shouldn't modify mBytePtr, assumed to be 'offset'
        if (mIn != null) {
            int count = mIn.read(mByteBuffer, offset, mByteBuffer.length - offset);
            if (count > 0) {
                mByteBufferEnd += count;
            }
            return count;
        }
        return -1;
    }
633528
protected int checkRead(int offset, int length) {
    checkOffset(offset);
    int position = offset + length;
    if (position > size()) {
      throw new BufferUnderflowException();
    }
    return position;
  }
194320
public static byte[] readBytes(ByteBuffer buffer, int offset, int size) {
        final byte[] dest = new byte[size];
        buffer.get(dest, offset, size);
        return dest;
    }
1030320
public static MutableRoaringBitmap addOffset(final ImmutableRoaringBitmap x, int offset) {
    int container_offset = offset >>> 16;
    int in_container_offset = offset % (1<<16);
    if(in_container_offset == 0) {
      MutableRoaringBitmap answer = x.toMutableRoaringBitmap();
      for(int pos = 0; pos < answer.highLowContainer.size(); pos++) {
        int key = BufferUtil.toIntUnsigned(answer.getMappeableRoaringArray()
            .getKeyAtIndex(pos));
        key += container_offset;
        if(key > 0xFFFF) {
          throw new IllegalArgumentException("Offset too large.");
        }
        answer.getMappeableRoaringArray().keys[pos] = (short) key;
      }
      return answer;
    } else {
      MutableRoaringBitmap answer = new MutableRoaringBitmap();
      for(int pos = 0; pos < x.highLowContainer.size(); pos++) {
        int key = BufferUtil.toIntUnsigned(x.highLowContainer.getKeyAtIndex(pos));
        key += container_offset;
        if(key > 0xFFFF) {
          throw new IllegalArgumentException("Offset too large.");
        }
        MappeableContainer c = x.highLowContainer.getContainerAtIndex(pos);
        MappeableContainer[] offsetted = BufferUtil.addOffset(c, 
          (short)in_container_offset);
        if( !offsetted[0].isEmpty()) {
          int current_size = answer.highLowContainer.size();
          int lastkey = 0;
          if(current_size > 0) {
            lastkey = answer.highLowContainer.getKeyAtIndex(
              current_size - 1);
          }
          if((current_size > 0) && (lastkey == key)) {
            MappeableContainer prev = answer.highLowContainer
                .getContainerAtIndex(current_size - 1);
            MappeableContainer orresult = prev.ior(offsetted[0]);
            answer.getMappeableRoaringArray().setContainerAtIndex(current_size - 1,
                orresult);
          } else {
            answer.getMappeableRoaringArray().append((short)key, offsetted[0]);
          }
        }
        if( !offsetted[1].isEmpty()) {
          if(key == 0xFFFF) {
            throw new IllegalArgumentException("Offset too large.");
          }
          answer.getMappeableRoaringArray().append((short)(key + 1), offsetted[1]);
        }
      }
      answer.repairAfterLazy();
      return answer;
    }
  }
253717
private byte[] getMMapBytes(long offset)
      throws IOException {
    //Read the first 4 bytes to get the size of the data
    ByteBuffer buf = getDataBuffer(offset);
    int maxLen = (int) Math.min(5, dataSize - offset);

    int size;
    if (buf.remaining() >= maxLen) {
      //Continuous read
      int pos = buf.position();
      size = LongPacker.unpackInt(buf);

      // Used in case of data is spread over multiple buffers
      offset += buf.position() - pos;
    } else {
      //The size of the data is spread over multiple buffers
      int len = maxLen;
      int off = 0;
      sizeBuffer.reset();
      while (len > 0) {
        buf = getDataBuffer(offset + off);
        int count = Math.min(len, buf.remaining());
        buf.get(sizeBuffer.getBuf(), off, count);
        off += count;
        len -= count;
      }
      size = LongPacker.unpackInt(sizeBuffer);
      offset += sizeBuffer.getPos();
      buf = getDataBuffer(offset);
    }

    //Create output bytes
    byte[] res = new byte[size];

    //Check if the data is one buffer
    if (buf.remaining() >= size) {
      //Continuous read
      buf.get(res, 0, size);
    } else {
      int len = size;
      int off = 0;
      while (len > 0) {
        buf = getDataBuffer(offset);
        int count = Math.min(len, buf.remaining());
        buf.get(res, off, count);
        offset += count;
        off += count;
        len -= count;
      }
    }

    return res;
  }
132194
public Long getOffset() {
    String offsetFromRequest =
        uriInfo.getQueryParameters().getFirst(OffsetParameter.getDefaultOffsetFieldName());

    return offsetFromRequest != null ? new OffsetParameter(offsetFromRequest).getValue()
        : OffsetParameter.getDefaultOffset();
  }
515978
public synchronized int read(byte[] buf, int offset, int length) 
        throws IOException
    {

        if (!waitForContent())
            return -1;
            
         if (length>_buffer.remaining())
            length=_buffer.remaining();
            
         _buffer.get(buf, offset, length);
        return length;
    }
454669
public IntBuffer get(int index, IntBuffer buffer) {
        MemUtil.INSTANCE.put(this, index, buffer);
        return buffer;
    }
414654
@Override
    public V get(ByteBuffer b, int offset, int len) {
        int t = 0;
        for (int i = 0; i < len; i++) {
            byte c = b.get(offset + i);
            int index = __lookup[c & 0x7f];
            if (index >= 0) {
                int idx = t * ROW_SIZE + index;
                t = _rowIndex[idx];
                if (t == 0)
                    return null;
            } else {
                char[] big = _bigIndex == null ? null : _bigIndex[t];
                if (big == null)
                    return null;
                t = big[c];
                if (t == 0)
                    return null;
            }
        }
        return (V) _value[t];
    }
1004168
protected function computeOffset($offset)
    {
        $length = \mb_strlen($this->_string);

        if (0 > $offset) {
            $offset = -$offset % $length;

            if (0 !== $offset) {
                $offset = $length - $offset;
            }
        } elseif ($offset >= $length) {
            $offset %= $length;
        }

        return $offset;
    }