Reputation: 2349
The ChannelBufferInputStream.available() method is:
@Override
public int available() throws IOException {
return endIndex - buffer.readerIndex();
}
Wouldn't this break if you write to the buffer after the input stream has been initialized?
Shouldn't this actually be
return buffer.writerIndex() - buffer.readerIndex();
I am trying to do something like this: Initialize the buffers and streams and read/write to the ChannelBuffer. What am I missing here?
final ChannelBuffer _channelBuffer = ChannelBuffers.dynamicBuffer();
final ChannelBufferOutputStream _outputStream = new ChannelBufferOutputStream(_channelBuffer);
final ChannelBufferInputStream _inputStream = new ChannelBufferInputStream(_channelBuffer);
Edit: According to the constructor documentation of ChannelBufferedInputStream: "Creates a new stream which reads data from the specified buffer starting at the current readerIndex and ending at the current writerIndex."
In that case it makes sense. But is there a way to achieve what I am trying to do? Have a single backed buffer and the read operation waits for the write operation to complete.
Upvotes: 1
Views: 299
Reputation: 1340
I need a stream to pull an AudioInputStream which unfortunately runs in a separate thread, but I found a work around by using a PipedInputStream / PipedOutputStream. Works great.
Basically, the messageReceived dumps my bytes into the PipedOutputStream, and my audio thread reads from the PipedInputStream and writes to my SourceDataLine.
Upvotes: 1
Reputation: 12351
It's an intentional behavior. The end of the stream is determined When a ChannelBufferInputStream is created. I agree that the documentation did not state this behavior explicitly. Let me fix it.
Upvotes: 0