Chapter 4 XML Processing
// Attempts to cache an entity; if it's too big just 
// return an input stream to it.
private InputStream cacheEntity(String publicId,
String systemId, InputStream stream) throws IOException {
stream = new BufferedInputStream(stream);
int count = 0;
for (int i = 0; count < buffer.length; count += i) {
if ((i =, count,
buffer.length   count)) < 0) { break; }
byte[] content = new byte[count];
System.arraycopy(buffer, 0, content, 0, count);
if (count != buffer.length) {
// Cache the entity for future use, using a soft reference 
// so that the GC may reclaim it if it's not referenced 
// anymore and memory is running low.
Entity entity = new Entity(); = publicId != null ? publicId : systemId;
entity.content = content;
entities.put(, new SoftReference(entity));
return new ByteArrayInputStream(content);
// Entity too big to be cached.
return new SequenceInputStream(
new ByteArrayInputStream(content), stream);
Code Example 4.13
Using SAX API to Implement a Caching Entity Resolver
4.5.6 Cache Dynamically Generated Documents
Dynamically generated documents are typically assembled from values returned
from calls to business logic. Generally, it is a good idea to cache dynamically gener 
ated XML documents to avoid having to refetch the document contents, which
entails extra round trips to a business tier. This is a good rule to follow when the data
is predominantly read only, such as catalog data. Furthermore, if applicable, you can

New Page 1

Home : About Us : Network : Services : Support : FAQ : Control Panel : Order Online : Sitemap : Contact : Terms Of Service

java web hosting



 Our partners: | PHP: Hypertext Preprocessor | Best Web Hosting | Java Web Hosting | Inexpensive Web Hosting |

Jsp Web Hosting | Cheapest Web Hosting | Jsp Hosting | Cheap Hosting


Virtualwebstudio. Business web hosting division of Web Design Plus. All rights reserved