I'm using ZipInputStream in following way (Code):
public InputStream getArtifactInputStream(InputStream contentInputStream)
throws ArtifactProviderException
{
ZipInputStream zipInputStream = new ZipInputStream(contentInputStream);
InputStream artifactContent=null;
Properties externalizedProperties = null;
ZipEntry ze=null;
try {
ze = zipInputStream.getNextEntry();
} catch (IOException e) {
throw new ArtifactProviderException(e);
}
boolean propertiesFound = false;
try {
while (ze != null) {
String name = ze.getName();
if(name.endsWith(PROP_EXTENSION) && !ze.isDirectory())
{
externalizedProperties = new java.util.Properties();
externalizedProperties.load(zipInputStream);
propertiesFound = true;
}
else if(name.endsWith(ARTIFACT_EXTENSION) && !ze.isDirectory())
{
artifactContent = zipInputStream;
artifactName = name.substring(name.lastIndexOf("/")+1, name.indexOf(ARTIFACT_EXTENSION));
break;
}
ze=zipInputStream.getNextEntry();
}
} catch (IOException e) {
throw new ArtifactProviderException(e);
}
return artifactContent;
}
The problem is i'm not sure if PROP_EXTENSION file will appear first or ARTIFACT_EXTENSION while looping on zipEntry, hence i can't use "break" in any of the these cases, if i don't use break the while loop completes the loop and at the end artifactContent points to zipInputStream which cotains 'null' zipEntry.
How do i solve this problem, is there any alternative here?
'contentInputStream' is basically jar or a zip.
Hope I'm able to explain the problem, please revert back if you need more details.
Thanks in advance, Piyush