close the stream

pull/847/head
Shrasti 5 years ago
parent 8b8b565f21
commit 607e85f6e3
  1. 15
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraUtils.java

@ -105,16 +105,27 @@ public class CameraUtils {
@WorkerThread @WorkerThread
@SuppressLint("NewApi") @SuppressLint("NewApi")
public static Uri writeToFile(Context context, @NonNull final byte[] data, @NonNull Uri file) { public static Uri writeToFile(Context context, @NonNull final byte[] data, @NonNull Uri file) {
OutputStream stream = null;
Uri result;
try { try {
ParcelFileDescriptor fd = context.getContentResolver().openFileDescriptor(file, "w"); ParcelFileDescriptor fd = context.getContentResolver().openFileDescriptor(file, "w");
OutputStream stream = new ParcelFileDescriptor.AutoCloseOutputStream(fd); stream = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
stream.write(data); stream.write(data);
stream.flush(); stream.flush();
result = file;
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
return null;
} finally { } finally {
return file; try {
if (stream != null) {
stream.close();
}
} catch (Exception ignored) {
}
} }
return result;
} }

Loading…
Cancel
Save