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

Replace FileInputStream and FileOutputStream by their JDK7 equivalents #81

Open
lbruun opened this issue Nov 29, 2017 · 1 comment
Open

Comments

@lbruun
Copy link

lbruun commented Nov 29, 2017

Files.newInputStream() and Files.newOutputStream() are generally preferred over new FileInputStream() and new FileOutputStream().

The reason is is that FileInputStream and FileOutputStream have finalizers and therefore puts pressure on the GC. The finalizers will make sure the file descriptor is actually released if the developer has forgotten to explicitly close the fis or fos. But if this is taken care of, then there's no need to have the overhead that use of fis or fos implies.

It is not in all cases that a fis or a fos can be replaced with the JDK7 equivalents from Files class. But in the cases where the fis or fos doesn't escape the method then it can always be replaced and the hint would apply.

@markiewb
Copy link
Owner

@lbruun: Good idea, but I do not actively support this plugin anymore. Nevertheless you could provide a pull-request, which I will merge. See the existing classes and the tests to get started.

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

No branches or pull requests

2 participants