1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-14 06:51:08 +01:00

Use try-with-resources where possible

and make StanzaCollector implement AutoCloseable.
This commit is contained in:
Florian Schmaus 2019-02-04 09:36:37 +01:00
parent e98d42790a
commit 658fd08d20
10 changed files with 30 additions and 69 deletions

View file

@ -1,6 +1,6 @@
/**
*
* Copyright © 2011-2018 Florian Schmaus
* Copyright © 2011-2019 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -130,11 +130,8 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache
* @throws IOException
*/
private static void writeInfoToFile(File file, DiscoverInfo info) throws IOException {
DataOutputStream dos = new DataOutputStream(new FileOutputStream(file));
try {
try (DataOutputStream dos = new DataOutputStream(new FileOutputStream(file))) {
dos.writeUTF(info.toXML(null).toString());
} finally {
dos.close();
}
}
@ -146,12 +143,9 @@ public class SimpleDirectoryPersistentCache implements EntityCapsPersistentCache
* @throws Exception
*/
private static DiscoverInfo restoreInfoFromFile(File file) throws Exception {
DataInputStream dis = new DataInputStream(new FileInputStream(file));
String fileContent;
try {
try (DataInputStream dis = new DataInputStream(new FileInputStream(file))) {
fileContent = dis.readUTF();
} finally {
dis.close();
}
if (fileContent == null) {
return null;