public Buffer asClientCookieBuffer(MemoryManager memoryManager) { if (memoryManager == null) memoryManager = MemoryManager.DEFAULT_MEMORY_MANAGER; final Buffer buffer = memoryManager.allocate(4096); CookieSerializerUtils.serializeClientCookies(buffer, this); buffer.trim(); return buffer; }
private static Buffer appendContentChunkAndTrim( final MemoryManager memoryManager, final Buffer dstBuffer, final Buffer httpContentBuffer) { final boolean useDstBufferForHeaders = dstBuffer != null && dstBuffer.remaining() >= BODY_CHUNK_HEADER_SIZE; final Buffer headerBuffer; if (useDstBufferForHeaders) { headerBuffer = dstBuffer; } else { if (dstBuffer != null) { dstBuffer.trim(); } headerBuffer = memoryManager.allocate(BODY_CHUNK_HEADER_SIZE); headerBuffer.allowBufferDispose(true); } headerBuffer.put((byte) 'A'); headerBuffer.put((byte) 'B'); headerBuffer.putShort((short) (4 + httpContentBuffer.remaining())); headerBuffer.put(AjpConstants.JK_AJP13_SEND_BODY_CHUNK); headerBuffer.putShort((short) httpContentBuffer.remaining()); headerBuffer.trim(); Buffer resultBuffer = Buffers.appendBuffers(memoryManager, headerBuffer, httpContentBuffer); // Add terminating \0 final Buffer terminatingBuffer = memoryManager.allocate(1); terminatingBuffer.allowBufferDispose(true); resultBuffer = Buffers.appendBuffers(memoryManager, resultBuffer, terminatingBuffer); if (!useDstBufferForHeaders && dstBuffer != null) { resultBuffer = Buffers.appendBuffers(memoryManager, dstBuffer, resultBuffer); } if (resultBuffer.isComposite()) { // If during buffer appending - composite buffer was created - // allow buffer disposing ((CompositeBuffer) resultBuffer).allowInternalBuffersDispose(true); } return resultBuffer; }