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

Android - The file reading code is written with an error #427

Closed
AleksMx opened this issue Oct 5, 2020 · 6 comments
Closed

Android - The file reading code is written with an error #427

AleksMx opened this issue Oct 5, 2020 · 6 comments
Labels
android Issue applies to Android platform triage Further information is requested

Comments

@AleksMx
Copy link

AleksMx commented Oct 5, 2020

I encountered a strange behavior of the plugin. Sometimes when a user selects a file, the file is read broken.

So I looked at how the file is read.

In the method "public static FileInfo openFileStream(final Context context, final Uri uri, boolean withData)" of FileUtils class a lot of errors.

  1. Why do you need to cache the file after user selection? This causes the cache to fill up.
  2. After you have copied the file. You re-read it again. What for?
  3. But before you read the file again, you do not close its descriptor for writing... But after you read the copy of the file, you flush the copy of the file to the flash memory.

So, if a user selected a file for the first time and by the time it had not been flushed to disk, then the file will be read not all.

I have fixed the code. But I need to figure out what to do with caching. Why is it needed?

@AleksMx AleksMx added the new issue An issue that hasn't yet been seen from the maintainer label Oct 5, 2020
@miguelpruivo
Copy link
Owner

@AleksMx hi, this has been answered multiple times. You can check here the explanation for your 1. and 3. points.

As for the 2. that happens because if the user wants the data to be loaded into memory, the file has to be read back again into it — which isn’t impossible while caching unless I use the buffer array reader but it could result in out of memory exceptions as its not efficient compared to File input reader.

I had no one reporting “a lot of errors” or even one with that class method, but if you found one, please post it with details and I’m happy to fix it.

Thank you!

@miguelpruivo miguelpruivo added android Issue applies to Android platform triage Further information is requested and removed new issue An issue that hasn't yet been seen from the maintainer labels Oct 5, 2020
@AleksMx
Copy link
Author

AleksMx commented Oct 6, 2020

@AleksMx hi, this has been answered multiple times. You can check here the explanation for your 1. and 3. points.

As for the 2. that happens because if the user wants the data to be loaded into memory, the file has to be read back again into it — which isn’t impossible while caching unless I use the buffer array reader but it could result in out of memory exceptions as its not efficient compared to File input reader.

I had no one reporting “a lot of errors” or even one with that class method, but if you found one, please post it with details and I’m happy to fix it.

Thank you!

If user wants the data to be loaded into memory, it is not necessary to cache the file. Because if you have content of the file, you don't need to have it's path.

File should be flushed before reading it and not after. And if you close the file descriptor it's not necessary to flush it.

@miguelpruivo
Copy link
Owner

@AleksMx flushing might make sense but I don’t get your first statement. One thing is the path, other is the content (bytes loaded into memory).

@miguelpruivo
Copy link
Owner

Closing due to inactivity. Feel free to reopen if you still have this issue. Thank you!

@AleksMx
Copy link
Author

AleksMx commented Oct 13, 2020

Closing due to inactivity. Feel free to reopen if you still have this issue. Thank you!

Plugin still have this issue. I fixed it locally.

@miguelpruivo
Copy link
Owner

@AleksMx mind to issue a PR with it? Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Issue applies to Android platform triage Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants