- if (fileChannel == null) {
- return;
- }
- var rootNode = jsonProcessor.createObjectNode();
- rootNode.put("username", username)
- .put("uuid", uuid == null ? null : uuid.toString())
- .put("deviceId", deviceId)
- .put("isMultiDevice", isMultiDevice)
- .put("password", password)
- .put("registrationId", identityKeyStore.getLocalRegistrationId())
- .put("identityPrivateKey",
- Base64.getEncoder()
- .encodeToString(identityKeyStore.getIdentityKeyPair().getPrivateKey().serialize()))
- .put("identityKey",
- Base64.getEncoder()
- .encodeToString(identityKeyStore.getIdentityKeyPair().getPublicKey().serialize()))
- .put("registrationLockPin", registrationLockPin)
- .put("pinMasterKey",
- pinMasterKey == null ? null : Base64.getEncoder().encodeToString(pinMasterKey.serialize()))
- .put("storageKey",
- storageKey == null ? null : Base64.getEncoder().encodeToString(storageKey.serialize()))
- .put("preKeyIdOffset", preKeyIdOffset)
- .put("nextSignedPreKeyId", nextSignedPreKeyId)
- .put("profileKey", Base64.getEncoder().encodeToString(profileKey.serialize()))
- .put("registered", registered)
- .putPOJO("groupStore", groupStore)
- .putPOJO("stickerStore", stickerStore);
- try {
- try (var output = new ByteArrayOutputStream()) {
- // Write to memory first to prevent corrupting the file in case of serialization errors
- jsonProcessor.writeValue(output, rootNode);
- var input = new ByteArrayInputStream(output.toByteArray());
- synchronized (fileChannel) {
+ synchronized (fileChannel) {
+ var rootNode = jsonProcessor.createObjectNode();
+ rootNode.put("username", username)
+ .put("uuid", uuid == null ? null : uuid.toString())
+ .put("deviceId", deviceId)
+ .put("isMultiDevice", isMultiDevice)
+ .put("password", password)
+ .put("registrationId", identityKeyStore.getLocalRegistrationId())
+ .put("identityPrivateKey",
+ Base64.getEncoder()
+ .encodeToString(identityKeyStore.getIdentityKeyPair().getPrivateKey().serialize()))
+ .put("identityKey",
+ Base64.getEncoder()
+ .encodeToString(identityKeyStore.getIdentityKeyPair().getPublicKey().serialize()))
+ .put("registrationLockPin", registrationLockPin)
+ .put("pinMasterKey",
+ pinMasterKey == null ? null : Base64.getEncoder().encodeToString(pinMasterKey.serialize()))
+ .put("storageKey",
+ storageKey == null ? null : Base64.getEncoder().encodeToString(storageKey.serialize()))
+ .put("preKeyIdOffset", preKeyIdOffset)
+ .put("nextSignedPreKeyId", nextSignedPreKeyId)
+ .put("profileKey", Base64.getEncoder().encodeToString(profileKey.serialize()))
+ .put("registered", registered)
+ .putPOJO("groupStore", groupStore)
+ .putPOJO("stickerStore", stickerStoreStorage);
+ try {
+ try (var output = new ByteArrayOutputStream()) {
+ // Write to memory first to prevent corrupting the file in case of serialization errors
+ jsonProcessor.writeValue(output, rootNode);
+ var input = new ByteArrayInputStream(output.toByteArray());