<p>I am developing a J2ME application that has a large amount of data to store on the device (in the region of 1MB but variable). I can't rely on the file system so I'm stuck the Record Management System (RMS), which allows multiple record stores but each have a limited size. My initial target platform, Blackberry, limits each to 64KB.</p>

<p>I'm wondering if anyone else has had to tackle the problem of storing a large amount of data in the RMS and how they managed it? I'm thinking of having to calculate record sizes and split one data set accross multiple stores if its too large, but that adds a lot of complexity to keep it intact.</p>

<p>There is lots of different types of data being stored but only one set in particular will exceed the 64KB limit.</p>

[{'answer_id': 19504, 'author': 'Anders Sandvig', 'author_id': 1709, 'author_profile': 'https://Stackoverflow.com/users/1709', 'pm_score': 2, 'selected': False, 'text': '<p>I think the most flexible approach would be to implement your own file system on top of the RMS. You can handle the RMS records in a similar way as blocks on a hard drive and use a <a href="http://en.wikipedia.org/wiki/Inode" rel="nofollow noreferrer">inode structure</a> or similar to spread logical files over multiple blocks. I would recommend implementing a byte or stream-oriented interface on top of the blocks, and then possibly making another API layer on top of that for writing special data structures (or simply make your objects serializable to the data stream).</p>\n\n<p><a href="https://rads.stackoverflow.com/amzn/click/com/0136006639" rel="nofollow noreferrer" rel="nofollow noreferrer">Tanenbaum\'s classical book on operating systems</a> covers how to implement a simple file system, but I am sure you can find other resources online if you don\'t like paper.</p>\n'}, {'answer_id': 25956, 'author': 'izb', 'author_id': 974, 'author_profile': 'https://Stackoverflow.com/users/974', 'pm_score': 2, 'selected': False, 'text': '<p>RMS performance and implementation varies wildly between devices, so if platform portability is a problem, you may find that your code works well on some devices and not others. RMS is designed to store small amounts of data (High score tables, or whatever) not large amounts.</p>\n\n<p>You might find that some platforms are faster with files stored in multiple record stores. Some are faster with multiple records within one store. Many are ok for storage, but become unusably slow when deleting large amounts of data from the store.</p>\n\n<p>Your best bet is to use JSR-75 instead where available, and create your own file store interface that falls back to RMS if nothing better is supported.</p>\n\n<p>Unfortunately when it comes to JavaME, you are often drawn into writing device-specific variants of your code.</p>\n'}, {'answer_id': 62837, 'author': 'Carlos Carrasco', 'author_id': 7027, 'author_profile': 'https://Stackoverflow.com/users/7027', 'pm_score': 4, 'selected': True, 'text': '<p>For anything past a few kilobytes you need to use either JSR 75 or a remote server. RMS records are extremely limited in size and speed, even in some higher end handsets. If you need to juggle 1MB of data in J2ME the only reliable, portable way is to store it on the network. The HttpConnection class and the GET and POST methods are always supported.</p>\n\n<p>On the handsets that support JSR 75 FileConnection it may be valid alternative but without code signing it is an user experience nightmare. Almost every single API call will invoke a security prompt with no blanket permission choice. Companies that deploy apps with JSR 75 usually need half a dozen binaries for every port just to cover a small part of the possible certificates. And this is just for the manufacturer certificates; some handsets only have carrier-locked certificates.</p>\n'}, {'answer_id': 81258, 'author': 'Stephen Denne', 'author_id': 11721, 'author_profile': 'https://Stackoverflow.com/users/11721', 'pm_score': 1, 'selected': False, 'text': "<p>I'm just starting to code for JavaME, but have experience with old versions of PalmOS, where all data chunks are limited in size, requiring the design of data structures using record indexes and offsets.</p>\n"}, {'answer_id': 83187, 'author': 'Richard', 'author_id': 7740, 'author_profile': 'https://Stackoverflow.com/users/7740', 'pm_score': 2, 'selected': False, 'text': "<p>Under Blackberry OS 4.6 the RMS store size limit has been increased to 512Kb but this isn't much help as many devices will likely not have support for 4.6. The other option on Blackberry is the Persistent Store which has a record size limit of 64kb but no limit on the size of the store (other than the physical limits of the device). </p>\n\n<p>I think Carlos and izb are right.</p>\n"}, {'answer_id': 86314, 'author': 'Honza', 'author_id': 8621, 'author_profile': 'https://Stackoverflow.com/users/8621', 'pm_score': 2, 'selected': False, 'text': '<p>It is quite simple, use JSR75 (FileConnection) and remember to sign your midlet with a valid (trusted) certificate.</p>\n'}, {'answer_id': 96542, 'author': 'roryf', 'author_id': 270, 'author_profile': 'https://Stackoverflow.com/users/270', 'pm_score': 1, 'selected': False, 'text': "<p>Thanks everyone for useful commments. In the end the simplest solution was to limit the amount of data being stored, implementing code that adjusts the data according to how large the store is, and fetching data from the server on demand if its not stored locally. Thats interesting that the limit is increased in OS 4.6, with any luck my code will simply adjust on its own and store more data :)</p>\n\n<p>Developing a J2ME application for Blackberry without using the .cod compiler limits the use of JSR 75 some what since we can't sign the archive. As pointed out by Carlos this is a problem on any platform and I've had similar issues using the PIM part of it. The RMS seems to be incredibly slow on the Blackberry platform so I'm not sure how useful a inode/b-tree file system on top would be, unless data was cached in memory and written to RMS in a low priority background thread.</p>\n"}, {'answer_id': 1660340, 'author': 'dhill', 'author_id': 69769, 'author_profile': 'https://Stackoverflow.com/users/69769', 'pm_score': 2, 'selected': False, 'text': "<p>For read only I'm arriving at acceptable times (within 10s), by indexing a resource file. I've got two ~800KB CSV price list exports. Program classes and both those files compress to a 300KB JAR.</p>\n\n<p>On searching I display a <code>List</code> and run a two <code>Thread</code>s in the background to fill it, so the first results come pretty quickly and are viewable immediately. I first implemented a simple linear search, but that was too slow (~2min). </p>\n\n<p>Then I indexed the file (which is alphabetically sorted) to find the beginnings of each letter. Now before parsing line by line, I first <code>InputStreamReader.skip()</code> to the desired position, based on first letter. I suspect the delay comes mostly from decompressing the resource, so splitting resources would speed it up further. I don't want to do that, not to loose the advantage of easy upgrade. CSV are exported without any preprocessing.</p>\n"}]
['https://Stackoverflow.com/questions/19011', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/270/']