• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

URlyBird: Data File Corrupted???

 
Leo Ho
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe all fields are ASCII (78 is 'N'). You can do a hex dump of the file to be sure.
 
Ed Tse
Ranch Hand
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The data file should not be corrupted, most likely you read it incorrectly.
 
Leo Ho
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Leo Ho
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot, Mihai, that makes me feel much less worried since I've done the same thing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic