Reverse File Reader developed: I need to bufferize it !

A

Alessandro

Hi,

I have developed a class reading a text file in reverse way (from EOF
to first line). using RandomAccessFile and calling seek( ) method.

I have only a problem about performance: it isn't a bufferized reader
and so a bit slow and I really don't know how to proceed.
Do you know if and how is possible to use a BufferedReader or
something like that to my code ?

For anyone interested about this enhancement, please contact me at
(e-mail address removed).

Thanks and best rgds,
Ale
 
R

Roedy Green

I have only a problem about performance: it isn't a bufferized reader
and so a bit slow and I really don't know how to proceed.
Do you know if and how is possible to use a BufferedReader or
something like that to my code ?

Here are three approaches:

1. just read the file in bigger chunks.

2. the old COBOL way, the way we used to use when computers had only
16K and only one app running at a time. You have two threads and two
buffers. One thread tries to keep two buffers full by lookahead,
toggling back and forth between the two buffers. The two threads have
a producer-consumer relationship. You have to synchronize them so
that the producer does not get too far ahead and the consumer does not
use a buffer until it is full.

3. fool around with nio.
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Here is a point of no return after which warming becomes unstoppable
and we are probably going to sail right through it.
It is the point at which anthropogenic (human-caused) warming triggers
huge releases of carbon dioxide from warming oceans, or similar releases
of both carbon dioxide and methane from melting permafrost, or both.
Most climate scientists think that point lies not far beyond 2°C (4°F) C hotter."
~ Gwynne Dyer
 
L

Lew

Alessandro said:
I have developed a class reading a text file in reverse way (from EOF
to first line). using RandomAccessFile and calling seek( ) method.

I have only a problem about performance: it isn't a bufferized reader
and so a bit slow and I really don't know how to proceed.
Do you know if and how is possible to use a BufferedReader or
something like that to my code ?

Please do not multipost.

You have received good answers in both clj.help and clj.programmer.
 
B

blueparty

Roedy said:
Here are three approaches:

1. just read the file in bigger chunks.

2. the old COBOL way, the way we used to use when computers had only
16K and only one app running at a time. You have two threads and two
buffers. One thread tries to keep two buffers full by lookahead,
toggling back and forth between the two buffers. The two threads have
a producer-consumer relationship. You have to synchronize them so
that the producer does not get too far ahead and the consumer does not
use a buffer until it is full.

3. fool around with nio.

Alessandro says he needs buffered reader. Perhaps he would like to have
things like readLine() working consistently. I think that he would need
to implement them himself.

I am not sure if this would work, but it is an interesting exercise
anyway. Perhaps Alessandro could do the following:

1. Create a subclass of BufferedReader

2. Override the methods inherited from Reader to work the way he needs
them. I mean methods like skip() and read().

B
 
M

Mark Space

blueparty said:
Alessandro says he needs buffered reader. Perhaps he would like to have
things like readLine() working consistently. I think that he would need
to implement them himself.

BufferReader and BufferWriter are decorators: they take another IO
stream and wrap it to provide their buffering functionality. I'd rather
implement something simple like InputStream than re-do the buffering in
BufferedReader.

And the above is just a general rule, I haven't actually looked at
buffering specifically.
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top