• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Monkhouse book and readFully method

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Margarita Babkova
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic