Use try-with-resources

This commit is contained in:
TacoTheDank
2022-09-02 03:04:30 -04:00
committed by Cameron Gutman
parent 51594e00b8
commit a96e508ffb
11 changed files with 97 additions and 134 deletions

View File

@@ -154,21 +154,15 @@ public class DiskAssetLoader {
}
public void populateCacheWithStream(CachedAppAssetLoader.LoaderTuple tuple, InputStream input) {
OutputStream out = null;
boolean success = false;
try {
out = CacheHelper.openCacheFileForOutput(cacheDir, "boxart", tuple.computer.uuid, tuple.app.getAppId() + ".png");
try (final OutputStream out = CacheHelper.openCacheFileForOutput(
cacheDir, "boxart", tuple.computer.uuid, tuple.app.getAppId() + ".png")
) {
CacheHelper.writeInputStreamToOutputStream(input, out, MAX_ASSET_SIZE);
success = true;
} catch (IOException e) {
e.printStackTrace();
} finally {
if (out != null) {
try {
out.close();
} catch (IOException ignored) {}
}
if (!success) {
LimeLog.warning("Unable to populate cache with tuple: "+tuple);
CacheHelper.deleteCacheFile(cacheDir, "boxart", tuple.computer.uuid, tuple.app.getAppId() + ".png");