• 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: Please Help - Writting and Reading 2 byte flag

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am reading and writting to my file fine except for the record
indicator (2 byte flag). Part of my database schema states

"Data section. (offset into file equal to "offset to start of record zero" value) Repeat to end of file:
2 byte flag. 00 implies valid record, 0x8000 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"


My question is how do I write/read 0X8000 to the file as a 2 byte flag???
When I read this flag I use the following code:
byte[] b = new byte[2];
raf.read(b); // Read the two bit flag
Where b[0] = 0 and b[1] = 0 for a valid record. But I don't understand how to write 0X8000 and if raf.read(b) will correctly read 0X8000. If I read 0X8000 using read(b) what will b[0] and b[1] equal (I cant test this
yet because I don't know how to write 0X8000 as a two byte flag yet).
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bill,
That "2 bytes flag" is a short. 0X8000 is (short) -32768 while 00 is (short) 0. So using readShort() / writeShort() should solve your issue.
Best,
Phil.
 
eat bricks! HA! And here's another one! And a tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic