100 likes | 234 Views
RMS – Persistent Storage, HTTP Connections. D303 Java Mobile. Persistent Storage. MIDP provides a way for MIDlets to persistently store data and retrieve it later This is a simple record-oriented database called the Record Management System (RMS)
E N D
RMS – Persistent Storage, HTTP Connections D303 Java Mobile
Persistent Storage • MIDP provides a way for MIDlets to persistently store data and retrieve it later • This is a simple record-oriented database called the Record Management System (RMS) • A MIDP database (or a record store) consists of a collection of records that remain persistent after the MIDlet exits
RMS • import javax.microedition.rms.* • import javax.microedition.io.* • import java.io.* • Record stores are binary files that are platform dependent
RMS APIs • The RMS APIs provide the following functionality: • Allow MIDlets to add and remove records within a record store. • Allow MIDlets in the same application to share records (access one another's record store directly). • Do not provide a mechanism for sharing records between MIDlets in different applications.
Record Stores • Data is stored as bytes in record stores • Data Streams are used to allow transfer of any data types to the record store • For each: RecordStore.openRecordStore there needs to be a corresponding close
Record Store • Create record store • Create streams for transferring data • two streams are created, data stream and byte stream • Write data to data stream • Write data stream to byte array and write record • Close record store
HTTP Connections • We can use a network enabled device to connect to a JSP/Servlet using HTTP • HTTP connection is made as a POST or a GET • GET simply adds the data to the URL so it is recommended that POST is used
HTTP Connection • Create HTTP connection passing URL of JSP • Set HTTP connection to POST • Set connection properties to enable reading of parameters • Create byte stream • Store data in byte array
HTTP Connection • Write byte array data to byte stream • Close byte stream – once stream is closed HTTP POST is created and data sent to JSP • Receive response from server • 200 – OK • 404 – Not Found • 500 – Internal Error
Conclusion • RMS and HTTP allow us to store data on a mobile device for transfer to our existing web application at a convenient time