@@ -402,10 +402,17 @@ public Object getProperty(String name) throws SAXNotRecognizedException,
402402 * @see org.xml.sax.XMLReader#parse(org.xml.sax.InputSource)
403403 */
404404 public void parse (InputSource input ) throws IOException , SAXException {
405+ parse (input , -1 );
406+ }
407+
408+ /**
409+ * @see org.xml.sax.XMLReader#parse(org.xml.sax.InputSource)
410+ */
411+ public void parse (InputSource input , int bufferSize ) throws IOException , SAXException {
405412 lazyInit ();
406413 try {
407414 treeBuilder .setFragmentContext (null );
408- tokenize (input );
415+ tokenize (input , bufferSize );
409416 } finally {
410417 if (saxTreeBuilder != null ) {
411418 Document document = saxTreeBuilder .getDocument ();
@@ -426,10 +433,27 @@ public void parse(InputSource input) throws IOException, SAXException {
426433 */
427434 public void parseFragment (InputSource input , String context )
428435 throws IOException , SAXException {
436+ parseFragment (input , context , -1 );
437+ }
438+ /**
439+ * Parses a fragment with HTML context.
440+ *
441+ * @param input the input to parse
442+ * @param context the name of the context element (HTML namespace assumed)
443+ * @param bufferSize the size of the buffer to feed to the tokenizer
444+ * @throws IOException
445+ * @throws SAXException
446+ */
447+ public void parseFragment (InputSource input , String context , int bufferSize )
448+ throws IOException , SAXException {
429449 lazyInit ();
430450 try {
431451 treeBuilder .setFragmentContext (context .intern ());
432- tokenize (input );
452+ if (bufferSize == -1 ) {
453+ tokenize (input );
454+ } else {
455+ tokenize (input , bufferSize );
456+ }
433457 } finally {
434458 if (saxTreeBuilder != null ) {
435459 DocumentFragment fragment = saxTreeBuilder .getDocumentFragment ();
@@ -449,10 +473,29 @@ public void parseFragment(InputSource input, String context)
449473 */
450474 public void parseFragment (InputSource input , String contextLocal , String contextNamespace )
451475 throws IOException , SAXException {
476+ parseFragment (input , contextLocal , contextNamespace , -1 );
477+ }
478+ /**
479+ * Parses a fragment.
480+ *
481+ * @param input the input to parse
482+ * @param contextLocal the local name of the context element
483+ * @param contextNamespace the namespace of the context element
484+ * @param bufferSize the size of the buffer to feed to the tokenizer
485+ * @throws IOException
486+ * @throws SAXException
487+ */
488+ public void parseFragment (InputSource input , String contextLocal ,
489+ String contextNamespace , int bufferSize )
490+ throws IOException , SAXException {
452491 lazyInit ();
453492 try {
454493 treeBuilder .setFragmentContext (contextLocal .intern (), contextNamespace .intern (), null , false );
455- tokenize (input );
494+ if (bufferSize == -1 ) {
495+ tokenize (input );
496+ } else {
497+ tokenize (input , bufferSize );
498+ }
456499 } finally {
457500 if (saxTreeBuilder != null ) {
458501 DocumentFragment fragment = saxTreeBuilder .getDocumentFragment ();
@@ -468,6 +511,10 @@ public void parseFragment(InputSource input, String contextLocal, String context
468511 * @throws MalformedURLException
469512 */
470513 private void tokenize (InputSource is ) throws SAXException , IOException , MalformedURLException {
514+ tokenize (is , -1 );
515+ }
516+ private void tokenize (InputSource is , int bufferSize ) throws SAXException ,
517+ IOException , MalformedURLException {
471518 if (is == null ) {
472519 throw new IllegalArgumentException ("Null input." );
473520 }
@@ -485,7 +532,11 @@ private void tokenize(InputSource is) throws SAXException, IOException, Malforme
485532 is .setByteStream (new URL (systemId ).openStream ());
486533 }
487534 }
488- driver .tokenize (is );
535+ if (bufferSize == -1 ) {
536+ driver .tokenize (is );
537+ } else {
538+ driver .tokenize (is , bufferSize );
539+ }
489540 }
490541
491542 /**
0 commit comments