in bijection-core/src/main/scala/com/twitter/bijection/Bufferable.scala [103:117]
def reallocate(bb: ByteBuffer): ByteBuffer = {
// Double the buffer, copy the old one, and put:
val newCapacity = if (bb.capacity > (DEFAULT_SIZE / 2)) bb.capacity * 2 else DEFAULT_SIZE
val newBb = if (bb.isDirect) {
ByteBuffer.allocateDirect(newCapacity)
} else {
ByteBuffer.allocate(newCapacity)
}
val tmpBb = bb.duplicate
val currentPos = tmpBb.position()
tmpBb.position(0)
tmpBb.limit(currentPos)
newBb.put(tmpBb)
newBb
}