| 1 | // ================================================================================================= |
| 2 | // ADOBE SYSTEMS INCORPORATED |
| 3 | // Copyright 2006 Adobe Systems Incorporated |
| 4 | // All Rights Reserved |
| 5 | // |
| 6 | // NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms |
| 7 | // of the Adobe license agreement accompanying it. |
| 8 | // ================================================================================================= |
| 9 | |
| 10 | package com.adobe.internal.xmp.utils; |
| 11 | |
| 12 | import java.io.BufferedWriter; |
| 13 | import java.io.IOException; |
| 14 | import java.io.OutputStream; |
| 15 | import java.io.OutputStreamWriter; |
| 16 | import java.io.Writer; |
| 17 | |
| 18 | import com.adobe.internal.xmp.options.SerializeOptions; |
| 19 | |
| 20 | |
| 21 | /** |
| 22 | * Factory for XMLStreamWriter |
| 23 | * |
| 24 | * @author Stefan Makswit |
| 25 | * @version $Revision$ |
| 26 | * @since 07.11.2006 |
| 27 | */ |
| 28 | public class XMLStreamWriterFactory |
| 29 | { |
| 30 | /** |
| 31 | * Creates an XMLStreamWriterImpl on top of standard writer with XMP serialization options. |
| 32 | * @param writer a <code>Writer</code> |
| 33 | * @param options serialization options |
| 34 | * @return Returns an XML stream writer. |
| 35 | */ |
| 36 | public static XMLStreamWriterImpl create(Writer writer, SerializeOptions options) |
| 37 | { |
| 38 | return new XMLStreamWriterImpl(writer, options); |
| 39 | } |
| 40 | |
| 41 | |
| 42 | /** |
| 43 | * Creates an XMLStreamWriterImpl on top of an output stream with XMP serialization options. |
| 44 | * @param stream an <code>OutputStream</code> |
| 45 | * @param options serialization options |
| 46 | * @return Returns an XML stream writer. |
| 47 | * @throws IOException If the encoding provided by <code>SerializeOptions</code> is not supported |
| 48 | */ |
| 49 | public static XMLStreamWriterImpl create(OutputStream stream, SerializeOptions options) |
| 50 | throws IOException |
| 51 | { |
| 52 | try |
| 53 | { |
| 54 | return create(new BufferedWriter(new OutputStreamWriter(stream, options.getEncoding()), |
| 55 | 4096), options); |
| 56 | } |
| 57 | catch (java.io.UnsupportedEncodingException uee) |
| 58 | { |
| 59 | throw new IOException("Unsupported encoding " + options.getEncoding()); |
| 60 | } |
| 61 | } |
| 62 | } |