I\'m receiving a ZipInputStream from another source, and I need to provide the first entry\'s InputStream to another source.
I was hoping to be able to do this witho
The zip code is fairly easy but I had issues with returning ZipInputStream as Inputstream. For some reason, some of the files contained within the zip had characters being dropped. The below was my solution and so far its been working.
private Map getFilesFromZip(final DataHandler dhZ,
String operation) throws ServiceFault {
Map fileEntries = new HashMap();
try {
ZipInputStream zipIsZ = new ZipInputStream(dhZ.getDataSource()
.getInputStream());
try {
ZipEntry entry;
while ((entry = zipIsZ.getNextEntry()) != null) {
if (!entry.isDirectory()) {
Path p = Paths.get(entry.toString());
fileEntries.put(p.getFileName().toString(),
convertZipInputStreamToInputStream(zipIsZ));
}
}
}
finally {
zipIsZ.close();
}
} catch (final Exception e) {
faultLocal(LOGGER, e, operation);
}
return fileEntries;
}
private InputStream convertZipInputStreamToInputStream(
final ZipInputStream in) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(in, out);
InputStream is = new ByteArrayInputStream(out.toByteArray());
return is;
}