• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RecordStore.setRecord(int, byte[], int, int)

 
Chris Gastin
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This question might need to be in Java 2 Micro Edition forum, but the reason I want to know if because I am studying for the SCMAD exam.

I undsertand thath e setRecor is for overwriting an existing record, but lets say the persited record is 24 bytes, and I am overwirting it with only 16 bytes of data. Will the remaining 8 bytes be overwritten?

For example:

Persitsed Record 1 is "My Persisted Record Value", and for the sake of conversation is 24 bytes. I think execute the following code to overwrite Record 1 with "New Record Value" whihc for sake of conversation is 16 bytes.



Will new record completly overwrite the previously persited record even though it is smaller size, or do you need to account for this?

Chris Gastin
SCJP 1.4
SCWCD
[ August 05, 2004: Message edited by: Chris Gastin ]
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The entire record will be overwritten. the two ints are for the offest and length of the byte[] array that you are submitting. The first int is the record number.

Mark
 
Chris Gastin
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Mark. I understand what the parameter are used for, but from my example, the size of the new record is smaller than the the existing record, so will it overwrite it completly


EEEEEEEEEEEEEEEEEEEEEEE -> Existing Record
NNNNNNNNNNNNNNNN -> New Record
NNNNNNNNNNNNNNNNEEEEEEE -> Is this the persisted data
NNNNNNNNNNNNNNNN -> Or this?

I hope this makes sense?
 
Sathya Srinivasan
Ranch Hand
Posts: 379
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Assuming that your call is

recordStore.setRecord(recordId, newData, 0, 16), the data stored will be "NNNNNNNNNNNNNNNN".

As per the API


Sets the data in the given record to that passed in. After this method returns, a call to getRecord(int recordId) will return an array of numBytes size containing the data supplied here.


This means that the next time you call a getRecord() to access the data, it will retrieve 16 bytes, which corresponds to the Ns.

In general, Java is an abstraction to the underlying layer and hence, hides all the byte manipulations. So, unlike C/C++, where you get back a pointer to the beginning address, in Java, you normally get the value of the data pointed out by the address, which will be massaged accordingly.
 
Chris Gastin
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sathya. Got it now. I thought that was how it was to respond, but wanted to make sure.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic