1

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.

1
  • I just spent a few hours trying to figure out why my input stream kept returning zero bytes available....now I know. I just pulled down a new build and I see no fix yet, maybe I'll pull down the source and fix it. Commented Apr 13, 2012 at 14:59

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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.

1 Comment

Thanks Trustin. Is there any other buffer/input stream that I can use to achieve this behavior. I want the read to block while the write (slow) operation fills the buffer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.