Class SocketBufferHandler
java.lang.Object
org.apache.tomcat.util.net.SocketBufferHandler
Manages read and write
ByteBuffer instances for a socket connection,
handling buffer state transitions between read and write modes.-
Constructor Summary
ConstructorsConstructorDescriptionSocketBufferHandler(int readBufferSize, int writeBufferSize, boolean direct) Creates a new SocketBufferHandler with the specified buffer sizes. -
Method Summary
Modifier and TypeMethodDescriptionvoidSwitches the read buffer into read mode.voidSwitches the read buffer into write mode.voidSwitches the write buffer into read mode.voidSwitches the write buffer into write mode.voidexpand(int newSize) Expands both read and write buffers to the specified size.voidfree()Releases native resources for direct buffers, if applicable.Returns the read buffer.Returns the write buffer.booleanChecks whether the read buffer contains any data.booleanChecks whether the write buffer contains any data.booleanChecks whether the write buffer has space for additional data.voidreset()Resets both read and write buffers to their initial empty state.voidunReadReadBuffer(ByteBuffer returnedData) Inserts previously read data back into the read buffer so it can be read again.
-
Constructor Details
-
SocketBufferHandler
public SocketBufferHandler(int readBufferSize, int writeBufferSize, boolean direct) Creates a new SocketBufferHandler with the specified buffer sizes.- Parameters:
readBufferSize- the size of the read buffer in byteswriteBufferSize- the size of the write buffer in bytesdirect- whether to allocate direct (off-heap) buffers
-
-
Method Details
-
configureReadBufferForWrite
public void configureReadBufferForWrite()Switches the read buffer into write mode. -
configureReadBufferForRead
public void configureReadBufferForRead()Switches the read buffer into read mode. -
getReadBuffer
-
isReadBufferEmpty
public boolean isReadBufferEmpty()Checks whether the read buffer contains any data.- Returns:
trueif the read buffer is empty
-
unReadReadBuffer
Inserts previously read data back into the read buffer so it can be read again.- Parameters:
returnedData- the data to insert back into the buffer- Throws:
BufferOverflowException- if the buffer cannot accommodate the returned data
-
configureWriteBufferForWrite
public void configureWriteBufferForWrite()Switches the write buffer into write mode. -
configureWriteBufferForRead
public void configureWriteBufferForRead()Switches the write buffer into read mode. -
isWriteBufferWritable
public boolean isWriteBufferWritable()Checks whether the write buffer has space for additional data.- Returns:
trueif the write buffer can accept more data
-
getWriteBuffer
-
isWriteBufferEmpty
public boolean isWriteBufferEmpty()Checks whether the write buffer contains any data.- Returns:
trueif the write buffer is empty
-
reset
public void reset()Resets both read and write buffers to their initial empty state. -
expand
public void expand(int newSize) Expands both read and write buffers to the specified size.- Parameters:
newSize- the new buffer size in bytes
-
free
public void free()Releases native resources for direct buffers, if applicable.
-