1 16 package org.apache.axis2.om; 17 18 import javax.xml.stream.FactoryConfigurationError; 19 import javax.xml.stream.XMLOutputFactory; 20 import javax.xml.stream.XMLStreamException; 21 import javax.xml.stream.XMLStreamWriter; 22 import java.io.ByteArrayOutputStream ; 23 import java.io.OutputStream ; 24 import java.util.LinkedList ; 25 26 32 33 public class OMOutput { 34 private XMLStreamWriter xmlWriter; 35 36 private boolean doOptimise; 37 38 private OutputStream outStream; 39 40 private XMLStreamWriter writer; 41 42 private LinkedList binaryNodeList; 43 44 private ByteArrayOutputStream bufferedSoapOutStream; 45 46 private static String mimeBoundary = "----=_AxIs2_Def_boundary_=42214532"; 47 48 50 54 public OMOutput(XMLStreamWriter xmlWriter) { 55 this.xmlWriter = xmlWriter; 56 } 57 58 63 public OMOutput(OutputStream outStream, boolean doOptimise) 64 throws XMLStreamException, FactoryConfigurationError { 65 this.doOptimise = doOptimise; 66 this.outStream = outStream; 67 if (doOptimise) { 68 bufferedSoapOutStream = new ByteArrayOutputStream (); 69 xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter( 70 bufferedSoapOutStream); 71 binaryNodeList = new LinkedList (); 72 } else { 73 xmlWriter = XMLOutputFactory.newInstance().createXMLStreamWriter( 74 outStream); 75 76 } 77 78 } 79 80 public XMLStreamWriter getXmlStreamWriter() { 81 return xmlWriter; 82 } 83 84 public void flush() throws XMLStreamException { 85 xmlWriter.flush(); 98 100 } 101 102 public boolean doOptimise() { 103 return doOptimise; 104 } 105 106 public static String getContentType(boolean doOptimize) { 107 if (doOptimize) { 108 return MIMEOutputUtils.getContentTypeForMime(mimeBoundary); 109 } 110 return null; 112 } 113 114 public void writeOptimised(OMText node) { 115 binaryNodeList.add(node); 116 } 117 118 public void complete() throws XMLStreamException { 119 if (doOptimise) { 120 xmlWriter.flush(); 121 MIMEOutputUtils.complete(outStream, bufferedSoapOutStream, 122 binaryNodeList, mimeBoundary); 123 } 124 } 125 126 133 134 } 135 | Popular Tags |