if (groupsFile.exists() && groupsFile.length() > 0) {
FileInputStream contactsFileStream = new FileInputStream(groupsFile);
- SignalServiceAttachmentStream attachmentStream = SignalServiceAttachment.newStreamBuilder()
- .withStream(contactsFileStream)
- .withContentType("application/octet-stream")
- .withLength(groupsFile.length())
- .build();
-
- sendSyncMessage(SignalServiceSyncMessage.forGroups(attachmentStream));
+ try {
+ SignalServiceAttachmentStream attachmentStream = SignalServiceAttachment.newStreamBuilder()
+ .withStream(contactsFileStream)
+ .withContentType("application/octet-stream")
+ .withLength(groupsFile.length())
+ .build();
+
+ sendSyncMessage(SignalServiceSyncMessage.forGroups(attachmentStream));
+ } finally {
+ contactsFileStream.close();
+ }
}
} finally {
groupsFile.delete();