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

Using Zips.addEntries with FileSources that refer to directories results in exceptions #138

Open
lstreepy opened this issue Sep 17, 2020 · 0 comments

Comments

@lstreepy
Copy link

I was trying to use Zips to construct a zip file containing an arbitrary set of entries, using FileSource objects. However, if the FileSource refers to a directory, it results in a "Stream closed" exception:


	at java.io.BufferedInputStream.read(BufferedInputStream.java:345)
	at java.io.FilterInputStream.read(FilterInputStream.java:107)
	at org.zeroturnaround.zip.commons.IOUtils.copyLarge(IOUtils.java:322)
	at org.zeroturnaround.zip.commons.IOUtils.copyLarge(IOUtils.java:299)
	at org.zeroturnaround.zip.commons.IOUtils.copy(IOUtils.java:274)
	at org.zeroturnaround.zip.ZipEntryUtil.addEntry(ZipEntryUtil.java:131)
	at org.zeroturnaround.zip.ZipEntryUtil.copyEntry(ZipEntryUtil.java:115)
	at org.zeroturnaround.zip.Zips$CopyingCallback.process(Zips.java:655)
	at org.zeroturnaround.zip.ZipEntryOrInfoAdapter.process(ZipEntryOrInfoAdapter.java:26)
	at org.zeroturnaround.zip.Zips.iterateChangedAndAdded(Zips.java:569)
	... 4 more

I think the source of the bug is in this method: ZipEntryUtil#copyEntry(java.util.zip.ZipEntry, java.io.InputStream, java.util.zip.ZipOutputStream, boolean),
where on line 115 it does this: addEntry(copy, new BufferedInputStream(in), out)

Instead it should do this: addEntry(copy, in == null ? null : new BufferedInputStream(in), out) so the called method does not try to read from the input stream.

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

No branches or pull requests

1 participant