if (entry != null)
return entry;
boolean isClassResource = path.endsWith(CLASS_FILE_SUFFIX);
WebResource resource = null;
boolean fileNeedConvert = false;
resource = resources.getClassLoaderResource(path);
if (!resource.exists()) {
return null;
}
entry = new ResourceEntry();
entry.source = resource.getURL();
entry.codeBase = entry.source;
entry.lastModified = resource.getLastModified();
if (needConvert) {
if (path.endsWith(".properties")) {
fileNeedConvert = true;
}
}
/* Only cache the binary content if there is some content
* available and either:
* a) It is a class file since the binary content is only cached
* until the class has been loaded
* or
* b) The file needs conversion to address encoding issues (see
* below)
*
* In all other cases do not cache the content to prevent
* excessive memory usage if large resources are present (see
* https://issues.apache.org/bugzilla/show_bug.cgi?id=53081).
*/
if (isClassResource || fileNeedConvert) {
byte[] binaryContent = resource.getContent();
if (binaryContent != null) {
if (fileNeedConvert) {
// Workaround for certain files on platforms that use
// EBCDIC encoding, when they are read through FileInputStream.
// See commit message of rev.303915 for details
// http://svn.apache.org/viewvc?view=revision&revision=303915
String str = new String(binaryContent);
try {
binaryContent = str.getBytes(StandardCharsets.UTF_8);
} catch (Exception e) {
return null;
}
}
entry.binaryContent = binaryContent;
// The certificates and manifest are made available as a side
// effect of reading the binary content
entry.certificates = resource.getCertificates();
}
}
entry.manifest = resource.getManifest();
if (isClassResource && entry.binaryContent != null &&
this.transformers.size() > 0) {
// If the resource is a class just being loaded, decorate it
// with any attached transformers