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
@SuppressLint("NewApi")
public static Uri writeToFile(Context context, @NonNull final byte[] data, @NonNull Uri file) {
OutputStream stream = null;
Uri result;
try {
ParcelFileDescriptor fd = context.getContentResolver().openFileDescriptor(file, "w");
OutputStream stream = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
stream = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
stream.write(data);
stream.flush();
result = file;
} catch (IOException e) {
e.printStackTrace();
return null;
} finally {
return file;
try {
if (stream != null) {
stream.close();
}
} catch (Exception ignored) {
}
}
return result;
}

Loading…
Cancel
Save