src/share/jaxws_classes/com/sun/xml/internal/org/jvnet/staxex/XMLStreamWriterEx.java

Sat, 07 Nov 2020 10:30:02 +0800

author
aoqi
date
Sat, 07 Nov 2020 10:30:02 +0800
changeset 1921
7166269ef0f1
parent 637
9c07ef4934dd
permissions
-rw-r--r--

Added tag mips-jdk8u275-b01 for changeset fdbe50121f48

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 */
aoqi@0 25
aoqi@0 26 package com.sun.xml.internal.org.jvnet.staxex;
aoqi@0 27
aoqi@0 28 import javax.activation.DataHandler;
aoqi@0 29 import javax.xml.stream.XMLStreamException;
aoqi@0 30 import javax.xml.stream.XMLStreamWriter;
aoqi@0 31 import java.io.OutputStream;
aoqi@0 32
aoqi@0 33 /**
aoqi@0 34 * {@link XMLStreamWriter} extended to support XOP.
aoqi@0 35 *
aoqi@0 36 * <p>
aoqi@0 37 * Some infoset serializer (such as XOP encoder, FastInfoset) uses a format
aoqi@0 38 * that can represent binary data more efficiently than base64 encoding.
aoqi@0 39 * Such infoset serializer may choose to implement this interface, to allow
aoqi@0 40 * the caller to pass in binary data more efficiently without first converting
aoqi@0 41 * it to binary data.
aoqi@0 42 *
aoqi@0 43 * <p>
aoqi@0 44 * Callers capable of using this interface can see if the serializer supports
aoqi@0 45 * it by simply downcasting {@link XMLStreamWriter} to {@link XMLStreamWriterEx}.
aoqi@0 46 *
aoqi@0 47 * <h2>TODO</h2>
aoqi@0 48 * <ol>
aoqi@0 49 * <li>
aoqi@0 50 * Add methods to write other primitive types, such as hex and integers
aoqi@0 51 * (and arrays of).
aoqi@0 52 * A textual implementation would write characters in accordance
aoqi@0 53 * to the canonical lexical definitions specified in W3C XML Schema: datatypes.
aoqi@0 54 * A MTOM implementation would write characters except for the case where octets
aoqi@0 55 * that would otherwise be base64 encoded when using the textual implementation.
aoqi@0 56 * A Fast Infoset implementation would encoded binary data the primitive types in
aoqi@0 57 * binary form.
aoqi@0 58 * <li>
aoqi@0 59 * Consider renaming writeBinary to writeBytesAsBase64 to be consistent with
aoqi@0 60 * infoset abstraction.
aoqi@0 61 * <li>
aoqi@0 62 * Add the ability to writeStart and writeEnd on attributes so that the same
aoqi@0 63 * methods for writing primitive types (and characters, which will require new methods)
aoqi@0 64 * can be used for writing attribute values as well as element content.
aoqi@0 65 * </ol>
aoqi@0 66 *
aoqi@0 67 * @see XMLStreamReaderEx
aoqi@0 68 * @author Kohsuke Kawaguchi
aoqi@0 69 * @author Paul Sandoz
aoqi@0 70 */
aoqi@0 71 public interface XMLStreamWriterEx extends XMLStreamWriter {
aoqi@0 72
aoqi@0 73 /**
aoqi@0 74 * Write the binary data.
aoqi@0 75 *
aoqi@0 76 * <p>
aoqi@0 77 * Conceptually (infoset-wise), this produces the base64-encoded binary data on the
aoqi@0 78 * output. But this allows implementations like FastInfoset or XOP to do the smart
aoqi@0 79 * thing.
aoqi@0 80 *
aoqi@0 81 * <p>
aoqi@0 82 * The use of this method has some restriction to support XOP. Namely, this method
aoqi@0 83 * must be invoked as a sole content of an element.
aoqi@0 84 *
aoqi@0 85 * <p>
aoqi@0 86 * (data,start,len) triplet identifies the binary data to be written.
aoqi@0 87 * After the method invocation, the callee owns the buffer.
aoqi@0 88 *
aoqi@0 89 * @param contentType
aoqi@0 90 * this mandatory parameter identifies the MIME type of the binary data.
aoqi@0 91 * If the MIME type isn't known by the caller, "application/octet-stream" can
aoqi@0 92 * be always used to indicate "I don't know." Never null.
aoqi@0 93 */
aoqi@0 94 void writeBinary(byte[] data, int start, int len, String contentType) throws XMLStreamException;
aoqi@0 95
aoqi@0 96 /**
aoqi@0 97 * Writes the binary data.
aoqi@0 98 *
aoqi@0 99 * <p>
aoqi@0 100 * This method works like the {@link #writeBinary(byte[], int, int, String)} method,
aoqi@0 101 * except that it takes the binary data in the form of {@link DataHandler}, which
aoqi@0 102 * contains a MIME type ({@link DataHandler#getContentType()} as well as the payload
aoqi@0 103 * {@link DataHandler#getInputStream()}.
aoqi@0 104 *
aoqi@0 105 * @param data
aoqi@0 106 * always non-null. After this method call, the callee owns the data handler.
aoqi@0 107 */
aoqi@0 108 void writeBinary(DataHandler data) throws XMLStreamException;
aoqi@0 109
aoqi@0 110 /**
aoqi@0 111 * Writes the binary data.
aoqi@0 112 *
aoqi@0 113 * <p>
aoqi@0 114 * This version of the writeBinary method allows the caller to produce
aoqi@0 115 * the binary data by writing it to {@link OutputStream}.
aoqi@0 116 *
aoqi@0 117 * <p>
aoqi@0 118 * It is the caller's responsibility to write and close
aoqi@0 119 * a stream before it invokes any other methods on {@link XMLStreamWriter}.
aoqi@0 120 *
aoqi@0 121 * TODO: experimental. appreciate feedback
aoqi@0 122 * @param contentType
aoqi@0 123 * See the content-type parameter of
aoqi@0 124 * {@link #writeBinary(byte[], int, int, String)}. Must not be null.
aoqi@0 125 *
aoqi@0 126 * @return
aoqi@0 127 * always return a non-null {@link OutputStream}.
aoqi@0 128 */
aoqi@0 129 OutputStream writeBinary(String contentType) throws XMLStreamException;
aoqi@0 130
aoqi@0 131 /**
aoqi@0 132 * Writes like {@link #writeCharacters(String)} but hides
aoqi@0 133 * actual data format.
aoqi@0 134 *
aoqi@0 135 * @param data
aoqi@0 136 * The {@link CharSequence} that represents the
aoqi@0 137 * character infoset items to be written.
aoqi@0 138 *
aoqi@0 139 * <p>
aoqi@0 140 * The {@link CharSequence} is normally a {@link String},
aoqi@0 141 * but can be any other {@link CharSequence} implementation.
aoqi@0 142 * For binary data, however, use of {@link Base64Data} is
aoqi@0 143 * recommended (so that the consumer interested in seeing it
aoqi@0 144 * as binary data may take advantage of mor efficient
aoqi@0 145 * data representation.)
aoqi@0 146 *
aoqi@0 147 */
aoqi@0 148 void writePCDATA(CharSequence data) throws XMLStreamException;
aoqi@0 149
aoqi@0 150 /**
aoqi@0 151 * {@inheritDoc}
aoqi@0 152 */
aoqi@0 153 NamespaceContextEx getNamespaceContext();
aoqi@0 154 }

mercurial