当前位置: 首页>>代码示例>>Java>>正文


Java StreamResult.getOutputStream方法代码示例

本文整理汇总了Java中javax.xml.transform.stream.StreamResult.getOutputStream方法的典型用法代码示例。如果您正苦于以下问题:Java StreamResult.getOutputStream方法的具体用法?Java StreamResult.getOutputStream怎么用?Java StreamResult.getOutputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.xml.transform.stream.StreamResult的用法示例。


在下文中一共展示了StreamResult.getOutputStream方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: StreamSerializer

import javax.xml.transform.stream.StreamResult; //导入方法依赖的package包/类
public StreamSerializer(StreamResult streamResult) {
    // if this method opened a stream, let it close it
    final OutputStream[] autoClose = new OutputStream[1];

    if (streamResult.getWriter() != null)
        writer = createWriter(streamResult.getWriter());
    else if (streamResult.getOutputStream() != null)
        writer = createWriter(streamResult.getOutputStream());
    else if (streamResult.getSystemId() != null) {
        String fileURL = streamResult.getSystemId();

        fileURL = convertURL(fileURL);

        try {
            FileOutputStream fos = new FileOutputStream(fileURL);
            autoClose[0] = fos;
            writer = createWriter(fos);
        } catch (IOException e) {
            throw new TxwException(e);
        }
    } else
        throw new IllegalArgumentException();

    // now delegate to the SaxSerializer
    serializer = new SaxSerializer(writer,writer,false) {
        public void endDocument() {
            super.endDocument();
            if(autoClose[0]!=null) {
                try {
                    autoClose[0].close();
                } catch (IOException e) {
                    throw new TxwException(e);
                }
                autoClose[0] = null;
            }
        }
    };
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:39,代码来源:StreamSerializer.java

示例2: setOutput

import javax.xml.transform.stream.StreamResult; //导入方法依赖的package包/类
/**
 * Use a StreamResult to initialize the output for this XMLStreamWriter. Check
 * for OutputStream, Writer and then systemId, in that order.
 *
 * @param sr        StreamResult encapsulating output information
 * @param encoding  Encoding to be used except when a Writer is available
 */
public void setOutput(StreamResult sr, String encoding)
    throws IOException {

    if (sr.getOutputStream() != null) {
        setOutputUsingStream(sr.getOutputStream(), encoding);
    }
    else if (sr.getWriter() != null) {
        setOutputUsingWriter(sr.getWriter());
    }
    else if (sr.getSystemId() != null) {
        setOutputUsingStream(new FileOutputStream(sr.getSystemId()),
            encoding);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:22,代码来源:XMLStreamWriterImpl.java


注:本文中的javax.xml.transform.stream.StreamResult.getOutputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。