java random access for input stream

S

suru

Hi,
do we any api in java by which i can have random access over input
stream.
i know randomaccess class which gives random access over a file.

but my requirement is,
i'll execute grep command by runtime exec.
then read grep command's output using inputstream (using buffered
reader e.g.)
i want to display this output on ui and also user can navigate result
using next & previous button.
therefore for this next & previous navigation through result i want
random access over input stream

also i dont want to store grep's result in file, since result could
be very large in size..

any idea, how to handle such situations?
 
A

Arne Vajhøj

suru said:
do we any api in java by which i can have random access over input
stream.
i know randomaccess class which gives random access over a file.

but my requirement is,
i'll execute grep command by runtime exec.
then read grep command's output using inputstream (using buffered
reader e.g.)
i want to display this output on ui and also user can navigate result
using next & previous button.
therefore for this next & previous navigation through result i want
random access over input stream

also i dont want to store grep's result in file, since result could
be very large in size..

any idea, how to handle such situations?

RandomAccessFile or read into an in-memory data structure.

You can not seek on a general InputStream.

Arne
 
R

Roedy Green

stream.
i know randomaccess class which gives random access over a file.

but my requirement is,
i'll execute grep command by runtime exec.
then read grep command's output using inputstream (using buffered
reader e.g.)
i want to display this output on ui and also user can navigate result
using next & previous button.
therefore for this next & previous navigation through result i want
random access over input stream

also i dont want to store grep's result in file, since result could
be very large in size..

Streams necessarily let you traverse forward only. The previous data
may often no longer exist anywhere.

If you want to allow something the user can scroll back, you must
provide some memory -- if not everything, at least a buffer.


I built a beast such as you describe using a JTable. It discarded
the oldest entries off the log, but other than that the user could hop
forward and back using the usual JScroller.

I was able to add a number of other wrinkles, including priorities,
colours, fading (as entries aged they faded). You define two colours
and the entry changes from one to the other by linear interpolation at
a given speed. You have a timer task to periodically refresh the
display with new colours.



--
Roedy Green Canadian Mind Products
http://mindprod.com

"Don’t worry about the world coming to an end today.
It is already tomorrow in Australia."
~ Charles Schulz
 
R

Roedy Green

any idea, how to handle such situations?

If they are in RAM, you have some sort of collection and you delete
the oldest elements.

If they are on disc, you use a squirrel cage, where you write in a
circular pattern and read in a circular pattern.

see http://mindprod.com/jgloss/buffer.html#SQUIRREL
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Don’t worry about the world coming to an end today.
It is already tomorrow in Australia."
~ Charles Schulz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top