Package javax.microedition.rms

Examples of javax.microedition.rms.RecordStore


        try {
            DataInputStream din;

            try {
                RecordStore rs = RecordStore.openRecordStore(rsStateName, false);
                byte[] data = rs.getRecord(1);
                rs.closeRecordStore();
                din = new DataInputStream(new ByteArrayInputStream(data));
                if (!din.readUTF().equals(version)) {
                    din = null;
                    //#ifdef debug
                    System.out.println("Clean run: Version mismatch!");
View Full Code Here


            menuScreen.save(dout);
            wc.setProgress(20);
            timeSystem.save(dout);
            wc.setProgress(30);
            byte[] data = baos.toByteArray();
            RecordStore rs = RecordStore.openRecordStore(rsStateName, true);
            try {
                rs.setRecord(1, data, 0, data.length);
            } catch (InvalidRecordIDException e) {
                rs.addRecord(data, 0, data.length);
            }
            rs.closeRecordStore();
        } catch (Exception e) {
            //#if debug
            e.printStackTrace();
            //#endif
        }
View Full Code Here

    Vector paths;

    public void open(boolean clean) {
        if (!clean) {
            try {
                RecordStore rs = RecordStore.openRecordStore(rsName, false);
                byte[] data = rs.getRecord(1);
                rs.closeRecordStore();

                restore(new ByteArrayInputStream(data));
            } catch (RecordStoreNotFoundException e) {
                // DO NOTHING
            } catch (Exception e) {
View Full Code Here

        try {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            save(baos);

            byte[] data = baos.toByteArray();
            RecordStore rs = RecordStore.openRecordStore(rsName, true);
            try {
                rs.setRecord(1, data, 0, data.length);
            } catch (InvalidRecordIDException e) {
                rs.addRecord(data, 0, data.length);
            }
            rs.closeRecordStore();
        } catch (Exception e) {
            //#ifdef debug
            e.printStackTrace();
            //#endif
        }
View Full Code Here

  server_services = new Vector(1,1);
  Datas.gateways = new Vector(3, 1);
  images = new Contents();
  port = TCP_PORT;
  boolean default_flag = false;
  RecordStore rs = null;
  try {
    rs = RecordStore.openRecordStore("MyOptions",true);
  }catch (RecordStoreException ex) {
    jid = new Jid("username@localhost/JabberMix");
           password = "password";
     server_name = "localhost";
    
   
    return;
   
  }
 
  //get record in order
  byte b[] = null;
  byte b1[] = null;
  byte b2[] = null;
  byte b3[] = null;
  byte b4[] = null;
  byte b5[] = null;
  byte b6[] = null;
  byte b7[] = null;
 
  try {
    b = rs.getRecord(1);
    b1 = rs.getRecord(2);
    b2 = rs.getRecord(3);
    b3 = rs.getRecord(4);
    b4 = rs.getRecord(5);
    b5 = rs.getRecord(6);
    b6 = rs.getRecord(7);
    b7 = rs.getRecord(8);
  }catch (RecordStoreNotOpenException e) {
    default_flag = true;
  }catch (InvalidRecordIDException e1) {
    default_flag = true;
  }catch (RecordStoreException e2) {
    default_flag = true;
  }
  if (default_flag) {//default options
    jid = new Jid("username@localhost/JabberMix");
           password = "password";
     server_name = "localhost";
    
   
  }
  else { //the records exist
    jid = new Jid(new String(b, 0, b.length));
   
    password = new String(b1, 0, b1.length);
 
    server_name = new String(b2, 0, b2.length);
   
    String ssl = new String(b3, 0, b3.length);
   
    String mail = new String(b4, 0, b4.length);

    subdomain = new String(b5, 0, b5.length);

    if (subdomain.equals("null"))
    {

      subdomain = null;
      hostname = server_name;
    }
    else
      hostname = subdomain;
    if (ssl.toLowerCase().equals("yes")) {
      isSSL = true;
      port = SSL_PORT; ;
    }
    else if (ssl.toLowerCase().equals("http")) {
      isHTTP = true;
      port = HTTP_PORT;
    }
    else {
      isSSL = false;
      port = TCP_PORT;
    }
   
    if (mail.equals("null"))
    {
      jid.setMail("");
     
    }
    else
      jid.setMail(mail);
   
    noData = false; //data set
     
    //Set AVATAR
   
    avatarFile = new String(b6, 0, b6.length);
    if (avatarFile != null && avatarFile.equals("null"))
      avatarFile = null;
    setJidAvatar();
   
    customPort = new String(b7, 0, b7.length);
    if (customPort != null && !customPort.equals(""))
      port = Integer.parseInt(customPort);
   
  }
        try{
    rs.closeRecordStore();
  }catch (RecordStoreException exc1){
    System.out.println(exc1.getMessage());
  }

View Full Code Here

     *Save user jid info in persistent storage (RMS)
     *@author Gabriele Bianchi
     *@return boolean
     */
    public static boolean saveRecord() {
  RecordStore rs = null;
  try {
    rs = RecordStore.openRecordStore("MyOptions",true);
  }catch (RecordStoreException ex) {
    return false;
  }
  //insert
  try {
  if (rs.getNumRecords() == 0) {
   
    byte bytes[] = jid.getFullJid().getBytes();
    try {
      rs.addRecord(bytes,0,bytes.length);
      bytes = password.getBytes();
      rs.addRecord(bytes,0,bytes.length);
      bytes = server_name.getBytes();
      rs.addRecord(bytes,0,bytes.length);
      if (isSSL) {
        bytes = "yes".getBytes();
        port = SSL_PORT;
      }
      else if (isHTTP) {
        bytes = "http".getBytes();
        port = HTTP_PORT;
      }
      else {
        bytes = "no".getBytes();
        port = TCP_PORT;
      }
      rs.addRecord(bytes,0,bytes.length);
      if (jid.getMail() == null || jid.getMail().equals(""))
        bytes = "null".getBytes();
      else
        bytes = jid.getMail().getBytes();
      rs.addRecord(bytes,0,bytes.length);
      if (subdomain == null)
        bytes = "null".getBytes();
      else
        bytes = subdomain.getBytes();
      rs.addRecord(bytes, 0, bytes.length);
      if (Datas.avatarFile == null)
        bytes = "null".getBytes();
      else
        bytes = Datas.avatarFile.getBytes(); //AVATAR
      rs.addRecord(bytes, 0, bytes.length);
     
      if (Datas.customPort.equals("")) {
        customPort = String.valueOf(port); //custom port
      }
      else
        port = Integer.parseInt(customPort);
      bytes = customPort.getBytes(); //custom port
      rs.addRecord(bytes, 0, bytes.length);
     
      noData = false; //data set
    }catch (RecordStoreException exc2){
      System.out.println(exc2.getMessage());
      try{
        rs.closeRecordStore();
      }catch (RecordStoreException exc1){
        System.out.println(exc1.getMessage());
        return false;
      }
      return false;
    }
   
   
   
  }
  //update
  else {
    byte bytes[] = jid.getFullJid().getBytes();
    try {
      rs.setRecord(1,bytes,0,bytes.length);
      bytes = password.getBytes();
      rs.setRecord(2,bytes,0,bytes.length);
      bytes = server_name.getBytes();
      rs.setRecord(3,bytes,0,bytes.length);
      if (isSSL){
        bytes = "yes".getBytes();
        port = SSL_PORT;
      }
      else if (isHTTP) {
        bytes = "http".getBytes();
        port = HTTP_PORT;
      }
      else {
        bytes = "no".getBytes();
        port = TCP_PORT;
      }
      rs.setRecord(4,bytes,0,bytes.length);
      if (jid.getMail() == null || jid.getMail().equals(""))
        bytes = "null".getBytes();
      else
        bytes = jid.getMail().getBytes();
      rs.setRecord(5,bytes,0,bytes.length);
      if (subdomain == null)
        bytes = "null".getBytes();
      else
        bytes = subdomain.getBytes();
      rs.setRecord(6, bytes, 0, bytes.length);
     
      //AVATAR
      if (avatarFile == null)
        bytes = "null".getBytes();
      else
        bytes = avatarFile.getBytes();
      rs.setRecord(7, bytes, 0, bytes.length);
     
      if (customPort.equals("")) {
        //bytes = "null".getBytes();
        customPort = String.valueOf(port);
      }
      else
        port = Integer.parseInt(customPort);
      bytes = customPort.getBytes();
      rs.setRecord(8, bytes, 0, bytes.length);
     
      noData = false; //data set
    }catch (RecordStoreException exc1){
      System.out.println(exc1.getMessage());
      try{
      rs.closeRecordStore();
      }catch (RecordStoreException exc2){
        System.out.println(exc2.getMessage());
        return false;
      }
      return false;
    }
  }
  }catch (RecordStoreNotOpenException exc3){
 
  try{
    rs.closeRecordStore();
  }catch (RecordStoreException exc1){return false;
  }
  return false;
  }
  try{
    rs.closeRecordStore();
  }catch (RecordStoreException exc1){return false;
  }
  return true;
    }
View Full Code Here

     * @throws DataAccessException
     **/
    public void setLastTimestamp(long lastTimestamp)
    throws DataAccessException {

        RecordStore recordStore = null;

        try {

            recordStore = RecordStore.openRecordStore(TIMESTAMP_RECORDSTORE, true);

            int numRecords = recordStore.getNumRecords();

            String recordValue = String.valueOf(lastTimestamp);

            if (numRecords == 1) {
               
                recordStore.setRecord(1, recordValue.getBytes(), 0, (recordValue.getBytes()).length);
            } else {
               
                recordStore.addRecord(recordValue.getBytes(), 0, (recordValue.getBytes()).length);
            }


        } catch (Exception e) {
           
            StaticDataHelper.log("error:" + e.getMessage());
            throw new DataAccessException(e.getMessage());
        } finally {
           
            if (recordStore != null) {
               
                try {
                   
                    recordStore.closeRecordStore();
                    recordStore = null;
                } catch (Exception e) {
                   
                    throw new DataAccessException(e.getMessage());
                }
View Full Code Here

     * @throws DataAccessException
     **/
    public long getLastTimestamp()
    throws DataAccessException {

        RecordStore recordStore = null;

        long lastTimestamp = 0;

        try {

            recordStore = RecordStore.openRecordStore(TIMESTAMP_RECORDSTORE, true);

            int numRecords = recordStore.getNumRecords();

            if (numRecords == 0) {
                lastTimestamp = 0;
            } else {
                lastTimestamp = Long.parseLong(new String(recordStore.getRecord(1)));
            }

        } catch (Exception e) {
            StaticDataHelper.log("error:" + e.getMessage());
            throw new DataAccessException(e.getMessage());
        } finally {
            if (recordStore != null) {
                try {
                    recordStore.closeRecordStore();
                    recordStore = null;
                } catch (Exception e) {
                    throw new DataAccessException(e.getMessage());
                }
            }
View Full Code Here

     * @param lastTimestamp
     * @throws DataAccessException
     */
    public void setLastTimestamp(long lastTimestamp) throws DataAccessException
    {
        RecordStore recordStore = null;

        try
        {
            recordStore = RecordStore.openRecordStore(TIMESTAMP_RECORDSTORE, true);

            int numRecords = recordStore.getNumRecords();

            String recordValue = String.valueOf(lastTimestamp);

            if (numRecords == 1)
            {
                recordStore.setRecord(1, recordValue.getBytes(), 0, (recordValue.getBytes()).length);
            }
            else
            {
                recordStore.addRecord(recordValue.getBytes(), 0, (recordValue.getBytes()).length);
            }
        }
        catch (Exception e)
        {
            StaticDataHelper.log("error:" + e.getMessage());
            throw new DataAccessException(e.getMessage());
        }
        finally
        {
            if (recordStore != null)
            {
                try
                {
                    recordStore.closeRecordStore();
                    recordStore = null;
                }
                catch (Exception e)
                {
                    throw new DataAccessException(e.getMessage());
View Full Code Here

     * @return last timestamp from dedicate recordstore
     * @throws DataAccessException
     */
    public long getLastTimestamp() throws DataAccessException
    {
        RecordStore recordStore = null;

        long lastTimestamp = 0;

        try
        {
            recordStore = RecordStore.openRecordStore(TIMESTAMP_RECORDSTORE, true);

            int numRecords = recordStore.getNumRecords();

            if (numRecords == 0)
            {
                lastTimestamp = 0;
            }
            else
            {
                lastTimestamp = Long.parseLong(new String(recordStore.getRecord(1)));
            }

        }
        catch (Exception e)
        {
            StaticDataHelper.log("error:" + e.getMessage());
            throw new DataAccessException(e.getMessage());
        }
        finally
        {
            if (recordStore != null)
            {
                try
                {
                    recordStore.closeRecordStore();
                    recordStore = null;
                }
                catch (Exception e)
                {
                    throw new DataAccessException(e.getMessage());
View Full Code Here

TOP

Related Classes of javax.microedition.rms.RecordStore

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.