| Author |
Monkhouse book and readFully method
|
Margarita Babkova
Ranch Hand
Joined: May 09, 2012
Posts: 32
|
|
Hi there,
I am reading a Monkhouse book and it says that "read method does not guarantee that entire record wood be read, but at list one byte would be read. and strongly suggest to use readFully.
I want only read a valid room record with delete flag==0; So before using this readFully, i am reading a flag byte value and do a validation of it.
but statement in the book puts doubts in me. Will it really work - 100% times?. it works now ...
what would happen if it just read my one byte flag and does not want to read my database.readFylly?
[edit] do not post complete code snippets
thank you in advance.
|
 |
Anayonkar Shivalkar
Bartender
Joined: Dec 08, 2010
Posts: 1295
|
|
Hello Margarita Babkova,
Welcome to CodeRanch!
Frankly speaking, I did not read thorough code from MonkHouse - I used it basically for tackling design level issues.
But yes, looking from code, the text makes pretty much sense.
In the code, they are first using read method to simply check that if record is not marked as deleted. If not, then readFully method is used to actually read complete record.
I hope this helps.
|
Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD)
|
 |
Roel De Nijs
Bartender
Joined: Jul 19, 2004
Posts: 4351
|
|
I have 2 concerns with the code you showed:
1/ Room.RECORD_LENGTH seems to me to be an integer, the readFully-method expects a byte array
2/ why throw a database exception if the flag's value is different from 0? It could be an indication for a deleted record and according to the instructions that's completely valid.
About the readFully-method. According to its javadoc Reads b.length bytes from this file into the byte array, starting at the current file pointer. This method reads repeatedly from the file until the requested number of bytes are read. This method blocks until the requested number of bytes are read, the end of the stream is detected, or an exception is thrown. I can't see no reason why your approach wouldn't work.
|
SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
|
 |
Margarita Babkova
Ranch Hand
Joined: May 09, 2012
Posts: 32
|
|
thank you all,
I am spending 90% time trying to understand the logic behind the code in a book - and call it a "Discovery" phase of my own asignment.
but not all of it makes sence from the first read.
in my real code i used a byte array for the readFully method, and throw RecordNotFoundException
[edit] do not post complete code snippets
|
 |
 |
|
|
subject: Monkhouse book and readFully method
|
|
|