This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes URlyBird: Data File Corrupted??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "URlyBird: Data File Corrupted???" Watch "URlyBird: Data File Corrupted???" New topic
Author

URlyBird: Data File Corrupted???

Leo Ho
Ranch Hand

Joined: Mar 31, 2005
Posts: 36
Hi everyone, I try to print out the data file, but it seems like the fields size and smoking are corrupted, for example, this is 2 records that I read:

Marker: 0
Name: Castle
City: Lendmarch
Size: 874520608 --> OOPS!!!
Smoking: 78 --> OOPS!!!
Rate: $140.00
Date: 2003/09/17
Owner:
**********************************************
Marker: 0
Name: Pandemonium
City: Lendmarch
Size: 908075040 --> OOPS!!!
Smoking: 89 --> OOPS!!!
Rate: $230.00
Date: 2004/05/02
Owner:

I use readInt(), readByte() to read the size and the smoking fields respectively.

Does anyone face similar problem or is the data file really corrupted???

Thanks,

Leo
B Chen
Ranch Hand

Joined: Dec 27, 2005
Posts: 89
I believe all fields are ASCII (78 is 'N'). You can do a hex dump of the file to be sure.


SCJD<br />SCJP 1.4
Ed Tse
Ranch Hand

Joined: Sep 18, 2003
Posts: 183
The data file should not be corrupted, most likely you read it incorrectly.


SCJP, Pre-SCJD (URLyBird 1.3.1), Teradata Cert'd Prof
Leo Ho
Ranch Hand

Joined: Mar 31, 2005
Posts: 36
Thanks Chen. You're right.

The wierd thing is that I cannot use readInt() to read the room's size, instead, I have to readFully() to get a string and then convert to an integer myself (e.g. room's size is stored as "2 ", "5 ").

Leo.
Ed Tse
Ranch Hand

Joined: Sep 18, 2003
Posts: 183
Yeah, you are not supposed to use readInt() because you are not supposed to know the size or type of each field. These information is defined in the schema and should not be hardcoded. This is what I did

for (int i=0; i<records.length; i++)
{
byte []byteString = new byte[((Integer)sizeOfFields.elementAt(i)).intValue()];
file.read(byteString);
records[i] = new String(byteString);
}

so I am reading a defined byte size and store it as a string. Every thing from the db are strings, they are not integers or anything else.
Leo Ho
Ranch Hand

Joined: Mar 31, 2005
Posts: 36
Ed, but for the magic cookie and other schema's headers, I can read them by using readInt(), readShort() - I try to use readFully() in order to make things consistently but it does not work (the call to Integer.parseInt() on the magic cookie, read by readFully(), throws NumberFormatException).

How do you parse the headers?

Leo
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi Leo,

You are dealing with two stuff here :
1.The magic cookie used to identify your right database file, im my case is a int (4 byte) so I use a readInt method.
2.The records - for each record I read the bytes (according to my data scheme) and I build strings(arrays).


Regards ,Mihai


SCJP, SCJD, SCWCD, OCPJBCD
Leo Ho
Ranch Hand

Joined: Mar 31, 2005
Posts: 36
Thanks a lot, Mihai, that makes me feel much less worried since I've done the same thing.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URlyBird: Data File Corrupted???
 
Similar Threads
URLyBird 1.1.3 Schema description section Data File Format
UrlyBird : Queries
About the db file question.
weird CREATE method !!!
Database file reader