• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NX: Is that possible?

 
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, I've just downloaded the exam and read quickly through the specification. These say that the first data in the database are:
4 bytes -> Cookie
4 bytes -> Length of each record
2 bytes -> Number of fields
I've written a very simple application to see the first 10 bytes and I obtain:
Cookie: 0011
Length of each record 000-97
Number of fields: 07
While the first and the third values are acceptable, is the second value right?

Thanks,
Marco
[ March 23, 2004: Message edited by: Marco Tedone ]
 
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marco

Originally posted by Marco Tedone:
Hi, I've just downloaded the exam and read quickly through the specification.

All set to go...Good Luck

These say that the first data in the database are:
4 bytes -> Cookie
4 bytes -> Length of each record
2 bytes -> Number of fields
I've written a very simple application to see the first 10 bytes and I obtain:
Cookie: 0011
Length of each record 000-97
Number of fields: 07
While the first and the third values are acceptable, is the second value right?

Might be. It seems that you have read the values in hexadecimal. If you convert them to int, I mean decimal you values are as follows:
Cookie: 17
Length of each record 151
Number of fields: 7
Then the values are closer to mine and most others, I think.

Thanks,
Marco
[ March 23, 2004: Message edited by: Marco Tedone ]

 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Satish.


Might be. It seems that you have read the values in hexadecimal. If you convert them to int, I mean decimal you values are as follows:
Cookie: 17
Length of each record 151
Number of fields: 7


The problem was the negative value. I then used the following method from the the DataInputStream class:
readUnsignedByte() and I obtained the following:
Cookie: 0011
Length of record: 159
Number of Fields: 07
Does it make sense?
Marco
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marco

Originally posted by Marco Tedone:
Hi Satish.
The problem was the negative value. I then used the following method from the the DataInputStream class:
readUnsignedByte() and I obtained the following:
Cookie: 0011
Length of record: 159
Number of Fields: 07
Does it make sense?
Marco


I'm not sure why you are getting 0's before the number. If you use the RandomAccessFile methods like readInt & readShort depending on the length of the cookie, lenght, and no. of fields, then you should'nt get the 0's before.
BTW, lenght value seems to be correct, but cookie still sould be a numberic value. The method you specified in DataInputStream reads Byte, so maybe you want to use methods that reads integers. If your instructions state somewhat like this:


4 byte numeric, magic cookie value.
4 byte numeric, total overall length
2 byte numeric, number of fields


Then if you use readInt methods or readShort methods then it should be fine. That will make sure you will not get 0's before numbers.
Good Luck.
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marco, to be clear, cookie and fields are still hexadecimal numbers. If you use readInt or readShort methods of RAF you should see the exact values.
 
alzamabar
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Satish Avadhanam:
Hi Marco, to be clear, cookie and fields are still hexadecimal numbers. If you use readInt or readShort methods of RAF you should see the exact values.


Well, because my assignment says explicitly that data uses the format of DataInputStream and DataOutputStream, I used DataInputStream to read the data with the above method. However, I put each byte in a StringBuffer, and then I convert it into a number with the following:

This is possible because the overloaded method append accepts integers. At the end I get a String that I can parse with the wrapper class.
However, the lengths were correct, as now the application reads all data (31 records), correctly.
The only doubt I've still got is related to the flag. My instructions say that it contain 0 or 1, but on my file I get no value. Shall I assume zero here (this would eventually be documented)?
Cheers,
 
Satish Avadhanam
Ranch Hand
Posts: 697
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Marco

Originally posted by Marco Tedone:

Well, because my assignment says explicitly that data uses the format of DataInputStream and DataOutputStream, I used DataInputStream to read the data with the above method. However, I put each byte in a StringBuffer, and then I convert it into a number with the following:

Ok. Its just an indication to us about the format of the data. You can read and write the file with RAF or you can use DIS, DOS. Its NOT a MUST requirement to use only DIS or DOS.


This is possible because the overloaded method append accepts integers. At the end I get a String that I can parse with the wrapper class.

As I said before you can use either RAF or DIS/DOS. If you use RAF then the code to read the cookie/lenghts would be


However, the lengths were correct, as now the application reads all data (31 records), correctly.
The only doubt I've still got is related to the flag. My instructions say that it contain 0 or 1, but on my file I get no value. Shall I assume zero here (this would eventually be documented)?

Actually it is 0 to most people. You can try traversing the whole file to print only flag values and see what they are with code something like this

I know you knew it already, but just for your info. each record length though it is 159, it will be 160 including flag. So you read 1 byte flag, then move 159 bytes, read flag and then move 159 bytes. You should be able to see 0's now.

Cheers,


Please let me know if its not working. Good Luck.
reply
    Bookmark Topic Watch Topic
  • New Topic