com.ctc.wstx.sw
Class RestrictedCharsAwareBufferingXmlWriter

java.lang.Object
  extended by com.ctc.wstx.sw.XmlWriter
      extended by com.ctc.wstx.sw.RestrictedCharsAwareBufferingXmlWriter
All Implemented Interfaces:
javax.xml.stream.XMLStreamConstants

public final class RestrictedCharsAwareBufferingXmlWriter
extends com.ctc.wstx.sw.XmlWriter
implements javax.xml.stream.XMLStreamConstants

Concrete implementation of XmlWriter that will dispatch writes to another writer (of type Writer, and will NOT handle encoding. It will, however, do basic buffering such that the underlying Writer need (and thus, should) not do buffering.

One design goal for this class is to avoid unnecessary buffering: since there will be another Writer doing the actual encoding, amount of buffering needed should still be limited. To this end, a threshold is used to define what's the threshold of writes that we do want to coalesce, ie. buffer. Writes bigger than this should in general proceed without buffering.


Field Summary
protected static int HIGHEST_ENCODABLE_ATTR_CHAR
          Highest valued character that may need to be encoded (minus charset encoding requirements) when writing attribute values.
protected static int HIGHEST_ENCODABLE_TEXT_CHAR
          Highest valued character that may need to be encoded (minus charset encoding requirements) when writing attribute values.
protected  java.io.Writer mOut
          Actual Writer to use for outputting buffered data as appropriate.
protected  char[] mOutputBuffer
           
protected  int mOutputBufLen
           
protected  int mOutputPtr
           
protected  int mSmallWriteSize
          This is the threshold used to check what is considered a "small" write; small writes will be buffered until resulting size will be above the threshold.
protected  java.io.OutputStream mUnderlyingStream
          Actual physical stream that the writer is using, if known.
 
Fields inherited from class com.ctc.wstx.sw.XmlWriter
DEFAULT_QUOTE_CHAR, mAttrValueWriter, mAutoCloseOutput, mCheckContent, mCheckNames, mCheckStructure, mConfig, mEncoding, mFixContent, mLocPastChars, mLocRowNr, mLocRowStartOffset, mNsAware, mRawWrapper, mTextWrapper, mTextWriter, mXml11, SURR1_FIRST, SURR1_LAST, SURR2_FIRST, SURR2_LAST
 
Fields inherited from interface javax.xml.stream.XMLStreamConstants
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT
 
Constructor Summary
RestrictedCharsAwareBufferingXmlWriter(java.io.Writer out, com.ctc.wstx.api.WriterConfig cfg, java.lang.String enc, boolean autoclose, java.io.OutputStream outs, int bitsize)
           
 
Method Summary
 void close(boolean forceRealClose)
           
 void flush()
           
protected  int getOutputPtr()
           
protected  java.io.OutputStream getOutputStream()
           
protected  java.io.Writer getWriter()
           
static int guessEncodingBitSize(java.lang.String enc)
          Method used to figure out which part of the Unicode char set the encoding can natively support.
static boolean isRestricted(int character)
           
protected  int verifyCDataContent(char[] c, int start, int end)
           
protected  int verifyCDataContent(java.lang.String content)
           
protected  int verifyCommentContent(java.lang.String content)
           
protected  void writeAsEntity(int c)
           
 void writeAttribute(java.lang.String localName, char[] value, int offset, int vlen)
           
 void writeAttribute(java.lang.String localName, java.lang.String value)
           
 void writeAttribute(java.lang.String prefix, java.lang.String localName, char[] value, int offset, int vlen)
           
 void writeAttribute(java.lang.String prefix, java.lang.String localName, java.lang.String value)
           
 int writeCData(char[] cbuf, int offset, int len)
           
 int writeCData(java.lang.String data)
           
 void writeCDataEnd()
           
 void writeCDataStart()
           
 void writeCharacters(char[] cbuf, int offset, int len)
           
 void writeCharacters(java.lang.String text)
           
 int writeComment(java.lang.String data)
          Method that will try to output the content as specified.
 void writeCommentEnd()
           
 void writeCommentStart()
           
 void writeDTD(java.lang.String data)
           
 void writeDTD(java.lang.String rootName, java.lang.String systemId, java.lang.String publicId, java.lang.String internalSubset)
           
 void writeEndTag(java.lang.String localName)
           
 void writeEndTag(java.lang.String prefix, java.lang.String localName)
           
 void writeEntityReference(java.lang.String name)
           
 int writePI(java.lang.String target, java.lang.String data)
           
 void writePIEnd()
           
 void writePIStart(java.lang.String target, boolean addSpace)
           
protected  void writePrefixedName(java.lang.String prefix, java.lang.String localName)
           
 void writeRaw(char[] cbuf, int offset, int len)
           
 void writeRaw(java.lang.String str)
           
 void writeRaw(java.lang.String str, int offset, int len)
           
 void writeRawAscii(char[] cbuf, int offset, int len)
          Method called to output typed values (int, long, double, float etc) that are known not to contain any escapable characters, or anything else beyond 7-bit ascii range.
protected  void writeSegmentedCData(char[] c, int start, int len, int index)
           
protected  void writeSegmentedCData(java.lang.String content, int index)
           
protected  void writeSegmentedComment(java.lang.String content, int index)
           
 void writeStartTagEmptyEnd()
           
 void writeStartTagEnd()
           
 void writeStartTagStart(java.lang.String localName)
           
 void writeStartTagStart(java.lang.String prefix, java.lang.String localName)
           
 void writeTypedAttribute(java.lang.String localName, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
           
 void writeTypedAttribute(java.lang.String prefix, java.lang.String localName, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
           
 void writeTypedAttribute(java.lang.String prefix, java.lang.String localName, java.lang.String nsURI, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc, org.codehaus.stax2.validation.XMLValidator validator, char[] copyBuffer)
           
 void writeTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
           
 void writeTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc, org.codehaus.stax2.validation.XMLValidator validator, char[] copyBuffer)
           
 void writeXmlDeclaration(java.lang.String version, java.lang.String encoding, java.lang.String standalone)
           
 
Methods inherited from class com.ctc.wstx.sw.XmlWriter
close, enableXml11, getAbsOffset, getColumn, getRow, reportNwfContent, reportNwfName, reportNwfName, throwInvalidChar, throwOutputError, throwOutputError, verifyNameValidity, wrapAsRawWriter, wrapAsTextWriter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HIGHEST_ENCODABLE_ATTR_CHAR

protected static final int HIGHEST_ENCODABLE_ATTR_CHAR
Highest valued character that may need to be encoded (minus charset encoding requirements) when writing attribute values.

See Also:
Constant Field Values

HIGHEST_ENCODABLE_TEXT_CHAR

protected static final int HIGHEST_ENCODABLE_TEXT_CHAR
Highest valued character that may need to be encoded (minus charset encoding requirements) when writing attribute values.

See Also:
Constant Field Values

mOut

protected final java.io.Writer mOut
Actual Writer to use for outputting buffered data as appropriate.


mOutputBuffer

protected char[] mOutputBuffer

mSmallWriteSize

protected final int mSmallWriteSize
This is the threshold used to check what is considered a "small" write; small writes will be buffered until resulting size will be above the threshold.


mOutputPtr

protected int mOutputPtr

mOutputBufLen

protected int mOutputBufLen

mUnderlyingStream

protected final java.io.OutputStream mUnderlyingStream
Actual physical stream that the writer is using, if known. Not used for actual output, only needed so that calling application may (try to) figure out the original source.

Constructor Detail

RestrictedCharsAwareBufferingXmlWriter

public RestrictedCharsAwareBufferingXmlWriter(java.io.Writer out,
                                              com.ctc.wstx.api.WriterConfig cfg,
                                              java.lang.String enc,
                                              boolean autoclose,
                                              java.io.OutputStream outs,
                                              int bitsize)
                                       throws java.io.IOException
Parameters:
outs - Underlying OutputStream that the writer (out) is using, if known. Needed to support (optional) access to the underlying stream
Throws:
java.io.IOException
Method Detail

getOutputPtr

protected int getOutputPtr()
Specified by:
getOutputPtr in class com.ctc.wstx.sw.XmlWriter

getOutputStream

protected final java.io.OutputStream getOutputStream()
Specified by:
getOutputStream in class com.ctc.wstx.sw.XmlWriter

getWriter

protected final java.io.Writer getWriter()
Specified by:
getWriter in class com.ctc.wstx.sw.XmlWriter

close

public void close(boolean forceRealClose)
           throws java.io.IOException
Throws:
java.io.IOException

flush

public final void flush()
                 throws java.io.IOException
Specified by:
flush in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeRaw

public void writeRaw(char[] cbuf,
                     int offset,
                     int len)
              throws java.io.IOException
Specified by:
writeRaw in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeRawAscii

public final void writeRawAscii(char[] cbuf,
                                int offset,
                                int len)
                         throws java.io.IOException
Method called to output typed values (int, long, double, float etc) that are known not to contain any escapable characters, or anything else beyond 7-bit ascii range.

Throws:
java.io.IOException

writeRaw

public void writeRaw(java.lang.String str)
              throws java.io.IOException
Overrides:
writeRaw in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeRaw

public void writeRaw(java.lang.String str,
                     int offset,
                     int len)
              throws java.io.IOException
Specified by:
writeRaw in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeCDataStart

public final void writeCDataStart()
                           throws java.io.IOException
Specified by:
writeCDataStart in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeCDataEnd

public final void writeCDataEnd()
                         throws java.io.IOException
Specified by:
writeCDataEnd in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeCommentStart

public final void writeCommentStart()
                             throws java.io.IOException
Specified by:
writeCommentStart in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeCommentEnd

public final void writeCommentEnd()
                           throws java.io.IOException
Specified by:
writeCommentEnd in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writePIStart

public final void writePIStart(java.lang.String target,
                               boolean addSpace)
                        throws java.io.IOException
Specified by:
writePIStart in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writePIEnd

public final void writePIEnd()
                      throws java.io.IOException
Specified by:
writePIEnd in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeCData

public int writeCData(java.lang.String data)
               throws java.io.IOException
Specified by:
writeCData in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeCData

public int writeCData(char[] cbuf,
                      int offset,
                      int len)
               throws java.io.IOException
Specified by:
writeCData in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeCharacters

public void writeCharacters(java.lang.String text)
                     throws java.io.IOException
Specified by:
writeCharacters in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeCharacters

public void writeCharacters(char[] cbuf,
                            int offset,
                            int len)
                     throws java.io.IOException
Specified by:
writeCharacters in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeComment

public int writeComment(java.lang.String data)
                 throws java.io.IOException
Method that will try to output the content as specified. If the content passed in has embedded "--" in it, it will either add an intervening space between consequtive hyphens (if content fixing is enabled), or return the offset of the first hyphen in multi-hyphen sequence.

Specified by:
writeComment in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeDTD

public void writeDTD(java.lang.String data)
              throws java.io.IOException
Specified by:
writeDTD in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeDTD

public void writeDTD(java.lang.String rootName,
                     java.lang.String systemId,
                     java.lang.String publicId,
                     java.lang.String internalSubset)
              throws java.io.IOException,
                     javax.xml.stream.XMLStreamException
Specified by:
writeDTD in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

writeEntityReference

public void writeEntityReference(java.lang.String name)
                          throws java.io.IOException,
                                 javax.xml.stream.XMLStreamException
Specified by:
writeEntityReference in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

writeXmlDeclaration

public void writeXmlDeclaration(java.lang.String version,
                                java.lang.String encoding,
                                java.lang.String standalone)
                         throws java.io.IOException
Specified by:
writeXmlDeclaration in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writePI

public int writePI(java.lang.String target,
                   java.lang.String data)
            throws java.io.IOException,
                   javax.xml.stream.XMLStreamException
Specified by:
writePI in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

writeStartTagStart

public void writeStartTagStart(java.lang.String localName)
                        throws java.io.IOException,
                               javax.xml.stream.XMLStreamException
Specified by:
writeStartTagStart in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

writeStartTagStart

public void writeStartTagStart(java.lang.String prefix,
                               java.lang.String localName)
                        throws java.io.IOException,
                               javax.xml.stream.XMLStreamException
Specified by:
writeStartTagStart in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

writeStartTagEnd

public void writeStartTagEnd()
                      throws java.io.IOException
Specified by:
writeStartTagEnd in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeStartTagEmptyEnd

public void writeStartTagEmptyEnd()
                           throws java.io.IOException
Specified by:
writeStartTagEmptyEnd in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeEndTag

public void writeEndTag(java.lang.String localName)
                 throws java.io.IOException
Specified by:
writeEndTag in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeEndTag

public void writeEndTag(java.lang.String prefix,
                        java.lang.String localName)
                 throws java.io.IOException
Specified by:
writeEndTag in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException

writeAttribute

public void writeAttribute(java.lang.String localName,
                           java.lang.String value)
                    throws java.io.IOException,
                           javax.xml.stream.XMLStreamException
Specified by:
writeAttribute in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

writeAttribute

public void writeAttribute(java.lang.String localName,
                           char[] value,
                           int offset,
                           int vlen)
                    throws java.io.IOException,
                           javax.xml.stream.XMLStreamException
Specified by:
writeAttribute in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

writeAttribute

public void writeAttribute(java.lang.String prefix,
                           java.lang.String localName,
                           java.lang.String value)
                    throws java.io.IOException,
                           javax.xml.stream.XMLStreamException
Specified by:
writeAttribute in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

writeAttribute

public void writeAttribute(java.lang.String prefix,
                           java.lang.String localName,
                           char[] value,
                           int offset,
                           int vlen)
                    throws java.io.IOException,
                           javax.xml.stream.XMLStreamException
Specified by:
writeAttribute in class com.ctc.wstx.sw.XmlWriter
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

writeTypedElement

public final void writeTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
                             throws java.io.IOException
Throws:
java.io.IOException

writeTypedElement

public final void writeTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc,
                                    org.codehaus.stax2.validation.XMLValidator validator,
                                    char[] copyBuffer)
                             throws java.io.IOException,
                                    javax.xml.stream.XMLStreamException
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

writeTypedAttribute

public void writeTypedAttribute(java.lang.String localName,
                                org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
                         throws java.io.IOException,
                                javax.xml.stream.XMLStreamException
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

writeTypedAttribute

public void writeTypedAttribute(java.lang.String prefix,
                                java.lang.String localName,
                                org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
                         throws java.io.IOException,
                                javax.xml.stream.XMLStreamException
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

writeTypedAttribute

public void writeTypedAttribute(java.lang.String prefix,
                                java.lang.String localName,
                                java.lang.String nsURI,
                                org.codehaus.stax2.ri.typed.AsciiValueEncoder enc,
                                org.codehaus.stax2.validation.XMLValidator validator,
                                char[] copyBuffer)
                         throws java.io.IOException,
                                javax.xml.stream.XMLStreamException
Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

writePrefixedName

protected final void writePrefixedName(java.lang.String prefix,
                                       java.lang.String localName)
                                throws java.io.IOException
Throws:
java.io.IOException

verifyCDataContent

protected int verifyCDataContent(java.lang.String content)
Returns:
Index at which a problem was found, if any; -1 if there's no problem.

verifyCDataContent

protected int verifyCDataContent(char[] c,
                                 int start,
                                 int end)

verifyCommentContent

protected int verifyCommentContent(java.lang.String content)

writeSegmentedCData

protected void writeSegmentedCData(java.lang.String content,
                                   int index)
                            throws java.io.IOException
Throws:
java.io.IOException

writeSegmentedCData

protected void writeSegmentedCData(char[] c,
                                   int start,
                                   int len,
                                   int index)
                            throws java.io.IOException
Throws:
java.io.IOException

writeSegmentedComment

protected void writeSegmentedComment(java.lang.String content,
                                     int index)
                              throws java.io.IOException
Throws:
java.io.IOException

guessEncodingBitSize

public static int guessEncodingBitSize(java.lang.String enc)
Method used to figure out which part of the Unicode char set the encoding can natively support. Values returned are 7, 8 and 16, to indicate (respectively) "ascii", "ISO-Latin" and "native Unicode". These just best guesses, but should work ok for the most common encodings.


writeAsEntity

protected final void writeAsEntity(int c)
                            throws java.io.IOException
Throws:
java.io.IOException

isRestricted

public static boolean isRestricted(int character)


Copyright © 2013 Atlassian Software Systems Pty Ltd. All Rights Reserved.