Package org.apache.tomcat.util.net
Class SocketBufferHandler
- java.lang.Object
-
- org.apache.tomcat.util.net.SocketBufferHandler
-
public class SocketBufferHandler extends java.lang.ObjectManages read and writeByteBufferinstances for a socket connection, handling buffer state transitions between read and write modes.
-
-
Constructor Summary
Constructors Constructor Description SocketBufferHandler(int readBufferSize, int writeBufferSize, boolean direct)Creates a new SocketBufferHandler with the specified buffer sizes.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidconfigureReadBufferForRead()Switches the read buffer into read mode.voidconfigureReadBufferForWrite()Switches the read buffer into write mode.voidconfigureWriteBufferForRead()Switches the write buffer into read mode.voidconfigureWriteBufferForWrite()Switches 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.java.nio.ByteBuffergetReadBuffer()Returns the read buffer.java.nio.ByteBuffergetWriteBuffer()Returns the write buffer.booleanisReadBufferEmpty()Checks whether the read buffer contains any data.booleanisWriteBufferEmpty()Checks whether the write buffer contains any data.booleanisWriteBufferWritable()Checks whether the write buffer has space for additional data.voidreset()Resets both read and write buffers to their initial empty state.voidunReadReadBuffer(java.nio.ByteBuffer returnedData)Inserts previously read data back into the read buffer so it can be read again.
-
-
-
Constructor Detail
-
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 Detail
-
configureReadBufferForWrite
public void configureReadBufferForWrite()
Switches the read buffer into write mode.
-
configureReadBufferForRead
public void configureReadBufferForRead()
Switches the read buffer into read mode.
-
getReadBuffer
public java.nio.ByteBuffer getReadBuffer()
Returns the read buffer.- Returns:
- the read buffer
-
isReadBufferEmpty
public boolean isReadBufferEmpty()
Checks whether the read buffer contains any data.- Returns:
trueif the read buffer is empty
-
unReadReadBuffer
public void unReadReadBuffer(java.nio.ByteBuffer returnedData)
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:
java.nio.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
public java.nio.ByteBuffer getWriteBuffer()
Returns the write buffer.- Returns:
- the write buffer
-
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.
-
-