xhtml.startDocument();
// At the end we want to close the bzip2 stream to release any associated
// resources, but the underlying document stream should not be closed
InputStream bzip2 =
new BZip2CompressorInputStream(new CloseShieldInputStream(stream));
try {
Metadata entrydata = new Metadata();
String name = metadata.get(Metadata.RESOURCE_NAME_KEY);
if (name != null) {
if (name.endsWith(".tbz")) {
name = name.substring(0, name.length() - 4) + ".tar";
} else if (name.endsWith(".tbz2")) {
name = name.substring(0, name.length() - 5) + ".tar";
} else if (name.endsWith(".bz")) {
name = name.substring(0, name.length() - 3);
} else if (name.endsWith(".bz2")) {
name = name.substring(0, name.length() - 4);
}
entrydata.set(Metadata.RESOURCE_NAME_KEY, name);
}
// Use the delegate parser to parse the compressed document
super.parse(
new CloseShieldInputStream(bzip2),
new EmbeddedContentHandler(
new BodyContentHandler(xhtml)),
entrydata, context);
} finally {
bzip2.close();
}
xhtml.endDocument();
}