• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading String like InputStream

 
Matt Hooks
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I'm trying to figure out a way to buffer string data, such as with a BufferedReader. I already use a BufferedReader with a socket to get incoming stream data, so I figured it could be useful for this implementation.

I use a while loop like below to read in data as it is received on a socket;



With this, the while loop always waits until there is new data in the BufferedReader before continuing. Plus, new data can be supplied to the buffered reader at any time.

I am trying to implement this functionality without a socket. For example, a thread class would have a method that allows me at any time to add a line to the buffer so the thread could parse it.

I've looked into StringReader, and various printwriter/buffer combinations, but I can never seem to get both of the above mentioned benefits into one solution. Two hours now and I am completely stumped.

Any suggestions are much appreciated.
 
Paul Clapham
Sheriff
Posts: 21862
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't quite get it. Are you saying you're going to have some threads which write to... something... and another thread which is reading from that something? Just saying you don't want to use sockets doesn't quite tell me what you do want instead.

Anyway, if that's it then there's PipedInputStream and PipedOutputStream. There might even be PipedReader and PipedWriter but you could check the API documentation for that.
 
Matt Hooks
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:I don't quite get it. Are you saying you're going to have some threads which write to... something... and another thread which is reading from that something? Just saying you don't want to use sockets doesn't quite tell me what you do want instead.

Anyway, if that's it then there's PipedInputStream and PipedOutputStream. There might even be PipedReader and PipedWriter but you could check the API documentation for that.


Sorry for having been vague, I was out the door, heheh.

I just ran a test file using PipedInputSteam and PipedOutputStream and it appears to be exactly what I was looking for! I'm a bit embarrassed I somehow missed these while digging through the documentation. Thanks a bunch. :)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!