Search code examples
javadata-structuresnio

java fifo queue that allows pushing back?


is there a fifo queue implementation that provides for replacing the head element after a peek?

i'd like to use this to push a partially written buffer back onto the queue after a partial write onto a network connection (when using java nio selector).

this would be a bit cleaner than sticking the partially written buffer as an attachment on the selection key, but if there's no convenient implementation available I'll have to use that.


Solution

  • You can use a Deque which allows you to add to the start or the end.

    However, if you have a partial write and your buffers are not huge, you could have a slow consumer and you might consider a different action such as closing the connection.