This method is often used in conjunction with the {@link Buffer#compact compact} method when transferring data fromone place to another.
8586878889909192939495
GrizzlyChannel.removeChannelIfDisconnectd(connection); byte[] bytes = output.toByteArray(); Buffer buffer = connection.getTransport().getMemoryManager().allocate(bytes.length); buffer.put(bytes); buffer.flip(); buffer.allowBufferDispose(true); context.setMessage(buffer); } finally { GrizzlyChannel.removeChannelIfDisconnectd(connection); }
298299300301302303304305306307308
final SSLConnectionContext.SslResult result = sslCtx.wrap(Buffers.EMPTY_BUFFER, buffer, HS_WRAP_ALLOCATOR); Buffer output = result.getOutput(); output.flip(); if (buffer != output) { if (buffer == netBuffer) { netBuffer.flip(); } }
390391392393394395396397398399400
static Buffer copy(final MemoryManager memoryManager, final Buffer buffer) { final Buffer tmpBuf = memoryManager.allocate(buffer.remaining()); tmpBuf.put(buffer); return tmpBuf.flip(); } static Buffer move(final MemoryManager memoryManager, final Buffer buffer) {
687688689690691692693694695696697
} else { // if we can't write the chunk - buffer it. finishCurrentBuffer(); final Buffer cloneBuffer = memoryManager.allocate(len); cloneBuffer.put(b, off, len); cloneBuffer.flip(); checkCompositeBuffer(); compositeBuffer.append(cloneBuffer); } }
919293949596979899100101
if (decState == Decoder.State.NEED_MORE_DATA || decodedBuffer == null) { return TransformationResult.createIncompletedResult(hasRemainder ? input : null); } return TransformationResult.createCompletedResult(decodedBuffer.flip(), hasRemainder ? input : null); } @Override protected LastResultAwareState<Buffer, Buffer> createStateObject() {
114115116117118119120121122123124
output.putInt(byteRepresentation.length); } output.put(byteRepresentation); output.flip(); output.allowBufferDispose(true); return TransformationResult.createCompletedResult(output, null); }
7778798081828384858687
final int length = remaining(); if (!hasClonedArray) { buffer = memoryManager.allocate(length); buffer.put(heap, offset + pos, length); buffer.flip(); } else { buffer = Buffers.wrap(memoryManager, heap, offset + pos, length); } buffer.allowBufferDispose(true);
186187188189190191192193194195196
return ((WrapperAware) memoryManager).wrap(array, offset, length); } final Buffer buffer = memoryManager.allocate(length); buffer.put(array, offset, length); buffer.flip(); return buffer; } /** * Returns {@link Buffer}, which wraps the {@link ByteBuffer}.
586587588589590591592593594595596
} final Buffer clone = getDefaultMemoryManager().allocate(srcLength); clone.put(srcBuffer, position, srcLength); return clone.flip(); } /** * Reads data from the {@link FileChannel} into the {@link Buffer}. *
188189190191192193194195196197198
// Put GZIP member trailer final Buffer trailer = memoryManager.allocate(TRAILER_SIZE); final CRC32 crc32 = state.crc32; putUInt(trailer, (int) crc32.getValue()); putUInt(trailer, deflater.getTotalIn()); trailer.flip(); resultBuffer = Buffers.appendBuffers(memoryManager, resultBuffer, trailer); }