@Override public Object deserialize() throws SerializerException { return deserialize(file); }
@Test public void testDataChangeListenersWhenDeserialized() throws Exception { ConversationData data = new ConversationData(); File conversationFile = new File(conversationFolder.getRoot(), "conversation.bin"); new FileSerializer(conversationFile).serialize(data); data = (ConversationData) new FileSerializer(conversationFile).deserialize(); testConversationListeners(data); }
/** * Attempts to migrate from the legacy clear text format. * * @return <code>false</code> if failed. */ boolean migrateConversationData() throws SerializerException { long start = System.currentTimeMillis(); File legacyConversationDataFile = Util.getUnencryptedFilename(conversationDataFile); if (legacyConversationDataFile.exists()) { try { ApptentiveLog.d(CONVERSATION, "Migrating %sconversation data...", hasState(LOGGED_IN) ? "encrypted " : ""); FileSerializer serializer = isAuthenticated() ? new EncryptedFileSerializer(legacyConversationDataFile, getEncryptionKey()) : new FileSerializer(legacyConversationDataFile); conversationData = (ConversationData) serializer.deserialize(); ApptentiveLog.d(CONVERSATION, "Conversation data migrated (took %d ms)", System.currentTimeMillis() - start); return true; } finally { boolean deleted = legacyConversationDataFile.delete(); ApptentiveLog.d(CONVERSATION, "Legacy conversation file deleted: %b", deleted); } } return false; }
@Override public void serialize(Object object) throws SerializerException { file.getParentFile().mkdirs(); AtomicFile atomicFile = new AtomicFile(file); FileOutputStream stream = null; try { stream = atomicFile.startWrite(); serialize(stream, object); atomicFile.finishWrite(stream); } catch (Exception e) { atomicFile.failWrite(stream); throw new SerializerException(e); } }
/** * Saves conversation data to the disk synchronously. Returns <code>true</code> * if succeed. */ private synchronized void saveConversationData() throws SerializerException { if (ApptentiveLog.canLog(ApptentiveLog.Level.VERBOSE)) { ApptentiveLog.v(CONVERSATION, "Saving conversation data..."); ApptentiveLog.v(CONVERSATION, "EventData: %s", getEventData().toString()); ApptentiveLog.v(CONVERSATION, "Messages: %s", messageManager.getMessageStore().toString()); } long start = System.currentTimeMillis(); FileSerializer serializer = new EncryptedFileSerializer(conversationDataFile, encryptionKey); serializer.serialize(conversationData); ApptentiveLog.v(CONVERSATION, "Conversation data saved (took %d ms)", System.currentTimeMillis() - start); }
void loadConversationData() throws SerializerException { long start = System.currentTimeMillis(); FileSerializer serializer = new EncryptedFileSerializer(conversationDataFile, encryptionKey); ApptentiveLog.d(CONVERSATION, "Loading conversation data..."); conversationData = (ConversationData) serializer.deserialize(); ApptentiveLog.d(CONVERSATION, "Conversation data loaded (took %d ms)", System.currentTimeMillis() - start); }