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

Use FileUtils.copy #287

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Use FileUtils.copy #287

wants to merge 1 commit into from

Conversation

sesam
Copy link
Contributor

@sesam sesam commented Mar 7, 2021

Untested!
This assumes we have compileSdkVersion 29 or higher. This copy method might be faster, or if noting else, less own code to maintain.

I found this since the code scanner warned of potential memory leak (unclosed file descriptors) if copying fails. If using FileUtils won't work, we should add a finally block that ensures the Streams get closed and garbage collected.

Untested!
This assumes we have `compileSdkVersion 29` or higher. This copy method might be faster, or if noting else, less own code to maintain.

I found this since the code scanner warned of potential memory leak (unclosed file descriptors) if copying fails. If using FileUtils won't work, we should add a `finally` block that ensures the Streams get closed and garbage collected.
@hsjoberg
Copy link
Owner

hsjoberg commented Mar 8, 2021

Thanks for the pull request, I'll get back to you about this once I've tested it.

Copy link
Owner

@hsjoberg hsjoberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what FileUtils is referring to, I assume import org.apache.commons.io.FileUtils?

Apache Commons IO is currently not a dependency of the Java project, but could be added.

}
in.close();
out.close();
FileUtils.copy(new FileInputStream(source), new FileOutputStream(destination));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

-      FileUtils.copy(new FileInputStream(source), new FileOutputStream(destination));
+      FileUtils.copy(new FileInputStream(sourceLocation), new FileOutputStream(targetLocation));

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

Successfully merging this pull request may close these issues.

2 participants