use of org.hibernate.boot.archive.spi.ArchiveEntry 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.ArchiveEntry in project wildfly by wildfly.
the class VirtualFileSystemArchiveDescriptor method processVirtualFile.
private void processVirtualFile(VirtualFile virtualFile, String path, ArchiveContext archiveContext) {
if (path == null) {
path = "";
} else {
if (!path.endsWith("/'")) {
path = path + "/";
}
}
for (VirtualFile child : virtualFile.getChildren()) {
if (!child.exists()) {
// should never happen conceptually, but...
continue;
}
if (child.isDirectory()) {
processVirtualFile(child, path + child.getName(), archiveContext);
continue;
}
final String name = child.getPathName();
final String relativeName = path + child.getName();
final InputStreamAccess inputStreamAccess = new VirtualFileInputStreamAccess(name, child);
final ArchiveEntry entry = new ArchiveEntry() {
@Override
public String getName() {
return name;
}
@Override
public String getNameWithinArchive() {
return relativeName;
}
@Override
public InputStreamAccess getStreamAccess() {
return inputStreamAccess;
}
};
archiveContext.obtainArchiveEntryHandler(entry).handleEntry(entry, archiveContext);
}
}
use of org.hibernate.boot.archive.spi.ArchiveEntry 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.ArchiveEntry in project hibernate-orm by hibernate.
the class ExplodedArchiveDescriptor method processDirectory.
private void processDirectory(File directory, String path, ArchiveContext context) {
if (directory == null) {
return;
}
final File[] files = directory.listFiles();
if (files == null) {
return;
}
path = path == null ? "" : path + "/";
for (final File localFile : files) {
if (!localFile.exists()) {
// should never happen conceptually, but...
continue;
}
if (localFile.isDirectory()) {
processDirectory(localFile, path + localFile.getName(), context);
continue;
}
final String name = localFile.getAbsolutePath();
final String relativeName = path + localFile.getName();
final InputStreamAccess inputStreamAccess = new FileInputStreamAccess(name, localFile);
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);
}
}
use of org.hibernate.boot.archive.spi.ArchiveEntry 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