This commit is contained in:
AsamK 2016-10-31 17:51:05 +01:00
parent 6c9f26f49b
commit 93e2c58fcf
3 changed files with 17 additions and 17 deletions

View file

@ -19,7 +19,7 @@ public class JsonContactsStore {
@JsonDeserialize(using = ContactsDeserializer.class) @JsonDeserialize(using = ContactsDeserializer.class)
private Map<String, ContactInfo> contacts = new HashMap<>(); private Map<String, ContactInfo> contacts = new HashMap<>();
private static final ObjectMapper jsonProcessot = new ObjectMapper(); private static final ObjectMapper jsonProcessor = new ObjectMapper();
void updateContact(ContactInfo contact) { void updateContact(ContactInfo contact) {
contacts.put(contact.number, contact); contacts.put(contact.number, contact);
@ -47,7 +47,7 @@ public class JsonContactsStore {
Map<String, ContactInfo> contacts = new HashMap<>(); Map<String, ContactInfo> contacts = new HashMap<>();
JsonNode node = jsonParser.getCodec().readTree(jsonParser); JsonNode node = jsonParser.getCodec().readTree(jsonParser);
for (JsonNode n : node) { for (JsonNode n : node) {
ContactInfo c = jsonProcessot.treeToValue(n, ContactInfo.class); ContactInfo c = jsonProcessor.treeToValue(n, ContactInfo.class);
contacts.put(c.number, c); contacts.put(c.number, c);
} }

View file

@ -21,7 +21,7 @@ public class JsonGroupStore {
public static List<GroupInfo> groupsWithLegacyAvatarId = new ArrayList<>(); public static List<GroupInfo> groupsWithLegacyAvatarId = new ArrayList<>();
private static final ObjectMapper jsonProcessot = new ObjectMapper(); private static final ObjectMapper jsonProcessor = new ObjectMapper();
void updateGroup(GroupInfo group) { void updateGroup(GroupInfo group) {
groups.put(Base64.encodeBytes(group.groupId), group); groups.put(Base64.encodeBytes(group.groupId), group);
@ -49,7 +49,7 @@ public class JsonGroupStore {
Map<String, GroupInfo> groups = new HashMap<>(); Map<String, GroupInfo> groups = new HashMap<>();
JsonNode node = jsonParser.getCodec().readTree(jsonParser); JsonNode node = jsonParser.getCodec().readTree(jsonParser);
for (JsonNode n : node) { for (JsonNode n : node) {
GroupInfo g = jsonProcessot.treeToValue(n, GroupInfo.class); GroupInfo g = jsonProcessor.treeToValue(n, GroupInfo.class);
// Check if a legacy avatarId exists // Check if a legacy avatarId exists
if (g.getAvatarId() != 0) { if (g.getAvatarId() != 0) {
groupsWithLegacyAvatarId.add(g); groupsWithLegacyAvatarId.add(g);

View file

@ -93,7 +93,7 @@ class Manager implements Signal {
private FileChannel fileChannel; private FileChannel fileChannel;
private FileLock lock; private FileLock lock;
private final ObjectMapper jsonProcessot = new ObjectMapper(); private final ObjectMapper jsonProcessor = new ObjectMapper();
private String username; private String username;
private int deviceId = SignalServiceAddress.DEFAULT_DEVICE_ID; private int deviceId = SignalServiceAddress.DEFAULT_DEVICE_ID;
private String password; private String password;
@ -115,12 +115,12 @@ class Manager implements Signal {
this.attachmentsPath = this.settingsPath + "/attachments"; this.attachmentsPath = this.settingsPath + "/attachments";
this.avatarsPath = this.settingsPath + "/avatars"; this.avatarsPath = this.settingsPath + "/avatars";
jsonProcessot.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE); // disable autodetect jsonProcessor.setVisibility(PropertyAccessor.ALL, JsonAutoDetect.Visibility.NONE); // disable autodetect
jsonProcessot.enable(SerializationFeature.INDENT_OUTPUT); // for pretty print, you can disable it. jsonProcessor.enable(SerializationFeature.INDENT_OUTPUT); // for pretty print, you can disable it.
jsonProcessot.enable(SerializationFeature.WRITE_NULL_MAP_VALUES); jsonProcessor.enable(SerializationFeature.WRITE_NULL_MAP_VALUES);
jsonProcessot.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); jsonProcessor.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
jsonProcessot.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE); jsonProcessor.disable(JsonParser.Feature.AUTO_CLOSE_SOURCE);
jsonProcessot.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET); jsonProcessor.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
} }
public String getUsername() { public String getUsername() {
@ -229,7 +229,7 @@ class Manager implements Signal {
private void load() throws IOException { private void load() throws IOException {
openFileChannel(); openFileChannel();
JsonNode rootNode = jsonProcessot.readTree(Channels.newInputStream(fileChannel)); JsonNode rootNode = jsonProcessor.readTree(Channels.newInputStream(fileChannel));
JsonNode node = rootNode.get("deviceId"); JsonNode node = rootNode.get("deviceId");
if (node != null) { if (node != null) {
@ -250,11 +250,11 @@ class Manager implements Signal {
} else { } else {
nextSignedPreKeyId = 0; nextSignedPreKeyId = 0;
} }
signalProtocolStore = jsonProcessot.convertValue(getNotNullNode(rootNode, "axolotlStore"), JsonSignalProtocolStore.class); signalProtocolStore = jsonProcessor.convertValue(getNotNullNode(rootNode, "axolotlStore"), JsonSignalProtocolStore.class);
registered = getNotNullNode(rootNode, "registered").asBoolean(); registered = getNotNullNode(rootNode, "registered").asBoolean();
JsonNode groupStoreNode = rootNode.get("groupStore"); JsonNode groupStoreNode = rootNode.get("groupStore");
if (groupStoreNode != null) { if (groupStoreNode != null) {
groupStore = jsonProcessot.convertValue(groupStoreNode, JsonGroupStore.class); groupStore = jsonProcessor.convertValue(groupStoreNode, JsonGroupStore.class);
} }
if (groupStore == null) { if (groupStore == null) {
groupStore = new JsonGroupStore(); groupStore = new JsonGroupStore();
@ -262,7 +262,7 @@ class Manager implements Signal {
JsonNode contactStoreNode = rootNode.get("contactStore"); JsonNode contactStoreNode = rootNode.get("contactStore");
if (contactStoreNode != null) { if (contactStoreNode != null) {
contactStore = jsonProcessot.convertValue(contactStoreNode, JsonContactsStore.class); contactStore = jsonProcessor.convertValue(contactStoreNode, JsonContactsStore.class);
} }
if (contactStore == null) { if (contactStore == null) {
contactStore = new JsonContactsStore(); contactStore = new JsonContactsStore();
@ -294,7 +294,7 @@ class Manager implements Signal {
if (username == null) { if (username == null) {
return; return;
} }
ObjectNode rootNode = jsonProcessot.createObjectNode(); ObjectNode rootNode = jsonProcessor.createObjectNode();
rootNode.put("username", username) rootNode.put("username", username)
.put("deviceId", deviceId) .put("deviceId", deviceId)
.put("password", password) .put("password", password)
@ -309,7 +309,7 @@ class Manager implements Signal {
try { try {
openFileChannel(); openFileChannel();
fileChannel.position(0); fileChannel.position(0);
jsonProcessot.writeValue(Channels.newOutputStream(fileChannel), rootNode); jsonProcessor.writeValue(Channels.newOutputStream(fileChannel), rootNode);
fileChannel.truncate(fileChannel.position()); fileChannel.truncate(fileChannel.position());
fileChannel.force(false); fileChannel.force(false);
} catch (Exception e) { } catch (Exception e) {