1
1
package com .fasterxml .jackson .dataformat .xml ;
2
2
3
+ import java .io .File ;
4
+ import java .io .FileOutputStream ;
3
5
import java .io .IOException ;
4
6
import java .io .OutputStream ;
5
7
9
11
import javax .xml .stream .XMLStreamWriter ;
10
12
11
13
import com .fasterxml .jackson .core .*;
14
+ import com .fasterxml .jackson .core .exc .StreamWriteException ;
12
15
import com .fasterxml .jackson .core .type .TypeReference ;
13
16
import com .fasterxml .jackson .core .util .ByteArrayBuilder ;
14
17
import com .fasterxml .jackson .databind .*;
@@ -398,7 +401,7 @@ public void writeValue(XMLStreamWriter w0, Object value) throws IOException {
398
401
/**
399
402
* Method that can be used to serialize any Java value as
400
403
* a byte array.
401
-
404
+ *
402
405
* @param value value to write as XML bytes
403
406
* @param encoding character encoding for the XML output
404
407
* @return byte array representing the XML output
@@ -418,10 +421,36 @@ public byte[] writeValueAsBytes(Object value, String encoding) throws JsonProces
418
421
}
419
422
}
420
423
424
+ /**
425
+ * Method that can be used to serialize any Java value as
426
+ * XML output, written to File provided.
427
+ *
428
+ * @param resultFile
429
+ * @param value
430
+ * @param encoding
431
+ * @throws IOException
432
+ * @throws StreamWriteException
433
+ * @throws DatabindException
434
+ * @since 2.16
435
+ */
436
+ public void writeValue (File resultFile , Object value , String encoding )
437
+ throws IOException , StreamWriteException , DatabindException
438
+ {
439
+ _writeValueAndClose (createGenerator (resultFile , encoding ), value );
440
+ }
441
+
421
442
private JsonGenerator createGenerator (OutputStream out , String encoding ) throws IOException {
422
443
this ._assertNotNull ("out" , out );
423
444
JsonGenerator g = ((XmlFactory ) _jsonFactory ).createGenerator (out , encoding );
424
445
this ._serializationConfig .initialize (g );
425
446
return g ;
426
447
}
448
+
449
+ private JsonGenerator createGenerator (File outputFile , String encoding ) throws IOException {
450
+ _assertNotNull ("outputFile" , outputFile );
451
+ JsonGenerator g = ((XmlFactory ) _jsonFactory ).createGenerator (
452
+ new FileOutputStream (outputFile ), encoding );
453
+ _serializationConfig .initialize (g );
454
+ return g ;
455
+ }
427
456
}
0 commit comments