Use try-with-resources.
This commit is contained in:
parent
8bcf0c6498
commit
95333d37c8
8 changed files with 84 additions and 137 deletions
|
|
@ -80,24 +80,15 @@ public class Utility {
|
|||
@SuppressWarnings("unchecked")
|
||||
public static <T> T readFromFile(File file) {
|
||||
T object;
|
||||
ObjectInputStream objectInputStream = null;
|
||||
|
||||
try {
|
||||
objectInputStream = new ObjectInputStream(new FileInputStream(file));
|
||||
try (ObjectInputStream objectInputStream =
|
||||
new ObjectInputStream(new FileInputStream(file))) {
|
||||
object = (T) objectInputStream.readObject();
|
||||
} catch (Exception e) {
|
||||
Log.e("Utility", "Failed to deserialize the object", e);
|
||||
object = null;
|
||||
}
|
||||
|
||||
if (objectInputStream != null) {
|
||||
try {
|
||||
objectInputStream.close();
|
||||
} catch (Exception e) {
|
||||
//nothing to do
|
||||
}
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue