Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save jpg file successfully but it can not be opened when use BufferedOutputStream #391

Open
evanyixie opened this issue Jul 5, 2023 · 0 comments

Comments

@evanyixie
Copy link

Problem

The code below works well, and the jpg file can be open:

            val inputStream = context.contentResolver.openInputStream(mediaFile.uri)
            val outputStream = BufferedOutputStream(UsbFileOutputStream(file), chunkSize)
            val buffer = ByteArray(chunkSize)
            var len = 0
            while (inputStream!!.read(buffer).also { len = it } != -1) {
                outputStream.write(buffer, 0, len)
            }
            outputStream.flush()
            outputStream.close()
            inputStream.close()

But when I want to improve the performance, so I changed the buffer size of BufferedOutputStream to 10 * chunkSize:

          val outputStream = BufferedOutputStream(UsbFileOutputStream(file),  10 * chunkSize)

The jpg file can not be opened, may be it had been broken.

Expected behavior

The jpg file saved in USB device should be opened.

Actual behavior

The jpg file saved in USB device can not be opened, maybe it had been broken

I don't know how to solve this problem, would you help me? Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant