aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Can someone explain this in better english for me ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Can someone explain this in better english for me ?" Watch "Can someone explain this in better english for me ?" New topic
Author

Can someone explain this in better english for me ?

Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

Start of file
4 byte numeric, magic cookie value. Identifies this as a data file
4 byte numeric, total overall length in bytes of each record
2 byte numeric, number of fields in each record

Schema description section.
Repeated for each field in a record:
2 byte numeric, length in bytes of field name
n bytes (defined by previous entry), field name
2 byte numeric, field length in bytes
end of repeating block

Data section.
Repeat to end of file:
1 byte "deleted" flag. 0 implies valid record, 1 implies deleted record
Record containing fields in order specified in schema section, no separators between fields, each field fixed length at maximum specified in schema information

End of file


I understand the 1st 4 bytes of the file and have identified my magic number. It then says there is another 4 bytes that give the length in bytes of each record. Now is that the bytes from number 4-8? Surely it cant be the same value as the magic cookie?

Also
In the schema section it says that n bytes defined be previous entry. Previous entry what? Length?

I feel very confused.

SCJP 6.0, SCJD (400/400), SCBCD for JEE 5, SCWCD 1.4 I do videos for development at
http://www.youtube.com/user/thejartender?feature=mhee
I am probably the only developer ever to have had an orange sized brain tumor in my brain while learning development!!
Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

I would just like to add that i used randomAccessFile with skipBytes() and readInt to get these values
Magic cookie = 513
The readInt method from bytes 4-8 return 182 does that mean that 182 is the length of each record?

Edit *** I just found out that these values match the supplied information. Should I therefore be using a class that calculates the record length for each contractor or can I use my own created class that calculated the record length with the supplied information? I dont want to add any reundant code to this assignment.
K. Tsang
Bartender

Joined: Sep 13, 2007
Posts: 1958
    
    7

Hi Yucca, I had the exact problem you did when I started my assignment. Let see if I can help:
Since you use RandomAccessFile to read/write your data. Then 4 bytes= integer, 2 bytes=short right? Then right off the bat when you first read your data file your should able to do this given raf is the RandomAccessFile:



Reading the data section uses the same idea - readByte to read the delete flag, for loop to read each field's value. Oh to get a String you can use new String(byte[]) constructor.

Now of course you don't neccessarily need to read the header everytime. That's why the pointer variable enables you to use the raf.seek() method to jump around. Another decision to make is how many time to read the magic cookie value.

Hope this helps.


K. Tsang JavaRanch SCJP5 SCJD/OCM-JD
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Can someone explain this in better english for me ?
 
Similar Threads
how to read data from db file
Delete Flag Empty -does this imply record valid?
Deciphering the instructions
How to check the B&S db file is in correct format?
URLyBird Data File Format