@@ -402,10 +402,17 @@ public Object getProperty(String name) throws SAXNotRecognizedException,
402
402
* @see org.xml.sax.XMLReader#parse(org.xml.sax.InputSource)
403
403
*/
404
404
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 {
405
412
lazyInit ();
406
413
try {
407
414
treeBuilder .setFragmentContext (null );
408
- tokenize (input );
415
+ tokenize (input , bufferSize );
409
416
} finally {
410
417
if (saxTreeBuilder != null ) {
411
418
Document document = saxTreeBuilder .getDocument ();
@@ -426,10 +433,27 @@ public void parse(InputSource input) throws IOException, SAXException {
426
433
*/
427
434
public void parseFragment (InputSource input , String context )
428
435
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 {
429
449
lazyInit ();
430
450
try {
431
451
treeBuilder .setFragmentContext (context .intern ());
432
- tokenize (input );
452
+ if (bufferSize == -1 ) {
453
+ tokenize (input );
454
+ } else {
455
+ tokenize (input , bufferSize );
456
+ }
433
457
} finally {
434
458
if (saxTreeBuilder != null ) {
435
459
DocumentFragment fragment = saxTreeBuilder .getDocumentFragment ();
@@ -449,10 +473,29 @@ public void parseFragment(InputSource input, String context)
449
473
*/
450
474
public void parseFragment (InputSource input , String contextLocal , String contextNamespace )
451
475
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 {
452
491
lazyInit ();
453
492
try {
454
493
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
+ }
456
499
} finally {
457
500
if (saxTreeBuilder != null ) {
458
501
DocumentFragment fragment = saxTreeBuilder .getDocumentFragment ();
@@ -468,6 +511,10 @@ public void parseFragment(InputSource input, String contextLocal, String context
468
511
* @throws MalformedURLException
469
512
*/
470
513
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 {
471
518
if (is == null ) {
472
519
throw new IllegalArgumentException ("Null input." );
473
520
}
@@ -485,7 +532,11 @@ private void tokenize(InputSource is) throws SAXException, IOException, Malforme
485
532
is .setByteStream (new URL (systemId ).openStream ());
486
533
}
487
534
}
488
- driver .tokenize (is );
535
+ if (bufferSize == -1 ) {
536
+ driver .tokenize (is );
537
+ } else {
538
+ driver .tokenize (is , bufferSize );
539
+ }
489
540
}
490
541
491
542
/**
0 commit comments