aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortbell <none@none>2009-04-20 15:25:02 -0700
committertbell <none@none>2009-04-20 15:25:02 -0700
commit659b0cd26745f875a9b4a3417d3cc6c2ab5f8d05 (patch)
treed1d2a83f3dfa76d69c8d3c4df6e0698e3a4e1dcc /src
parent26100ef649fd4718cbf9c8c9f0420e68881a742c (diff)
parent4dfa595366ea4139853b9a888530fc8d11e29c28 (diff)
downloadjdk8u_jaxws-659b0cd26745f875a9b4a3417d3cc6c2ab5f8d05.tar.gz
Merge
Diffstat (limited to 'src')
-rw-r--r--src/share/classes/com/sun/xml/internal/bind/v2/runtime/output/UTF8XmlOutput.java38
1 files changed, 32 insertions, 6 deletions
diff --git a/src/share/classes/com/sun/xml/internal/bind/v2/runtime/output/UTF8XmlOutput.java b/src/share/classes/com/sun/xml/internal/bind/v2/runtime/output/UTF8XmlOutput.java
index f8347818..f7603e98 100644
--- a/src/share/classes/com/sun/xml/internal/bind/v2/runtime/output/UTF8XmlOutput.java
+++ b/src/share/classes/com/sun/xml/internal/bind/v2/runtime/output/UTF8XmlOutput.java
@@ -32,6 +32,7 @@ import javax.xml.stream.XMLStreamException;
import com.sun.xml.internal.bind.DatatypeConverterImpl;
import com.sun.xml.internal.bind.v2.runtime.Name;
import com.sun.xml.internal.bind.v2.runtime.XMLSerializer;
+import com.sun.xml.internal.bind.v2.runtime.MarshallerImpl;
import org.xml.sax.SAXException;
@@ -81,6 +82,11 @@ public class UTF8XmlOutput extends XmlOutputAbstractImpl {
protected boolean closeStartTagPending = false;
/**
+ * @see MarshallerImpl#header
+ */
+ private String header;
+
+ /**
*
* @param localNames
* local names encoded in UTF-8.
@@ -92,6 +98,10 @@ public class UTF8XmlOutput extends XmlOutputAbstractImpl {
prefixes[i] = new Encoded();
}
+ public void setHeader(String header) {
+ this.header = header;
+ }
+
@Override
public void startDocument(XMLSerializer serializer, boolean fragment, int[] nsUriIndex2prefixIndex, NamespaceContextImpl nsContext) throws IOException, SAXException, XMLStreamException {
super.startDocument(serializer, fragment,nsUriIndex2prefixIndex,nsContext);
@@ -100,6 +110,10 @@ public class UTF8XmlOutput extends XmlOutputAbstractImpl {
if(!fragment) {
write(XML_DECL);
}
+ if(header!=null) {
+ textBuffer.set(header);
+ textBuffer.write(this);
+ }
}
public void endDocument(boolean fragment) throws IOException, SAXException, XMLStreamException {
@@ -383,11 +397,23 @@ public class UTF8XmlOutput extends XmlOutputAbstractImpl {
return buf;
}
- private static final byte[] XMLNS_EQUALS = toBytes(" xmlns=\"");
- private static final byte[] XMLNS_COLON = toBytes(" xmlns:");
- private static final byte[] EQUALS = toBytes("=\"");
- private static final byte[] CLOSE_TAG = toBytes("</");
- private static final byte[] EMPTY_TAG = toBytes("/>");
+ // per instance copy to prevent an attack where malicious OutputStream
+ // rewrites the byte array.
+ private final byte[] XMLNS_EQUALS = _XMLNS_EQUALS.clone();
+ private final byte[] XMLNS_COLON = _XMLNS_COLON.clone();
+ private final byte[] EQUALS = _EQUALS.clone();
+ private final byte[] CLOSE_TAG = _CLOSE_TAG.clone();
+ private final byte[] EMPTY_TAG = _EMPTY_TAG.clone();
+ private final byte[] XML_DECL = _XML_DECL.clone();
+
+ // masters
+ private static final byte[] _XMLNS_EQUALS = toBytes(" xmlns=\"");
+ private static final byte[] _XMLNS_COLON = toBytes(" xmlns:");
+ private static final byte[] _EQUALS = toBytes("=\"");
+ private static final byte[] _CLOSE_TAG = toBytes("</");
+ private static final byte[] _EMPTY_TAG = toBytes("/>");
+ private static final byte[] _XML_DECL = toBytes("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
+
+ // no need to copy
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
- private static final byte[] XML_DECL = toBytes("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>");
}