wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes NX : Help! Error occur in read the data file! 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 "NX : Help! Error occur in read the data file!" Watch "NX : Help! Error occur in read the data file!" New topic
Author

NX : Help! Error occur in read the data file!

Jamy Wang
Ranch Hand

Joined: Sep 21, 2003
Posts: 83
in my introduce.html:
Data file Format
The format of data in the database file is as follows:
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
All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes. All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII.
//my code

And print :
magic cookie value : 259
columnCount = 7
fieldName = name
fieldLength = 64
fieldName = location
fieldLength = 64
fieldName = size
fieldLength = 4
fieldName = smoking
fieldLength = 1
fieldName = rate
fieldLength = 8
fieldName = date
fieldLength = 10
fieldName = owner
fieldLength = 8
fieldFlag : 0
64
64
Dew Drop Inn
fieldFlag : 83
64
64
mallville 4
fieldFlag : 32
4
4
Y$
fieldFlag : 50
1
1
1
fieldFlag : 48
8
8
.00 2005
fieldFlag : 47
10
10
05/02
fieldFlag : 32
8
8
What's wrong with my code?


Best Regards<br /> <br />SCJP1.4 SCJD1.4 SCEA
Jamy Wang
Ranch Hand

Joined: Sep 21, 2003
Posts: 83
help
Paul Tongyoo
Ranch Hand

Joined: Sep 30, 2003
Posts: 91
Originally posted by james wang:
help

Hi James--
It looks like the byte pointer is off after the first for-loop iteration in that infinite while loop. Why don't you confirm its location after the readFully operation so you know it actually read in what you expected?
Regards,
Paul


Sun Certified Java Web Component Developer for J2EE v1.4<br />Sun Certified Java Developer for J2SE v1.4<br />Sun Certified Java Programmer for J2SE v1.4
Jamy Wang
Ranch Hand

Joined: Sep 21, 2003
Posts: 83
Thank you for your reply ,Paul.
I don't understand why the point to will be incorrect.
I got the first "field Flag" as 0 , but I got the second flag as 83??
What's the wrong with my code? What should be done?
I read the instructions.html file, it said :
//////////////////
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
All numeric values are stored in the header information use the formats of the DataInputStream and DataOutputStream classes. All text values, and all fields (which are text only), contain only 8 bit characters, null terminated if less than the maximum length for the field. The character encoding is 8 bit US ASCII.
//////////////////////
each field fixed length at maximum specified in schema information ,so i use readFully() to read the data into the byte array.
Anyone who could help me ? Thanks in advance!
Filip Moens
Greenhorn

Joined: Oct 16, 2003
Posts: 24
Hi James,
had a quick look at your problem.
It looks like you are reading the flag every time you read a field instead of for each record.
Can you try to change your code to:
while(true) {
pt("fieldFlag : "+db.readByte() );
for(int i =0;i<columnCount;i++){
and see what happens?
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Filip,
and see what happens?

I bet with you that the file will look OK.
Well, I am a bit ashamed of it, but I spent twice 3 minutes on that code snippet without pointing the issue ...
Thank you for having solved the problem.
Best,
Phil.
Paul Tongyoo
Ranch Hand

Joined: Sep 30, 2003
Posts: 91
Originally posted by Filip Moens:
...
had a quick look at your problem.
It looks like you are reading the flag every time you read a field instead of for each record.
...


Ack!! You weren't actually supposed to tell him the answer!!!

[ November 10, 2003: Message edited by: Paul Tongyoo ]
Jamy Wang
Ranch Hand

Joined: Sep 21, 2003
Posts: 83
Thank you all! I found out the error just after I post this thread. I'm so careless and made a silly mistake...
Thank you again.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: NX : Help! Error occur in read the data file!
 
Similar Threads
NX:[URLyBird]How to use the specified Data File Format?
About the db file question.
NX:[URLyBird]Get the correct field values
How to check the B&S db file is in correct format?
Data class in Beta