File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes What about records 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 "What about records" Watch "What about records" New topic
Author

What about records

uzma ali
Ranch Hand

Joined: Jun 22, 2007
Posts: 56
My understanding that after reading the feild names then there should be record values
so when I use readByte from the 7th byte , it does not give me desired results:
DB file is :

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

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

Data section.
Repeat to end of file:
1 byte flag. 00 implies valid record, 0xFF 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



It starts reading feild names again. Please help.

Regards

Uzma

P.S list is storing the bytes in each field
Jason Moors
Ranch Hand

Joined: Dec 04, 2001
Posts: 188
Hi,

The 7th byte will give you start of the schema description section not the start of the data section for record values.

I can't understand from your code what you are trying to achieve with the iterator?

1) Read Magic Cookie
2) Read Number of fields
3) Use a for loop to get the fieldname a field length

Once you have performed the following steps the file pointer will be at the start of the data section, you can then use the field lengths you have retrieved in the previous step to read each record.

Regards
Jason
uzma ali
Ranch Hand

Joined: Jun 22, 2007
Posts: 56
Thanks Jason you are always been help


Finally I am getting values in shape of records. The iterator is to iterate records basically.
The output is as under for one record, it's still not 100% but I am close. Any suggestions?

Bitter Homes & Gardens Smallville Drywall, Painting, Carpets 10 $75.00 ]

Thanks for all the help, I am grateful.

Regards

Uzma
Jason Moors
Ranch Hand

Joined: Dec 04, 2001
Posts: 188
But what is bufferstore? as you are still reading records from your randomaccessfile (in) object? so it's not clear what you are iterating.

The read(byte[] b) method returns -1 if there is no more data or then end of file is reached, so you could loop through the records until you reach the end and remove the need for your iterator, which I think complicates the mechanism.

Otherwise I think you are almost there, you just need to split the record byte array into individual fields before converting to strings.


Jason
[ August 10, 2007: Message edited by: Jason Moors ]
uzma ali
Ranch Hand

Joined: Jun 22, 2007
Posts: 56
Thanks Jason

you were right iterator was not needed



Now there is last problem left there is a box I am getting in the out put where every record start. I know the reason which is 1 byte flag. 00 implies valid record, 0xFF implies deleted record , according to the data file . I am just thinking how to read this byte so it does not show in the output. Any suggestions? Also please advice , am I on the right track?

regards

Uzma
Jason Moors
Ranch Hand

Joined: Dec 04, 2001
Posts: 188
All you need to do is split the oneRecord byte array into separate fields, as you know the length of the fields from reading the header section.

When I read the header section I store the field information in an array call fieldInfo, therefore when I've read the record byte array I know how many bytes to read


[ August 10, 2007: Message edited by: Jason Moors ]
Vaishali Paramane
Ranch Hand

Joined: Mar 05, 2007
Posts: 106
Hi
Please check this link.
May be it will help you.

http://www.coderanch.com/t/187523/java-developer-SCJD/certification/db-format

Thanks

Vaishali


SCJP, SCJD
Preparing for SCWCD
uzma ali
Ranch Hand

Joined: Jun 22, 2007
Posts: 56
Thanks Jason , your tips are always been helpful.
if you would not hear anything from me by tomorrow then that means I have done it

Thanks Vaishali for the link. but only thing is that they are hard coding the values which might not be a good idea.

Thanks a bunch

regards

Uzma
Vaishali Paramane
Ranch Hand

Joined: Mar 05, 2007
Posts: 106
Yes its hard coded
I am also stuck on fetching field lenght.

using that link code i understand all schema related quesion but i cannot able to read field length from schema thats the problem for me.
uzma ali
Ranch Hand

Joined: Jun 22, 2007
Posts: 56
read through my this post and the last one and still you don't get and idea then ask me Jason was a big help to me.

Please do ask if your problem persists after reading.

Uzma
Vaishali Paramane
Ranch Hand

Joined: Mar 05, 2007
Posts: 106
Hi

Thanks

My problem solved.
[ August 10, 2007: Message edited by: Vaishali Paramane ]
Vaishali Paramane
Ranch Hand

Joined: Mar 05, 2007
Posts: 106
HI

can anyone tell me that following checking valid or deleted flag is correct or not?
my out put is correct no problem. just want to confirm.
(2 byte flag. 00 implies valid record, 0x8000 implies deleted record)

short flag = raf.readShort();

while(flag==00 || flag==0x8000){}
uzma ali
Ranch Hand

Joined: Jun 22, 2007
Posts: 56
I think it should be ok as the link you provided me earlier used the same check. Also from datafile description it sounds that you are on the right track.

regards

uzma
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What about records
 
Similar Threads
URLyBird Data File Format
IOException thrown
URLyBird: How do I read in Deleted Flag?
NX:[URLyBird]How to use the specified Data File Format?
still stuck in database