mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-28 21:06:50 +01:00
Close stream on error and log exception
This commit is contained in:
parent
bf29814294
commit
ef2bbf13c7
@ -123,14 +123,7 @@ public class GB {
|
||||
dir.mkdirs();
|
||||
}
|
||||
}
|
||||
FileOutputStream fos;
|
||||
try {
|
||||
fos = new FileOutputStream(dir + "/" + filename);
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
try (FileOutputStream fos = new FileOutputStream(dir + "/" + filename)) {
|
||||
ByteBuffer headerbuf = ByteBuffer.allocate(FILE_HEADER_SIZE + INFO_HEADER_SIZE + screenshot.clut.length);
|
||||
headerbuf.order(ByteOrder.LITTLE_ENDIAN);
|
||||
|
||||
@ -154,7 +147,6 @@ public class GB {
|
||||
headerbuf.putInt(2); // number of colors in CLUT
|
||||
headerbuf.putInt(2); // numbers of used colors
|
||||
headerbuf.put(screenshot.clut);
|
||||
try {
|
||||
fos.write(headerbuf.array());
|
||||
int rowbytes = screenshot.width / 8;
|
||||
byte[] pad = new byte[rowbytes % 4];
|
||||
@ -162,11 +154,11 @@ public class GB {
|
||||
fos.write(screenshot.data, rowbytes * i, rowbytes);
|
||||
fos.write(pad);
|
||||
}
|
||||
fos.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
LOG.error("Error saving screenshot", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user