log.trace(_loc.get("scanning-jar-at-url", url));
try {
InputStream is = (InputStream)
AccessController.doPrivileged(
J2DoPrivHelper.openStreamAction(url));
scan(new ZipStreamMetaDataIterator(
new ZipInputStream(is),
newMetaDataFilter()), cparser, names, true, url);
} catch (PrivilegedActionException pae) {
throw (IOException) pae.getException();
}
} else {
// Open an InputStream from the URL and sniff for a zip header. If it is, then this is
// a URL with a jar-formated InputStream, as per the JPA specification. Otherwise, fall back
// to URLMetaDataIterator.
BufferedInputStream is = null;
try {
is = new BufferedInputStream((InputStream) AccessController.
doPrivileged(J2DoPrivHelper.openStreamAction(url)));
} catch (PrivilegedActionException pae) {
throw (IOException) pae.getException();
}
// Check for zip header magic 0x50 0x4b 0x03 0x04
is.mark(0);
boolean zipHeaderMatch = is.read() == 0x50 && is.read() == 0x4b && is.read() == 0x03 &&
is.read() == 0x04;
is.reset();
if (zipHeaderMatch) {
// The URL provides a Jar-formatted InputStream, consume it with ZipStreamMetaDataIterator
if (log.isTraceEnabled())
log.trace(_loc.get("scanning-jar-at-url", url));
scan(new ZipStreamMetaDataIterator(new ZipInputStream(is), newMetaDataFilter()),
cparser, names, true, url);
} else {
// Fall back to URLMetaDataIterator
if (log.isTraceEnabled())
log.trace(_loc.get("scanning-url", url));
clss = cparser.parseTypeNames(new URLMetaDataIterator(url));
List<String> newNames = Arrays.asList(clss);
if (log.isTraceEnabled())
log.trace(_loc.get("scan-found-names", newNames, url));
names.addAll(newNames);
mapPersistentTypeNames(url, clss);
}
}
}
}
if (rsrcs != null) {
String rsrc;
MetaDataIterator mitr;
for (Iterator itr = rsrcs.iterator(); itr.hasNext();) {
rsrc = (String) itr.next();
if (rsrc.endsWith(".jar")) {
url = AccessController.doPrivileged(
J2DoPrivHelper.getResourceAction(loader, rsrc));
if (url != null) {
if (log.isTraceEnabled())
log.trace(_loc.get("scanning-jar-stream-url", url));
try {
InputStream is = (InputStream)
AccessController.doPrivileged(
J2DoPrivHelper.openStreamAction(url));
scan(new ZipStreamMetaDataIterator
(new ZipInputStream(is),
newMetaDataFilter()), cparser, names, true,
url);
} catch (PrivilegedActionException pae) {
throw (IOException) pae.getException();