Merge

Fri, 10 Apr 2009 13:05:12 -0700

author
asaha
date
Fri, 10 Apr 2009 13:05:12 -0700
changeset 43
f89f252678be
parent 38
50ea00dc5f14
parent 42
99fc62f032a7
child 44
fa6a4207cae8

Merge

     1.1 --- a/src/share/classes/com/sun/xml/internal/bind/v2/runtime/output/UTF8XmlOutput.java	Thu Apr 02 16:51:48 2009 -0700
     1.2 +++ b/src/share/classes/com/sun/xml/internal/bind/v2/runtime/output/UTF8XmlOutput.java	Fri Apr 10 13:05:12 2009 -0700
     1.3 @@ -22,7 +22,6 @@
     1.4   * CA 95054 USA or visit www.sun.com if you need additional information or
     1.5   * have any questions.
     1.6   */
     1.7 -
     1.8  package com.sun.xml.internal.bind.v2.runtime.output;
     1.9  
    1.10  import java.io.IOException;
    1.11 @@ -33,6 +32,7 @@
    1.12  import com.sun.xml.internal.bind.DatatypeConverterImpl;
    1.13  import com.sun.xml.internal.bind.v2.runtime.Name;
    1.14  import com.sun.xml.internal.bind.v2.runtime.XMLSerializer;
    1.15 +import com.sun.xml.internal.bind.v2.runtime.MarshallerImpl;
    1.16  
    1.17  import org.xml.sax.SAXException;
    1.18  
    1.19 @@ -82,6 +82,11 @@
    1.20      protected boolean closeStartTagPending = false;
    1.21  
    1.22      /**
    1.23 +     * @see MarshallerImpl#header
    1.24 +     */
    1.25 +    private String header;
    1.26 +
    1.27 +    /**
    1.28       *
    1.29       * @param localNames
    1.30       *      local names encoded in UTF-8.
    1.31 @@ -93,6 +98,10 @@
    1.32              prefixes[i] = new Encoded();
    1.33      }
    1.34  
    1.35 +    public void setHeader(String header) {
    1.36 +        this.header = header;
    1.37 +    }
    1.38 +
    1.39      @Override
    1.40      public void startDocument(XMLSerializer serializer, boolean fragment, int[] nsUriIndex2prefixIndex, NamespaceContextImpl nsContext) throws IOException, SAXException, XMLStreamException {
    1.41          super.startDocument(serializer, fragment,nsUriIndex2prefixIndex,nsContext);
    1.42 @@ -101,6 +110,10 @@
    1.43          if(!fragment) {
    1.44              write(XML_DECL);
    1.45          }
    1.46 +        if(header!=null) {
    1.47 +            textBuffer.set(header);
    1.48 +            textBuffer.write(this);
    1.49 +        }
    1.50      }
    1.51  
    1.52      public void endDocument(boolean fragment) throws IOException, SAXException, XMLStreamException {
    1.53 @@ -377,13 +390,6 @@
    1.54          octetBufferIndex = 0;
    1.55      }
    1.56  
    1.57 -    public void flush() throws IOException {
    1.58 -        flushBuffer();
    1.59 -        out.flush();
    1.60 -    }
    1.61 -
    1.62 -
    1.63 -
    1.64      static byte[] toBytes(String s) {
    1.65          byte[] buf = new byte[s.length()];
    1.66          for( int i=s.length()-1; i>=0; i-- )
    1.67 @@ -391,11 +397,23 @@
    1.68          return buf;
    1.69      }
    1.70  
    1.71 -    private static final byte[] XMLNS_EQUALS = toBytes(" xmlns=\"");
    1.72 -    private static final byte[] XMLNS_COLON = toBytes(" xmlns:");
    1.73 -    private static final byte[] EQUALS = toBytes("=\"");
    1.74 -    private static final byte[] CLOSE_TAG = toBytes("</");
    1.75 -    private static final byte[] EMPTY_TAG = toBytes("/>");
    1.76 +    // per instance copy to prevent an attack where malicious OutputStream
    1.77 +    // rewrites the byte array.
    1.78 +    private final byte[] XMLNS_EQUALS = _XMLNS_EQUALS.clone();
    1.79 +    private final byte[] XMLNS_COLON = _XMLNS_COLON.clone();
    1.80 +    private final byte[] EQUALS = _EQUALS.clone();
    1.81 +    private final byte[] CLOSE_TAG = _CLOSE_TAG.clone();
    1.82 +    private final byte[] EMPTY_TAG = _EMPTY_TAG.clone();
    1.83 +    private final byte[] XML_DECL = _XML_DECL.clone();
    1.84 +
    1.85 +    // masters
    1.86 +    private static final byte[] _XMLNS_EQUALS = toBytes(" xmlns=\"");
    1.87 +    private static final byte[] _XMLNS_COLON = toBytes(" xmlns:");
    1.88 +    private static final byte[] _EQUALS = toBytes("=\"");
    1.89 +    private static final byte[] _CLOSE_TAG = toBytes("</");
    1.90 +    private static final byte[] _EMPTY_TAG = toBytes("/>");
    1.91 +    private static final byte[] _XML_DECL = toBytes("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
    1.92 +
    1.93 +    // no need to copy
    1.94      private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
    1.95 -    private static final byte[] XML_DECL = toBytes("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
    1.96  }

mercurial