Reputation: 18350
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.
Upvotes: 0
Views: 698
Reputation: 311016
After a peek the head element is undisturbed, so your question doesn't make sense. Just peek, try the write, and if there is nothing left then remove the buffer from the queue.
Upvotes: -1
Reputation: 533780
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.
Upvotes: 3