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

refactor: close resource in ZipFolder.java #2623

Merged
merged 3 commits into from
Oct 9, 2018
Merged

refactor: close resource in ZipFolder.java #2623

merged 3 commits into from
Oct 9, 2018

Conversation

zielint0
Copy link
Contributor

@zielint0 zielint0 commented Oct 4, 2018

Make sure a resource is properly released.

@pvojtechovsky
Pavel could you take a look on public List getFiles() and tell me if this algorithm is correct before and after change.

@monperrus
Copy link
Collaborator

LGTM. @pvojtechovsky do you merge?

Copy link
Collaborator

@pvojtechovsky pvojtechovsky left a comment

Choose a reason for hiding this comment

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

I added failing test and fix for the mentioned problem

ZipEntry entry;
while ((entry = zipInput.getNextEntry()) != null) {
// deflate in buffer
final int buffer = 2048;
ByteArrayOutputStream output = new ByteArrayOutputStream(buffer);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This code seems to be wrong.
The content of output will grow with each zip entry. Before, it was reset with each entry.
Solution:
A) create ByteArrayOutputStream in scope of while body, similar like before
B) call ByteArrayOutputStream#reset() method to clear it's content

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you Pavel. I felt there is something wrong with it.

Choose a reason for hiding this comment

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

Please consider using IOUtils from Apache.

@pvojtechovsky
Copy link
Collaborator

@monperrus please review my changes too and merge it - if ok. Thank you.

@monperrus monperrus merged commit 798ca3d into INRIA:master Oct 9, 2018
@monperrus
Copy link
Collaborator

Thanks for the added test, a new test is always valuable.

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.

4 participants