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 URLyBird: How do I read in Deleted Flag? 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 "URLyBird: How do I read in Deleted Flag?" Watch "URLyBird: How do I read in Deleted Flag?" New topic
Author

URLyBird: How do I read in Deleted Flag?

Alan Morehead
Greenhorn

Joined: Feb 11, 2004
Posts: 4
Using DataInputStream, I have read in the contents of my sample database file. The header says the fields are 64,64,4,1,8,10,8 bytes. So, I do a loop for each record and read in each field with these byte lengths. The print out is off by 1 byte, so I have to skip one byte for it to line up correctly. The specs say the delete field is 1 byte, so I think this is it. My question is, where is the delete byte? At the beginning of the record or end? When I try to read in the byte, it just shows up blank instead of 0 or 1.
(This is how I am reading the data)
byte [] myByteArray = new byte[1];
in.read(myByteArray);
String s = new String(myByteArray);
System.out.println(s);
The DB schema only lists the 7 fields and this is the data file format:
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
Alan Morehead
Greenhorn

Joined: Feb 11, 2004
Posts: 4
Here is my output without skipping 1 byte:
administrators-Computer:~/java/testArea admin$ java test
Magic Cookie = 257, Total Length = 159, NumOF Fields = 7
===================================================================
FieldNameLength = 4, FieldName = name, Field Length = 64
FieldNameLength = 8, FieldName = location, Field Length = 64
FieldNameLength = 4, FieldName = size, Field Length = 4
FieldNameLength = 7, FieldName = smoking, Field Length = 1
FieldNameLength = 4, FieldName = rate, Field Length = 8
FieldNameLength = 4, FieldName = date, Field Length = 10
FieldNameLength = 5, FieldName = owner, Field Length = 8
===================================================================
Palace Smallville 2 Y$150.00 2005/07/27
Castle Smallville 6 Y$220.00 2005/11/19
Excelsior Smallville 4 Y$230.00 2003/02/05
Palace Whoville 6 N$110.00 2005/09/11
Bed & Breakfast & Business Whoville 2 Y$100.00 2005/08/07
Grandview Whoville 6 Y$210.00 2003/06/10
Dew Drop Inn Metropolis 4 Y$240.00 2005/11/17
Excelsior Metropolis 6 Y$140.00 2005/02/28
Pandemonium Pleasantville 4 N$250.00 2004/12/0
2 Dew Drop Inn Pleasantville 6 N$160.00 2005/03/
04 Dew Drop Inn Digitopolis 4 N$190.00 2005/09
/17 Castle Digitopolis 4 N$90.00 2004/0
1/17 Bed & Breakfast & Business Digitopolis 6 Y$250.00 2003/
09/15 Bed & Breakfast & Business Atlantis 4 N$110.00 2003
/09/03 Excelsior Atlantis 6 Y$230.00 200
4/04/05 Grandview Atlantis 4 N$110.00 20
04/05/04 Elephant Inn EmeraldCity 6 Y$110.00 2
003/07/28 Splendide EmeraldCity 6 N$120.00
2003/06/10 Castle EmeraldCity 4 Y$150.00
2003/05/15 Splendide Bali Hai 6 Y$100.0
0 2005/04/06 Pandemonium Bali Hai 4 Y$150.
00 2003/08/01 Grandview Xanadu 6 N$150
.00 2003/08/02 Pandemonium Xanadu 2 N$13
0.00 2004/08/07 Castle Paravel 4 N$2
20.00 2004/09/14 Splendide Paravel 4 N$
110.00 2004/03/14 Palace Hobbiton 4 N
$90.00 2003/09/22 Grandview Hobbiton 4
Y$110.00 2004/01/03 Excelsior Hobbiton 4
N$110.00 2005/06/23 Castle Lendmarch 4
N$140.00 2003/09/17 Pandemonium Lendmarch 6
Y$230.00 2004/05/02 Grandview Lendmarch

And then I skip 1 byte and it lines up fine...

Magic Cookie = 257, Total Length = 159, NumOF Fields = 7
===================================================================
FieldNameLength = 4, FieldName = name, Field Length = 64
FieldNameLength = 8, FieldName = location, Field Length = 64
FieldNameLength = 4, FieldName = size, Field Length = 4
FieldNameLength = 7, FieldName = smoking, Field Length = 1
FieldNameLength = 4, FieldName = rate, Field Length = 8
FieldNameLength = 4, FieldName = date, Field Length = 10
FieldNameLength = 5, FieldName = owner, Field Length = 8
===================================================================
Palace Smallville 2 Y$150.00 2005/07/27
Castle Smallville 6 Y$220.00 2005/11/19
Excelsior Smallville 4 Y$230.00 2003/02/05
Palace Whoville 6 N$110.00 2005/09/11
Bed & Breakfast & Business Whoville 2 Y$100.00 2005/08/07
Grandview Whoville 6 Y$210.00 2003/06/10
Dew Drop Inn Metropolis 4 Y$240.00 2005/11/17
Excelsior Metropolis 6 Y$140.00 2005/02/28
Pandemonium Pleasantville 4 N$250.00 2004/12/02
Dew Drop Inn Pleasantville 6 N$160.00 2005/03/04
Dew Drop Inn Digitopolis 4 N$190.00 2005/09/17
Castle Digitopolis 4 N$90.00 2004/01/17
Bed & Breakfast & Business Digitopolis 6 Y$250.00 2003/09/15
Bed & Breakfast & Business Atlantis 4 N$110.00 2003/09/03
Excelsior Atlantis 6 Y$230.00 2004/04/05
Grandview Atlantis 4 N$110.00 2004/05/04
Elephant Inn EmeraldCity 6 Y$110.00 2003/07/28
Splendide EmeraldCity 6 N$120.00 2003/06/10
Castle EmeraldCity 4 Y$150.00 2003/05/15
Splendide Bali Hai 6 Y$100.00 2005/04/06
Pandemonium Bali Hai 4 Y$150.00 2003/08/01
Grandview Xanadu 6 N$150.00 2003/08/02
Pandemonium Xanadu 2 N$130.00 2004/08/07
Castle Paravel 4 N$220.00 2004/09/14
Splendide Paravel 4 N$110.00 2004/03/14
Palace Hobbiton 4 N$90.00 2003/09/22
Grandview Hobbiton 4 Y$110.00 2004/01/03
Excelsior Hobbiton 4 N$110.00 2005/06/23
Castle Lendmarch 4 N$140.00 2003/09/17
Pandemonium Lendmarch 6 Y$230.00 2004/05/02
Grandview Lendmarch 4 N$170.00 2003/11/12
George Marinkovich
Ranch Hand

Joined: Apr 15, 2003
Posts: 619
Hi Alan,
According to the Data Section of your assignment instructions:

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

So for each record you need to read:
1 byte for the deleted flag
64 bytes for the first data field
...
8 bytes for the last data field
According to the specification the deleted flag would be at the start of a data record. It should have the value 0x00 or 0xFF.
Hope this helps,
George


Regards, George
SCJP, SCJD, SCWCD, SCBCD
Alan Morehead
Greenhorn

Joined: Feb 11, 2004
Posts: 4
Thanks,
I got it to work.
I just needed to use in.readByte() instead of an array like the other fields.
Just needed to know I was on the right path.
Thanks again.
 
Consider Paul's rocket mass heater.
 
subject: URLyBird: How do I read in Deleted Flag?
 
Similar Threads
Delete Flag Empty -does this imply record valid?
How to decide header length from data file ?
URLyBird Data File Format
Can someone explain this in better english for me ?
Deciphering the instructions