use of org.hibernate.boot.archive.spi.ArchiveException in project hibernate-orm by hibernate.
the class ClassFileArchiveEntryHandler method toClassFile.
private ClassFile toClassFile(ArchiveEntry entry) {
final InputStream inputStream = entry.getStreamAccess().accessInputStream();
final DataInputStream dataInputStream = new DataInputStream(inputStream);
try {
return new ClassFile(dataInputStream);
} catch (IOException e) {
throw new ArchiveException("Could not build ClassFile", e);
} finally {
try {
dataInputStream.close();
} catch (Exception ignore) {
}
try {
inputStream.close();
} catch (IOException ignore) {
}
}
}
use of org.hibernate.boot.archive.spi.ArchiveException in project hibernate-orm by hibernate.
the class JarFileBasedArchiveDescriptor method visitArchive.
@Override
public void visitArchive(ArchiveContext context) {
final JarFile jarFile = resolveJarFileReference();
if (jarFile == null) {
return;
}
final Enumeration<? extends ZipEntry> zipEntries = jarFile.entries();
while (zipEntries.hasMoreElements()) {
final ZipEntry zipEntry = zipEntries.nextElement();
final String entryName = extractName(zipEntry);
if (getEntryBasePrefix() != null && !entryName.startsWith(getEntryBasePrefix())) {
continue;
}
if (zipEntry.isDirectory()) {
continue;
}
if (entryName.equals(getEntryBasePrefix())) {
// just any random entry
try (InputStream is = new BufferedInputStream(jarFile.getInputStream(zipEntry))) {
final JarInputStream jarInputStream = new JarInputStream(is);
ZipEntry subZipEntry = jarInputStream.getNextEntry();
while (subZipEntry != null) {
if (!subZipEntry.isDirectory()) {
final String name = extractName(subZipEntry);
final String relativeName = extractRelativeName(subZipEntry);
final InputStreamAccess inputStreamAccess = buildByteBasedInputStreamAccess(name, jarInputStream);
final ArchiveEntry entry = new ArchiveEntry() {
@Override
public String getName() {
return name;
}
@Override
public String getNameWithinArchive() {
return relativeName;
}
@Override
public InputStreamAccess getStreamAccess() {
return inputStreamAccess;
}
};
final ArchiveEntryHandler entryHandler = context.obtainArchiveEntryHandler(entry);
entryHandler.handleEntry(entry, context);
}
subZipEntry = jarInputStream.getNextEntry();
}
} catch (Exception e) {
throw new ArchiveException("Error accessing JarFile entry [" + zipEntry.getName() + "]", e);
}
} else {
final String name = extractName(zipEntry);
final String relativeName = extractRelativeName(zipEntry);
final InputStreamAccess inputStreamAccess;
try (InputStream is = jarFile.getInputStream(zipEntry)) {
inputStreamAccess = buildByteBasedInputStreamAccess(name, is);
} catch (IOException e) {
throw new ArchiveException(String.format("Unable to access stream from jar file [%s] for entry [%s]", jarFile.getName(), zipEntry.getName()));
}
final ArchiveEntry entry = new ArchiveEntry() {
@Override
public String getName() {
return name;
}
@Override
public String getNameWithinArchive() {
return relativeName;
}
@Override
public InputStreamAccess getStreamAccess() {
return inputStreamAccess;
}
};
final ArchiveEntryHandler entryHandler = context.obtainArchiveEntryHandler(entry);
entryHandler.handleEntry(entry, context);
}
}
}
use of org.hibernate.boot.archive.spi.ArchiveException in project hibernate-orm by hibernate.
the class ExplodedArchiveDescriptor method processZippedRoot.
private void processZippedRoot(File rootFile, ArchiveContext context) {
try {
final JarFile jarFile = new JarFile(rootFile);
final Enumeration<? extends ZipEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
final ZipEntry zipEntry = entries.nextElement();
if (zipEntry.isDirectory()) {
continue;
}
final String name = extractName(zipEntry);
final String relativeName = extractRelativeName(zipEntry);
final InputStreamAccess inputStreamAccess;
try {
inputStreamAccess = buildByteBasedInputStreamAccess(name, jarFile.getInputStream(zipEntry));
} catch (IOException e) {
throw new ArchiveException(String.format("Unable to access stream from jar file [%s] for entry [%s]", jarFile.getName(), zipEntry.getName()));
}
final ArchiveEntry entry = new ArchiveEntry() {
@Override
public String getName() {
return name;
}
@Override
public String getNameWithinArchive() {
return relativeName;
}
@Override
public InputStreamAccess getStreamAccess() {
return inputStreamAccess;
}
};
context.obtainArchiveEntryHandler(entry).handleEntry(entry, context);
}
} catch (IOException e) {
throw new ArchiveException("Error accessing jar file [" + rootFile.getAbsolutePath() + "]", e);
}
}
use of org.hibernate.boot.archive.spi.ArchiveException 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