@@ -481,19 +481,20 @@ public ToXmlGenerator createGenerator(OutputStream out) throws IOException {
481
481
public ToXmlGenerator createGenerator (OutputStream out , JsonEncoding enc ) throws IOException
482
482
{
483
483
// false -> we won't manage the stream unless explicitly directed to
484
- IOContext ctxt = _createContext (out , false );
484
+ final IOContext ctxt = _createContext (out , false );
485
485
ctxt .setEncoding (enc );
486
486
return new ToXmlGenerator (ctxt ,
487
487
_generatorFeatures , _xmlGeneratorFeatures ,
488
- _objectCodec , _createXmlWriter (out ));
488
+ _objectCodec , _createXmlWriter (ctxt , out ));
489
489
}
490
490
491
491
@ Override
492
492
public ToXmlGenerator createGenerator (Writer out ) throws IOException
493
493
{
494
- return new ToXmlGenerator (_createContext (out , false ),
494
+ final IOContext ctxt = _createContext (out , false );
495
+ return new ToXmlGenerator (ctxt ,
495
496
_generatorFeatures , _xmlGeneratorFeatures ,
496
- _objectCodec , _createXmlWriter (out ));
497
+ _objectCodec , _createXmlWriter (ctxt , out ));
497
498
}
498
499
499
500
@ SuppressWarnings ("resource" )
@@ -502,10 +503,10 @@ public ToXmlGenerator createGenerator(File f, JsonEncoding enc) throws IOExcepti
502
503
{
503
504
OutputStream out = new FileOutputStream (f );
504
505
// true -> yes, we have to manage the stream since we created it
505
- IOContext ctxt = _createContext (out , true );
506
+ final IOContext ctxt = _createContext (out , true );
506
507
ctxt .setEncoding (enc );
507
508
return new ToXmlGenerator (ctxt , _generatorFeatures , _xmlGeneratorFeatures ,
508
- _objectCodec , _createXmlWriter (out ));
509
+ _objectCodec , _createXmlWriter (ctxt , out ));
509
510
}
510
511
511
512
/*
@@ -645,22 +646,22 @@ protected JsonGenerator _createGenerator(Writer out, IOContext ctxt) throws IOEx
645
646
/**********************************************************************
646
647
*/
647
648
648
- protected XMLStreamWriter _createXmlWriter (OutputStream out ) throws IOException
649
+ protected XMLStreamWriter _createXmlWriter (IOContext ctxt , OutputStream out ) throws IOException
649
650
{
650
651
XMLStreamWriter sw ;
651
652
try {
652
- sw = _xmlOutputFactory .createXMLStreamWriter (out , "UTF-8" );
653
+ sw = _xmlOutputFactory .createXMLStreamWriter (_decorate ( ctxt , out ) , "UTF-8" );
653
654
} catch (XMLStreamException e ) {
654
655
return StaxUtil .throwAsGenerationException (e , null );
655
656
}
656
657
return _initializeXmlWriter (sw );
657
658
}
658
659
659
- protected XMLStreamWriter _createXmlWriter (Writer w ) throws IOException
660
+ protected XMLStreamWriter _createXmlWriter (IOContext ctxt , Writer w ) throws IOException
660
661
{
661
662
XMLStreamWriter sw ;
662
663
try {
663
- sw = _xmlOutputFactory .createXMLStreamWriter (w );
664
+ sw = _xmlOutputFactory .createXMLStreamWriter (_decorate ( ctxt , w ) );
664
665
} catch (XMLStreamException e ) {
665
666
return StaxUtil .throwAsGenerationException (e , null );
666
667
}
@@ -853,4 +854,31 @@ private final static int skipSpace(InputAccessor acc, byte b) throws IOException
853
854
}
854
855
}
855
856
857
+ /*
858
+ /**********************************************************
859
+ /* Decorators, output
860
+ /**********************************************************
861
+ */
862
+
863
+ protected OutputStream _decorate (IOContext ioCtxt , OutputStream out ) throws IOException
864
+ {
865
+ if (_outputDecorator != null ) {
866
+ OutputStream out2 = _outputDecorator .decorate (ioCtxt , out );
867
+ if (out2 != null ) {
868
+ return out2 ;
869
+ }
870
+ }
871
+ return out ;
872
+ }
873
+
874
+ protected Writer _decorate (IOContext ioCtxt , Writer out ) throws IOException
875
+ {
876
+ if (_outputDecorator != null ) {
877
+ Writer out2 = _outputDecorator .decorate (ioCtxt , out );
878
+ if (out2 != null ) {
879
+ return out2 ;
880
+ }
881
+ }
882
+ return out ;
883
+ }
856
884
}
0 commit comments