NIO Line at a time handler

Hi everyone,

While I was working on NIO SSH support for my project, I noticed that SSH sends characters one at a time (instead of Telnet in "Line mode"). I created my own crude version of a Line at a time handler that takes the incoming SSHChannelData/ByteBuffer and outputs a String when the user presses 'Enter'. While entering, I also echo back all characters entered.

I can imagine line-at-a-time is pretty common behavior that is well usable in many situations. Is there a standard Line-at-a-Time handler that takes a ByteBuffer and outputs a String?
And if not, do you feel this is something worth pursuing?

Kind regards,

Maarten Engels

There is already something that can do that - LineBasedFrameDecoder from GitHub - apple/swift-nio-extras: Useful code around SwiftNIO. package

Hi Artem,

Thanks for the suggestion!

Perhaps I don't understand correctly, but this decoder seems intended to split incoming ByteBuffers. Whereas I am looking to merge incoming ByteBuffers into a single string.

Perhaps it can be used for this intended behavior? Do you (or perhaps someone else in the forum) know about an example I can look at?

Ah, sorry, I misunderstood you intention, no, that handler is for the opposite. You can accumulate incoming buffers into one buffer and then try decoding a String from the byte buffer when you need it.