use of org.hibernate.boot.archive.spi.InputStreamAccess in project hibernate-orm by hibernate.
the class JarInputStreamBasedArchiveDescriptor method visitArchive.
@Override
public void visitArchive(ArchiveContext context) {
final JarInputStream jarInputStream;
try {
jarInputStream = new JarInputStream(getArchiveUrl().openStream());
} catch (Exception e) {
//really should catch IOException but Eclipse is buggy and raise NPE...
URL_LOGGER.logUnableToFindFileByUrl(getArchiveUrl(), e);
return;
}
try {
JarEntry jarEntry;
while ((jarEntry = jarInputStream.getNextJarEntry()) != null) {
final String jarEntryName = jarEntry.getName();
if (getEntryBasePrefix() != null && !jarEntryName.startsWith(getEntryBasePrefix())) {
continue;
}
if (jarEntry.isDirectory()) {
continue;
}
if (jarEntryName.equals(getEntryBasePrefix())) {
// just any random entry
try {
final JarInputStream subJarInputStream = new JarInputStream(jarInputStream);
try {
ZipEntry subZipEntry = jarInputStream.getNextEntry();
while (subZipEntry != null) {
if (!subZipEntry.isDirectory()) {
final String subName = extractName(subZipEntry);
final InputStreamAccess inputStreamAccess = buildByteBasedInputStreamAccess(subName, subJarInputStream);
final ArchiveEntry entry = new ArchiveEntry() {
@Override
public String getName() {
return subName;
}
@Override
public String getNameWithinArchive() {
return subName;
}
@Override
public InputStreamAccess getStreamAccess() {
return inputStreamAccess;
}
};
context.obtainArchiveEntryHandler(entry).handleEntry(entry, context);
}
subZipEntry = jarInputStream.getNextJarEntry();
}
} finally {
subJarInputStream.close();
}
} catch (Exception e) {
throw new ArchiveException("Error accessing nested jar", e);
}
} else {
final String entryName = extractName(jarEntry);
final InputStreamAccess inputStreamAccess = buildByteBasedInputStreamAccess(entryName, jarInputStream);
final String relativeName = extractRelativeName(jarEntry);
final ArchiveEntry entry = new ArchiveEntry() {
@Override
public String getName() {
return entryName;
}
@Override
public String getNameWithinArchive() {
return relativeName;
}
@Override
public InputStreamAccess getStreamAccess() {
return inputStreamAccess;
}
};
context.obtainArchiveEntryHandler(entry).handleEntry(entry, context);
}
}
jarInputStream.close();
} catch (IOException ioe) {
throw new ArchiveException(String.format("Error accessing JarInputStream [%s]", getArchiveUrl()), ioe);
}
}
Aggregations