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?
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.