• 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: Reading and writting the 2 byte flag indicator

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My directions have:
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 .
----------------------------------------------------------------------------
Two questions regarding this:
1. How do you write 0x8000 to the file to mark an entry as deleted.
What format is this? I have used numerous raf.write() and raf.writeX()
forms but they all produce junk.
2. Also, how do you read this 2 byte flag indicator?
I have read the flag using multiple forms
of raf.read() and raf.readX(), but none of them ouput 00. For example the following outputs 2. So I must not be reading it correctly.
byte[] record = new byte[2];
System.out.println(raf.read(record));
 
Ranch Hand
Posts: 435
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well I used file channels and put...
byte[] flag ={-128,0};
into a bytebuffer and then wrote it to the channel.
Or you can use any of the methods in RandomAccessFile or DataOutputStream.
Remember when you write the actual fields to the file that they have to be encoded.
Tony
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you can cast 0x8000 to a short and use a file channel or a stream to write it to output. or you could use RandomAccessFile's writeShort(int) method.
 
Bill Robertson
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any help on number 2:
2. Also, how do you read this 2 byte flag indicator?
I have read the flag using multiple forms
of raf.read() and raf.readX(), but none of them ouput 00. For example the following outputs 2. So I must not be reading it correctly.
byte[] record = new byte[2];
System.out.println(raf.read(record));

--------------------------------------------------------------------------------
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, Bill,
Did you try RandomAccessFile's readShort()?
Regards
Davidd
 
Bill Robertson
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 don't know how i skipped over trying to test that one but it
works. thanks Davidd !!!
 
An elephant? An actual elephant. Into the apartment. How is the floor still here. Hold this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic