类 StaxEventItemWriter<T>

    • 方法概要

      所有方法 实例方法 具体方法 
      修饰符和类型方法说明
      voidafterPropertiesSet() 
      voidclose()
      Flush and close the output source.
      protected javax.xml.transform.ResultcreateStaxResult()
      Subclasses can override to customize the STAX result.
      protected javax.xml.stream.XMLEventFactorycreateXmlEventFactory()
      Subclasses can override to customize the event factory.
      protected javax.xml.stream.XMLEventWritercreateXmlEventWriter​(javax.xml.stream.XMLOutputFactory outputFactory, java.io.Writer writer)
      Subclasses can override to customize the writer.
      protected javax.xml.stream.XMLOutputFactorycreateXmlOutputFactory()
      Subclasses can override to customize the factory.
      protected voidendDocument​(javax.xml.stream.XMLEventWriter writer)
      Writes the EndDocument tag manually.
      java.lang.StringgetEncoding()
      Get used encoding.
      java.util.Map<java.lang.String,​java.lang.String>getRootElementAttributes()
      Get attributes of the root element.
      java.lang.StringgetRootTagName()
      Get the tag name of the root element.
      java.lang.StringgetRootTagNamespace()
      Get the namespace of the root element.
      java.lang.StringgetRootTagNamespacePrefix()
      Get the namespace prefix of the root element.
      java.lang.StringgetVersion()
      Get XML version.
      protected voidinitNamespaceContext​(javax.xml.stream.XMLEventWriter writer)
      Inits the namespace context of the XMLEventWriter: rootTagNamespacePrefix for rootTagName any other xmlns namespace prefix declarations in the root element attributes
      voidopen​(ExecutionContext executionContext)
      Open the output source
      voidsetEncoding​(java.lang.String encoding)
      Set encoding to be used for output file.
      voidsetFooterCallback​(StaxWriterCallback footerCallback)
      footerCallback is called after writing all items but before closing the file.
      voidsetForceSync​(boolean forceSync)
      Flag to indicate that changes should be force-synced to disk on flush.
      voidsetHeaderCallback​(StaxWriterCallback headerCallback)
      headerCallback is called before writing any items.
      voidsetMarshaller​(org.springframework.oxm.Marshaller marshaller)
      Set Object to XML marshaller.
      voidsetOverwriteOutput​(boolean overwriteOutput)
      Set "overwrite" flag for the output file.
      voidsetResource​(org.springframework.core.io.Resource resource)
      Set output file.
      voidsetRootElementAttributes​(java.util.Map<java.lang.String,​java.lang.String> rootElementAttributes)
      Set the root element attributes to be written.
      voidsetRootTagName​(java.lang.String rootTagName)
      Set the tag name of the root element.
      voidsetSaveState​(boolean saveState) 
      voidsetShouldDeleteIfEmpty​(boolean shouldDeleteIfEmpty)
      Flag to indicate that the target file should be deleted if no items have been written (other than header and footer) on close.
      voidsetTransactional​(boolean transactional)
      Flag to indicate that writes should be deferred to the end of a transaction if present.
      voidsetVersion​(java.lang.String version)
      Set XML version to be used for output XML.
      protected voidstartDocument​(javax.xml.stream.XMLEventWriter writer)
      Writes simple XML header containing: xml declaration - defines encoding and XML version opening tag of the root element and its attributes If this is not sufficient for you, simply override this method.
      voidupdate​(ExecutionContext executionContext)
      Get the restart data.
      voidwrite​(java.util.List<? extends T> items)
      Write the value objects and flush them to the file.
      • 从类继承的方法 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 方法详细资料

      • setMarshaller

        public void setMarshaller​(org.springframework.oxm.Marshaller marshaller)
        Set Object to XML marshaller.
        参数:
        marshaller - the Object to XML marshaller
      • setTransactional

        public void setTransactional​(boolean transactional)
        Flag to indicate that writes should be deferred to the end of a transaction if present. Defaults to true.
        参数:
        transactional - the flag to set
      • setForceSync

        public void setForceSync​(boolean forceSync)
        Flag to indicate that changes should be force-synced to disk on flush. Defaults to false, which means that even with a local disk changes could be lost if the OS crashes in between a write and a cache flush. Setting to true may result in slower performance for usage patterns involving many frequent writes.
        参数:
        forceSync - the flag value to set
      • setShouldDeleteIfEmpty

        public void setShouldDeleteIfEmpty​(boolean shouldDeleteIfEmpty)
        Flag to indicate that the target file should be deleted if no items have been written (other than header and footer) on close. Defaults to false.
        参数:
        shouldDeleteIfEmpty - the flag value to set
      • getEncoding

        public java.lang.String getEncoding()
        Get used encoding.
        返回:
        the encoding used
      • setEncoding

        public void setEncoding​(java.lang.String encoding)
        Set encoding to be used for output file.
        参数:
        encoding - the encoding to be used
      • getVersion

        public java.lang.String getVersion()
        Get XML version.
        返回:
        the XML version used
      • setVersion

        public void setVersion​(java.lang.String version)
        Set XML version to be used for output XML.
        参数:
        version - the XML version to be used
      • getRootTagName

        public java.lang.String getRootTagName()
        Get the tag name of the root element.
        返回:
        the root element tag name
      • setRootTagName

        public void setRootTagName​(java.lang.String rootTagName)
        Set the tag name of the root element. If not set, default name is used ("root"). Namespace URI and prefix can also be set optionally using the notation:
         {uri}prefix:root
         
        The prefix is optional (defaults to empty), but if it is specified then the uri must be provided. In addition you might want to declare other namespaces using the root attributes.
        参数:
        rootTagName - the tag name to be used for the root element
      • getRootTagNamespacePrefix

        public java.lang.String getRootTagNamespacePrefix()
        Get the namespace prefix of the root element. Empty by default.
        返回:
        the rootTagNamespacePrefix
      • getRootTagNamespace

        public java.lang.String getRootTagNamespace()
        Get the namespace of the root element.
        返回:
        the rootTagNamespace
      • getRootElementAttributes

        public java.util.Map<java.lang.String,​java.lang.String> getRootElementAttributes()
        Get attributes of the root element.
        返回:
        attributes of the root element
      • setRootElementAttributes

        public void setRootElementAttributes​(java.util.Map<java.lang.String,​java.lang.String> rootElementAttributes)
        Set the root element attributes to be written. If any of the key names begin with "xmlns:" then they are treated as namespace declarations.
        参数:
        rootElementAttributes - attributes of the root element
      • setOverwriteOutput

        public void setOverwriteOutput​(boolean overwriteOutput)
        Set "overwrite" flag for the output file. Flag is ignored when output file processing is restarted.
        参数:
        overwriteOutput - If set to true, output file will be overwritten (this flag is ignored when processing is restart).
      • setSaveState

        public void setSaveState​(boolean saveState)
      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws java.lang.Exception
        指定者:
        afterPropertiesSet 在接口中 org.springframework.beans.factory.InitializingBean
        抛出:
        java.lang.Exception - thrown if error occurs
        另请参阅:
        InitializingBean.afterPropertiesSet()
      • createXmlEventWriter

        protected javax.xml.stream.XMLEventWriter createXmlEventWriter​(javax.xml.stream.XMLOutputFactory outputFactory,
                                                                       java.io.Writer writer)
                                                                throws javax.xml.stream.XMLStreamException
        Subclasses can override to customize the writer.
        参数:
        outputFactory - the factory to be used to create an XMLEventWriter.
        writer - the Writer to be used by the XMLEventWriter for writing to character streams.
        返回:
        an xml writer
        抛出:
        javax.xml.stream.XMLStreamException - thrown if error occured creating XMLEventWriter.
      • createXmlOutputFactory

        protected javax.xml.stream.XMLOutputFactory createXmlOutputFactory()
                                                                    throws javax.xml.stream.FactoryConfigurationError
        Subclasses can override to customize the factory.
        返回:
        a factory for the xml output
        抛出:
        javax.xml.stream.FactoryConfigurationError - throw if an instance of this factory cannot be loaded.
      • createXmlEventFactory

        protected javax.xml.stream.XMLEventFactory createXmlEventFactory()
                                                                  throws javax.xml.stream.FactoryConfigurationError
        Subclasses can override to customize the event factory.
        返回:
        a factory for the xml events
        抛出:
        javax.xml.stream.FactoryConfigurationError - thrown if an instance of this factory cannot be loaded.
      • createStaxResult

        protected javax.xml.transform.Result createStaxResult()
        Subclasses can override to customize the STAX result.
        返回:
        a result for writing to
      • initNamespaceContext

        protected void initNamespaceContext​(javax.xml.stream.XMLEventWriter writer)
                                     throws javax.xml.stream.XMLStreamException
        Inits the namespace context of the XMLEventWriter:
        • rootTagNamespacePrefix for rootTagName
        • any other xmlns namespace prefix declarations in the root element attributes
        参数:
        writer - XML event writer
        抛出:
        javax.xml.stream.XMLStreamException - thrown if error occurs while setting the prefix or default name space.
      • startDocument

        protected void startDocument​(javax.xml.stream.XMLEventWriter writer)
                              throws javax.xml.stream.XMLStreamException
        Writes simple XML header containing:
        • xml declaration - defines encoding and XML version
        • opening tag of the root element and its attributes
        If this is not sufficient for you, simply override this method. Encoding, version and root tag name can be retrieved with corresponding getters.
        参数:
        writer - XML event writer
        抛出:
        javax.xml.stream.XMLStreamException - thrown if error occurs.
      • endDocument

        protected void endDocument​(javax.xml.stream.XMLEventWriter writer)
                            throws javax.xml.stream.XMLStreamException
        Writes the EndDocument tag manually.
        参数:
        writer - XML event writer
        抛出:
        javax.xml.stream.XMLStreamException - thrown if error occurs.
      • write

        public void write​(java.util.List<? extends T> items)
                   throws org.springframework.oxm.XmlMappingException,
                          java.io.IOException
        Write the value objects and flush them to the file.
        指定者:
        write 在接口中 ItemWriter<T>
        参数:
        items - the value object
        抛出:
        java.io.IOException - thrown if general error occurs.
        org.springframework.oxm.XmlMappingException - thrown if error occurs during XML Mapping.