Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
henryci
Posts: 23
Registered: ‎01-01-2009
My Device: Not Specified

Any clever way to append data to a persisted store object?

I am attempting to port an app to BlackBerry which appends String data to a file.  On the other platforms this isn't a problem because filesystem access is pretty straight forward and I just open the file for appending and it's easy to write the data.  However, this data shouldn't be stored on the user's Compact Flash device, and when I try and access file:///store/ I get a permissions dialog on some devices which is not an option.

 

So it looks like I'm stuck with the persisted store.   However, if the data ends up being large (say 100, 10 byte blobs), I don't want to be reading in and appending to an ever increasing string every time.  Is there some clever object, or way to use the persisted store that allows me to append data without re-consuming everything that is stored?  

 

-- Henry 

Please use plain text.
New Developer
henryci
Posts: 23
Registered: ‎01-01-2009
My Device: Not Specified

Re: Any clever way to append data to a persisted store object?

It seems like the MIDP RecordStore object support inserting data at a given position:

public int addRecord(byte[] data, int offset, int numBytes);

 

Assuming there is no similar functionality with the PersistentStore, is this a better way for me to append data to persistent storage?

 

-- Henry 

Please use plain text.
New Developer
henryci
Posts: 23
Registered: ‎01-01-2009
My Device: Not Specified

Re: Any clever way to append data to a persisted store object?

Nope that is completely wrong.  The buffer / offset for that argument exist only to facilitate storing parts of the data.  Using RecordStore does not allow appending of data without reading in the entire object, that I can tell.

 

Maybe somebody else will have an idea. :smileyhappy:

 

- Henry 

Please use plain text.
Developer
gregzav
Posts: 170
Registered: ‎01-17-2009
My Device: 9630

Re: Any clever way to append data to a persisted store object?

Since you said you get a permissions dialog I'm assuming you haven't signed your code, right?
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Any clever way to append data to a persisted store object?

Use PersistentStore.  For me the most compelling reason to use the file connection API is the size of the data.  You don't want to put photos or videos in persistent Store.  But in this case you are storing 100 10 bytes blob = 1,000 byes.  This is very small by persistent storage standards.  Also, using persistent store, adding a blob is very easy.  Create your Persistent Store object extending Vector and you just add an element.  You can consume everything by walking your Vector.

 

Minor point: external storage on a BlackBerry is SD Card not Compact Flash.

Please use plain text.
New Developer
henryci
Posts: 23
Registered: ‎01-01-2009
My Device: Not Specified

Re: Any clever way to append data to a persisted store object?

I signed my code, but on my older test device (8800) I get a dialog saying "app would like to access file:///store"

 

Do you have any advice on when the data becomes too great for the persisted store?

 

-- Henry 

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: Any clever way to append data to a persisted store object?

Signing allows the application to use RIM restricted APIs.  Permissions are what the application is allowed, by the user, to do, so is not related to signing.

 

I don't think that I can give you much advice about when data becomes too big, because that depends on the device and the other applications on the device.  However, given that the App Store application is 500 MB, I think you can persist quite a lot of data.

Please use plain text.
Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: Any clever way to append data to a persisted store object?

"You can consume everything by walking your Vector."

 

Presuming you want to actually find it however, I would advocate some type of indexing system.

You could even call it a database if that matters :smileyhappy:

 

Please use plain text.