Skip to content

Use FileUtils.copy - #287

Open
sesam wants to merge 1 commit into
smolcars:masterfrom
sesam:patch-5
Open

Use FileUtils.copy#287
sesam wants to merge 1 commit into
smolcars:masterfrom
sesam:patch-5

Conversation

@sesam

@sesam sesam commented Mar 7, 2021

Copy link
Copy Markdown
Contributor

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

hsjoberg commented Mar 8, 2021

Copy link
Copy Markdown
Member

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

@hsjoberg hsjoberg left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

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