1 /* 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.xml.internal.ws.streaming; 27 28 import com.sun.istack.internal.Nullable; 29 import com.sun.xml.internal.ws.encoding.HasEncoding; 30 import com.sun.xml.internal.ws.encoding.SOAPBindingCodec; 31 32 import javax.xml.namespace.QName; 33 import javax.xml.stream.XMLStreamWriter; 34 import javax.xml.stream.XMLStreamException; 35 import java.util.Map; 36 import java.io.OutputStream; 37 38 /** 39 * <p>XMLStreamWriterUtil provides some utility methods intended to be used 40 * in conjunction with a StAX XMLStreamWriter. </p> 41 * 42 * @author Santiago.PericasGeertsen@sun.com 43 */ 44 public class XMLStreamWriterUtil { 45 46 private XMLStreamWriterUtil() { 47 } 48 49 /** 50 * Gives the underlying stream for XMLStreamWriter. It closes any start elements, and returns the stream so 51 * that JAXB can write infoset directly to the stream. 52 * 53 * @param writer XMLStreamWriter for which stream is required 54 * @return underlying OutputStream, null if writer doesn't provide a way to get it 55 * @throws XMLStreamException if any of writer operations throw the exception 56 */ 57 public static @Nullable OutputStream getOutputStream(XMLStreamWriter writer) throws XMLStreamException { 58 Object obj = null; 59 60 // Hack for JDK6's SJSXP 61 if (writer instanceof Map) { 62 obj = ((Map) writer).get("sjsxp-outputstream"); 63 } 64 65 // woodstox 66 if (obj == null) { 67 try { 68 obj = writer.getProperty("com.ctc.wstx.outputUnderlyingStream"); 69 } catch(Exception ie) { 70 // Catch all exceptions. SJSXP in JDK throws NPE 71 // nothing to do here 72 } 73 } 74 75 // SJSXP 76 if (obj == null) { 77 try { 78 obj = writer.getProperty("http://java.sun.com/xml/stream/properties/outputstream"); 79 } catch(Exception ie) { 80 // Catch all exceptions. SJSXP in JDK throws NPE 81 // nothing to do here 82 } | 1 /* 2 * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package com.sun.xml.internal.ws.streaming; 27 28 import com.sun.istack.internal.Nullable; 29 import com.sun.xml.internal.ws.api.streaming.XMLStreamWriterFactory; 30 import com.sun.xml.internal.ws.encoding.HasEncoding; 31 import com.sun.xml.internal.ws.encoding.SOAPBindingCodec; 32 33 import javax.xml.namespace.QName; 34 import javax.xml.stream.XMLStreamWriter; 35 import javax.xml.stream.XMLStreamException; 36 import java.util.Map; 37 import java.io.OutputStream; 38 39 /** 40 * <p>XMLStreamWriterUtil provides some utility methods intended to be used 41 * in conjunction with a StAX XMLStreamWriter. </p> 42 * 43 * @author Santiago.PericasGeertsen@sun.com 44 */ 45 public class XMLStreamWriterUtil { 46 47 private XMLStreamWriterUtil() { 48 } 49 50 /** 51 * Gives the underlying stream for XMLStreamWriter. It closes any start elements, and returns the stream so 52 * that JAXB can write infoset directly to the stream. 53 * 54 * @param writer XMLStreamWriter for which stream is required 55 * @return underlying OutputStream, null if writer doesn't provide a way to get it 56 * @throws XMLStreamException if any of writer operations throw the exception 57 */ 58 public static @Nullable OutputStream getOutputStream(XMLStreamWriter writer) throws XMLStreamException { 59 Object obj = null; 60 61 XMLStreamWriter xmlStreamWriter = 62 writer instanceof XMLStreamWriterFactory.HasEncodingWriter ? 63 ((XMLStreamWriterFactory.HasEncodingWriter) writer).getWriter() 64 : writer; 65 66 67 // Hack for JDK6's SJSXP 68 if (xmlStreamWriter instanceof Map) { 69 obj = ((Map) xmlStreamWriter).get("sjsxp-outputstream"); 70 } 71 72 // woodstox 73 if (obj == null) { 74 try { 75 obj = writer.getProperty("com.ctc.wstx.outputUnderlyingStream"); 76 } catch(Exception ie) { 77 // Catch all exceptions. SJSXP in JDK throws NPE 78 // nothing to do here 79 } 80 } 81 82 // SJSXP 83 if (obj == null) { 84 try { 85 obj = writer.getProperty("http://java.sun.com/xml/stream/properties/outputstream"); 86 } catch(Exception ie) { 87 // Catch all exceptions. SJSXP in JDK throws NPE 88 // nothing to do here 89 } |