Allow initial buffer size definition in TransformWriter, and use available() method to set it in htmlParser. In this situation a ByteArrayInputStream is used so the available() method gives a good size estimation and avoid the buffer needing to be continually grown

pull/1/head
Al Sutton 13 years ago
parent f02ea27b31
commit d73c84f9a0

@ -81,11 +81,22 @@ public final class TransformerWriter extends Writer {
final Scraper scraper,
final Transformer transformer,
final boolean passbyIfBinarySuspect
) {
this(outStream, charSet, scraper, transformer, passbyIfBinarySuspect, 1024);
}
public TransformerWriter(
final OutputStream outStream,
final Charset charSet,
final Scraper scraper,
final Transformer transformer,
final boolean passbyIfBinarySuspect,
final int initialBufferSize
) {
this.outStream = outStream;
this.scraper = scraper;
this.transformer = transformer;
this.buffer = new CharBuffer(1024);
this.buffer = new CharBuffer(initialBufferSize);
this.filterTag = null;
this.filterOpts = null;
this.filterCont = null;

@ -196,7 +196,7 @@ public class htmlParser extends AbstractParser implements Parser {
// parsing the content
final ContentScraper scraper = new ContentScraper(location);
final TransformerWriter writer = new TransformerWriter(null,null,scraper,null,false);
final TransformerWriter writer = new TransformerWriter(null,null,scraper,null,false, sourceStream.available());
try {
FileUtils.copy(sourceStream, writer, c);
} catch (final IOException e) {

Loading…
Cancel
Save