• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

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.
 
And tomorrow is the circus! We can go to the circus! I love the circus! We can take this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic