Skip to content

Commit dee5774

Browse files
authored
perf: leverage use block when handling fileoutput stream (#95)
1 parent 363ec37 commit dee5774

File tree

1 file changed

+7
-5
lines changed
  • android/src/main/java/com/sourcetoad/reactnativesketchcanvas

1 file changed

+7
-5
lines changed

android/src/main/java/com/sourcetoad/reactnativesketchcanvas/SketchCanvas.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,13 @@ class SketchCanvas(context: ThemedReactContext) : View(context) {
362362
if (format == "png") ".png" else ".jpg"
363363
)
364364
try {
365-
bitmap.compress(
366-
if (format == "png") Bitmap.CompressFormat.PNG else Bitmap.CompressFormat.JPEG,
367-
if (format == "png") 100 else 90,
368-
FileOutputStream(file)
369-
)
365+
FileOutputStream(file).use { fos ->
366+
bitmap.compress(
367+
if (format == "png") Bitmap.CompressFormat.PNG else Bitmap.CompressFormat.JPEG,
368+
if (format == "png") 100 else 90,
369+
fos
370+
)
371+
}
370372
onSaved(true, file.path)
371373
} catch (e: Exception) {
372374
e.printStackTrace()

0 commit comments

Comments
 (0)