Package org.apache.thrift.transport.sasl
Class FrameWriter
java.lang.Object
org.apache.thrift.transport.sasl.FrameWriter
- Direct Known Subclasses:
DataFrameWriter
,SaslNegotiationFrameWriter
Write frame (header and payload) to transport in a nonblocking way.
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected abstract ByteBuffer
buildFrame
(byte[] header, int headerOffset, int headerLength, byte[] payload, int payloadOffset, int payloadLength) void
clear()
Release the byte buffer.boolean
void
withHeaderAndPayload
(byte[] header, byte[] payload) Provide (maybe empty) header and payload to the frame.void
withHeaderAndPayload
(byte[] header, int headerOffset, int headerLength, byte[] payload, int payloadOffset, int payloadLength) Provide extra header and payload to the frame.void
withOnlyPayload
(byte[] payload) Provide only payload to the frame.abstract void
withOnlyPayload
(byte[] payload, int offset, int length) Provide only payload to the frame.void
write
(TNonblockingTransport transport) Nonblocking write to the underlying transport.
-
Field Details
-
frameBytes
-
-
Constructor Details
-
FrameWriter
public FrameWriter()
-
-
Method Details
-
withHeaderAndPayload
public void withHeaderAndPayload(byte[] header, byte[] payload) Provide (maybe empty) header and payload to the frame. This can be called only when isComplete returns true (last frame has been written out).- Parameters:
header
- Some extra header bytes (without the 4 bytes for payload length), which will be the start of the frame. It can be empty, depending on the message formatpayload
- Payload as a byte array- Throws:
IllegalStateException
- if it is called when isComplete returns falseIllegalArgumentException
- if header or payload is invalid
-
withHeaderAndPayload
public void withHeaderAndPayload(byte[] header, int headerOffset, int headerLength, byte[] payload, int payloadOffset, int payloadLength) Provide extra header and payload to the frame.- Parameters:
header
- byte array containing the extra headerheaderOffset
- starting offset of the header portitionheaderLength
- length of the extra headerpayload
- byte array containing the payloadpayloadOffset
- starting offset of the payload portionpayloadLength
- length of the payload- Throws:
IllegalStateException
- if preivous frame is not yet complete (isComplete returns fals)IllegalArgumentException
- if header or payload is invalid
-
withOnlyPayload
public void withOnlyPayload(byte[] payload) Provide only payload to the frame. Throws UnsupportedOperationException if the frame expects a header.- Parameters:
payload
- payload as a byte array
-
withOnlyPayload
public abstract void withOnlyPayload(byte[] payload, int offset, int length) Provide only payload to the frame. Throws UnsupportedOperationException if the frame expects a header.- Parameters:
payload
- The underlying byte array as a recipient of the payloadoffset
- The offset in the byte array starting from where the payload is locatedlength
- The length of the payload
-
buildFrame
protected abstract ByteBuffer buildFrame(byte[] header, int headerOffset, int headerLength, byte[] payload, int payloadOffset, int payloadLength) -
write
Nonblocking write to the underlying transport.- Throws:
TTransportException
-
isComplete
public boolean isComplete()- Returns:
- true when no more data needs to be written out
-
clear
public void clear()Release the byte buffer.
-