To Write in DB
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(myObj);
byte[] yourBytes = bos.toByteArray();
out.close();
bos.close();
String data = Base64.encodeToString(yourBytes, Base64.DEFAULT);
dbHelper.insertWeather(db, data);
To Read from DB
String data = cursor.getString(0);
ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decode(data, Base64.DEFAULT));
ObjectInput in = new ObjectInputStream(bis);
myObj = (POJO_My_Info)in.readObject();
bis.close();
in.close();;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(myObj);
byte[] yourBytes = bos.toByteArray();
out.close();
bos.close();
String data = Base64.encodeToString(yourBytes, Base64.DEFAULT);
dbHelper.insertWeather(db, data);
To Read from DB
String data = cursor.getString(0);
ByteArrayInputStream bis = new ByteArrayInputStream(Base64.decode(data, Base64.DEFAULT));
ObjectInput in = new ObjectInputStream(bis);
myObj = (POJO_My_Info)in.readObject();
bis.close();
in.close();;
No comments:
Post a Comment