192
Performance Considerations
buffer = new byte[MAX_CACHE_ENTRY_SIZE];
}
public InputSource resolveEntity(String publicId,
String systemId) throws IOException, SAXException {
InputStream stream = getEntity(publicId, systemId);
if (stream != null) {
InputSource source = new InputSource(stream);
source.setPublicId(publicId);
source.setSystemId(systemId);
return source;
}
return null;
}
private InputStream getEntity(String publicId, String systemId)
throws IOException, SAXException {
Entity entity = null;
SoftReference reference
= (SoftReference) entities.get(systemId);
if (reference != null) {
// Got a soft reference to the entity,
// let's get the actual entity.
entity = (Entity) reference.get();
}
if (entity == null) {
// The entity has been reclaimed by the GC or was
// never created, let's download it again! Delegate to
// the parent resolver that implements the actual
// resolution strategy.
InputSource source
= parentResolver.resolveEntity(publicId, systemId);
if (source != null) {
return cacheEntity(publicId, systemId,
source.getByteStream());
}
return null;
}
return new ByteArrayInputStream(entity.content);
New Page 1