FileShuttle: use try-with-resource for FileOutputStream

This commit is contained in:
Peter Cai 2023-11-04 16:06:02 -04:00
parent 15516b0dde
commit edb8447d2d

View file

@ -284,14 +284,13 @@ public class FileShuttleService extends Service {
return null;
}
FileOutputStream os = new FileOutputStream(pair[1].getFileDescriptor());
// Send the bitmap into the pipe in another thread, so that we can return the
// reading fd to the Documents UI before we finish sending the Bitmap.
new Thread(() -> {
bmp.compress(Bitmap.CompressFormat.PNG, 100, os);
try {
try (FileOutputStream os = new FileOutputStream(pair[1].getFileDescriptor())) {
bmp.compress(Bitmap.CompressFormat.PNG, 100, os);
os.flush();
os.close();
} catch (IOException e) {
// ...
}