aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes (B&S) The read() method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "(B&S) The read() method" Watch "(B&S) The read() method" New topic
Author

(B&S) The read() method

Saheed Adepoju
Ranch Hand

Joined: Jun 23, 2004
Posts: 267
Hi all
I have been a bit confused on how to go by implementing the read() method. Since it accepts an Integer, my immediate instinct is that it would use the value supplied and jump to a particular section(That is after all the schema section and header section has been skipped)!I would like it if i could get a pseudo-code of some kind!


Saheed Adepoju<br />SCJP 1.4<br />SCJD (B&S..In progress)
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Well, you are basically correct. So try to write a formula for getting to the n-th record, n >= 0. Let p(n) be the file pointer position of the record you want to find. Let o be the offset to the first data record, r be the record length (including its delete flag). What's p(n)?

You may have to adjust that for your own particular file schema.
[ December 03, 2005: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Saheed Adepoju
Ranch Hand

Joined: Jun 23, 2004
Posts: 267
Hi
Thanks i was able to solve the above quoted problem on the same day! Now the problem i face s this:
I intend to use a cache(An arraylist), that would have the records on the data file. My algorithm would involve the constructor of my data class read the whole records of the datafile unto an arrayList(private static: so that only one instance is available if client requests for the data file).
My question is this: Do i allow the read() method read from this cache instead of the actual file?My second question is: Is it ok to have the constructor of data.java read all the record once it is invoked?Thanks!
Saheed Adepoju
Ranch Hand

Joined: Jun 23, 2004
Posts: 267
Hi
My other question is: Do i sync on my cache cause i figured, a client might be trying to update, a deleted record!In any case, i would luv a push in the right direction! Thanks!
Ailsa Cape
Ranch Hand

Joined: Aug 10, 2005
Posts: 92
Hi,Saheed

I think you are on the right track.
Do i allow the read() method read from this cache instead of the actual file?

I do the same thing as what you want to do. You may find in this forum that using cache is valid in this exam.

Is it ok to have the constructor of data.java read all the record once it is invoked?

I also did it just like what you said.

Do i sync on my cache cause i figured, a client might be trying to update, a deleted record!

Yes, I think you have to ensure thread safety in multithreading environment by using synchronized sign in this ArrayList when your program is running in the server mode.

I hope this would be helpful.

Regards, Ailsa Cape
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: (B&S) The read() method