I am implementing a client that will receive a single file from the
server. To keep it simple, I am assuming the client already knows the
name of the file it is to receive. So the client will first receive a
file header followed by actual file contents. The header is simple,
just the length of the file encapsulated as an 8 byte long.
Overall Sequence Diagram
Server --> Length of File --> Client
Server --> FileContents --> Client
I add the following channel handlers to my client’s channel handler pipeline:
p.addLast(new msgToLongDecoder(), chunkedReadHandler());
where msgToLongDecoder extends ByteToMessageDecoder and ReadFileHandler
ReadFileHandler extends SimpleChannelInboundHandler
New Overall Sequence Diagram
Server --> Length of File --> Client(MsgToLongDecoder ReadFileHandler)
Server --> FileContents --> Client(MsgToLongDecoderReadFileHandler)
After the client receives the file length (encapsulated by raw bytes)
the client first uses the MsgToLongDecoder to decode the bytes ( into
the file length (type Long).
Questions
- After decoding, is the file length automatically pushed to the next handler in the channel pipeline which will be the
ReadFileHandler? if so, what method in the netty code would
automatically push the file Length to the next handler?
- Also do I have to manually within the code handle this case, meaning
within the readFileHandler methos I will have to check to see if the
event/msg is an instance of ByteBuf () as in (if message instanceof
ByteBuf)?
- When the server sends the actual file contents, based on the channel
pipeline, will the client’s msgToLongDecoder first receive the file
contents (ByteBuf)?
if so, does the msgToLongDecoder automatically ignore the stream and
pushes it to the next channelHandler within the pipeline which is the
ReadFileHandler? Or do I have to manually do this?
Also, how can the ReadFileHandler accept and process ChunkedInput?
The Netty API specifies that ChunkedInput is a data stream of
indefinite length which is consumed by ChunkedWriteHandler?