- DeviceGroupsInputStream s = new DeviceGroupsInputStream(retrieveAttachmentAsStream(syncMessage.getGroups().get().asPointer(), tmpFile));
- DeviceGroup g;
- while ((g = s.read()) != null) {
- GroupInfo syncGroup = groupStore.getGroup(g.getId());
- if (syncGroup == null) {
- syncGroup = new GroupInfo(g.getId());
- }
- if (g.getName().isPresent()) {
- syncGroup.name = g.getName().get();
- }
- syncGroup.members.addAll(g.getMembers());
- syncGroup.active = g.isActive();
-
- if (g.getAvatar().isPresent()) {
- retrieveGroupAvatarAttachment(g.getAvatar().get(), syncGroup.groupId);
+ try (InputStream attachmentAsStream = retrieveAttachmentAsStream(syncMessage.getGroups().get().asPointer(), tmpFile)) {
+ DeviceGroupsInputStream s = new DeviceGroupsInputStream(attachmentAsStream);
+ DeviceGroup g;
+ while ((g = s.read()) != null) {
+ GroupInfo syncGroup = groupStore.getGroup(g.getId());
+ if (syncGroup == null) {
+ syncGroup = new GroupInfo(g.getId());
+ }
+ if (g.getName().isPresent()) {
+ syncGroup.name = g.getName().get();
+ }
+ syncGroup.members.addAll(g.getMembers());
+ syncGroup.active = g.isActive();
+
+ if (g.getAvatar().isPresent()) {
+ retrieveGroupAvatarAttachment(g.getAvatar().get(), syncGroup.groupId);
+ }
+ groupStore.updateGroup(syncGroup);