/** * Allocate a {@link ByteBuffer} if the current instance is null; */ protected void createByteBuffer(boolean force){ if (force || byteBuffer == null){ byteBuffer = ByteBufferFactory.allocate(byteBufferType, initialByteBufferSize); } }
/** * Return a direct {@link ByteBuffer} view using the default size. * @param direct - direct or non-direct buffer * @return {@link ByteBuffer} */ public synchronized static ByteBuffer allocateView(boolean direct){ return allocateView(defaultCapacity, direct); }
/** * Create an instance of {@link ByteBuffer} * @param size * @param isDirect * @return */ private static ByteBuffer createByteBuffer(int size, boolean isDirect) { return ByteBufferFactory.allocateView(size, isDirect); }
/** * Allocate a {@link ByteBuffer} if the current instance is null; */ protected void createByteBuffer(boolean force){ if (force || byteBuffer == null){ byteBuffer = ByteBufferFactory.allocate(byteBufferType, initialByteBufferSize); } }
/** * Return a direct {@link ByteBuffer} view using the default size. * @param direct - direct or non-direct buffer * @return {@link ByteBuffer} */ public synchronized static ByteBuffer allocateView(boolean direct){ return allocateView(defaultCapacity, direct); }
public void run(){ if (byteBuffer == null){ byteBuffer = ByteBufferFactory.allocate(byteBufferType, initialByteBufferSize);
/** * Allocate a {@link ByteBuffer} * @param useDirectByteBuffer to create a direct {@link ByteBuffer} * @param useByteBufferView to create {@link ByteBuffer} view * @param size the size of the {@link ByteBuffer} * @return a {@link ByteBuffer} */ public ByteBuffer allocate(boolean useDirectByteBuffer, boolean useByteBufferView, int size){ ByteBuffer byteBuffer; if (useByteBufferView){ byteBuffer = ByteBufferFactory.allocateView(size, useDirectByteBuffer); } else if ( useDirectByteBuffer ){ byteBuffer = ByteBuffer.allocateDirect(size); } else { byteBuffer = ByteBuffer.allocate(size); } return byteBuffer; }
public ThreadAttachment detach() { ThreadAttachment currentAttachment = getAttachment(); int mode = currentAttachment.getMode(); updateAttachment(mode); // Re-create a new ByteBuffer if ((mode & Mode.BYTE_BUFFER) != 0) { byteBuffer = ByteBufferFactory.allocate(byteBufferType, initialByteBufferSize); } if ((mode & Mode.SSL_ENGINE) != 0) { sslEngine = null; } if ((mode & Mode.INPUT_BB) != 0) { inputBB = null; } if ((mode & Mode.OUTPUT_BB) != 0) { outputBB = null; } // Switch to the new ThreadAttachment. this.threadAttachment = null; currentAttachment.deassociate(); return currentAttachment; }
/** * Allocate a {@link ByteBuffer} * @param useDirectByteBuffer to create a direct {@link ByteBuffer} * @param useByteBufferView to create {@link ByteBuffer} view * @param size the size of the {@link ByteBuffer} * @return a {@link ByteBuffer} */ public ByteBuffer allocate(boolean useDirectByteBuffer, boolean useByteBufferView, int size){ ByteBuffer byteBuffer; if (useByteBufferView){ byteBuffer = ByteBufferFactory.allocateView(size, useDirectByteBuffer); } else if ( useDirectByteBuffer ){ byteBuffer = ByteBuffer.allocateDirect(size); } else { byteBuffer = ByteBuffer.allocate(size); } return byteBuffer; }
/** * {@inheritDoc} */ @Override protected InputReader createInputReader() { return new SSLAsyncStream(ByteBufferFactory.allocateView(bbSize,false)); }
/** * Return a new ByteBuffer based on the requested <code>ByteBufferType</code> * @param type the requested <code>ByteBufferType</code> * @param size the {@link ByteBuffer} size. * @return a new ByteBuffer based on the requested <code>ByteBufferType</code> */ public static ByteBuffer allocate(ByteBufferType type,int size){ if (type == ByteBufferType.HEAP){ return ByteBuffer.allocate(size); } else if (type == ByteBufferType.HEAP_VIEW) { return allocateView(size,false); } else if (type == ByteBufferType.HEAP_ARRAY) { return ByteBuffer.wrap(new byte[size]); } else if (type == ByteBufferType.DIRECT){ return ByteBuffer.allocateDirect(size); } else if (type == ByteBufferType.DIRECT_VIEW){ return allocateView(size,true); } else { throw new IllegalStateException("Invalid ByteBuffer Type"); } } }
/** * Return a new ByteBuffer based on the requested <code>ByteBufferType</code> * @param type the requested <code>ByteBufferType</code> * @param size the {@link ByteBuffer} size. * @return a new ByteBuffer based on the requested <code>ByteBufferType</code> */ public static ByteBuffer allocate(ByteBufferType type,int size){ if (type == ByteBufferType.HEAP){ return ByteBuffer.allocate(size); } else if (type == ByteBufferType.HEAP_VIEW) { return allocateView(size,false); } else if (type == ByteBufferType.HEAP_ARRAY) { return ByteBuffer.wrap(new byte[size]); } else if (type == ByteBufferType.DIRECT){ return ByteBuffer.allocateDirect(size); } else if (type == ByteBufferType.DIRECT_VIEW){ return allocateView(size,true); } else { throw new IllegalStateException("Invalid ByteBuffer Type"); } } }
/** * {@inheritDoc} */ @Override protected InputReader createByteBufferInputStream() { return new SSLAsyncStream(ByteBufferFactory.allocateView(bbSize,false)); }
/** * Creates {@link InputReader} */ protected InputReader createInputReader() { return new InputReader( ByteBufferFactory.allocateView(bbSize,false)); }
/** * Creates {@link InputReader} */ protected InputReader createByteBufferInputStream() { return new InputReader( ByteBufferFactory.allocateView(bbSize,false)); } }
securedBB = ByteBufferFactory.allocateView( requiredBBSize * 2, securedBB != null && securedBB.isDirect()); final ByteBuffer newBB = ByteBufferFactory.allocateView( requiredBBSize * 2, securedBB.isDirect()); newBB.limit(newBB.position());
ByteBuffer newBuffer = ByteBufferFactory.allocateView( size, buffer.isDirect());
workerThread.setByteBuffer(nBuf); } else { workerThread.setByteBuffer(ByteBufferFactory.allocateView(false));