當前位置: 首頁>>代碼示例>>Java>>正文


Java StreamSource.getReader方法代碼示例

本文整理匯總了Java中javax.xml.transform.stream.StreamSource.getReader方法的典型用法代碼示例。如果您正苦於以下問題:Java StreamSource.getReader方法的具體用法?Java StreamSource.getReader怎麽用?Java StreamSource.getReader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.xml.transform.stream.StreamSource的用法示例。


在下文中一共展示了StreamSource.getReader方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: jaxpSourcetoXMLInputSource

import javax.xml.transform.stream.StreamSource; //導入方法依賴的package包/類
XMLInputSource jaxpSourcetoXMLInputSource(Source source){
     if(source instanceof StreamSource){
         StreamSource stSource = (StreamSource)source;
         String systemId = stSource.getSystemId();
         String publicId = stSource.getPublicId();
         InputStream istream = stSource.getInputStream();
         Reader reader = stSource.getReader();

         if(istream != null){
             return new XMLInputSource(publicId, systemId, null, istream, null);
         }
         else if(reader != null){
             return new XMLInputSource(publicId, systemId,null, reader, null);
         }else{
             return new XMLInputSource(publicId, systemId, null);
         }
     }

     throw new UnsupportedOperationException("Cannot create " +
            "XMLStreamReader or XMLEventReader from a " +
            source.getClass().getName());
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:23,代碼來源:XMLInputFactoryImpl.java

示例2: jaxpSourcetoXMLInputSource

import javax.xml.transform.stream.StreamSource; //導入方法依賴的package包/類
XMLInputSource jaxpSourcetoXMLInputSource(Source source){
     if(source instanceof StreamSource){
         StreamSource stSource = (StreamSource)source;
         String systemId = stSource.getSystemId();
         String publicId = stSource.getPublicId();
         InputStream istream = stSource.getInputStream();
         Reader reader = stSource.getReader();

         if(istream != null){
             return new XMLInputSource(publicId, systemId, null, istream, null);
         }
         else if(reader != null){
             return new XMLInputSource(publicId, systemId,null, reader, null);
         }else{
             return new XMLInputSource(publicId, systemId, null, false);
         }
     }

     throw new UnsupportedOperationException("Cannot create " +
            "XMLStreamReader or XMLEventReader from a " +
            source.getClass().getName());
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:XMLInputFactoryImpl.java

示例3: toXMLInputSource

import javax.xml.transform.stream.StreamSource; //導入方法依賴的package包/類
/**
 * Creates a proper {@link XMLInputSource} from a {@link StreamSource}.
 *
 * @return always return non-null valid object.
 */
public static final XMLInputSource toXMLInputSource( StreamSource in ) {
    if( in.getReader()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getReader(), null );
    if( in.getInputStream()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getInputStream(), null );

    return new XMLInputSource(
    in.getPublicId(), in.getSystemId(), in.getSystemId() );
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:Util.java

示例4: transformSummaryToHTML

import javax.xml.transform.stream.StreamSource; //導入方法依賴的package包/類
/**
 * Transform summary information to HTML.
 *
 * @param htmlWriter the Writer to write the HTML output to
 */
public void transformSummaryToHTML(Writer htmlWriter)
        throws IOException, TransformerException {

	ByteArrayOutputStream summaryOut = new ByteArrayOutputStream(8096);
	reportSummary(summaryOut);
	String summaryXML = summaryOut.toString();


	StreamSource in = new StreamSource(new StringReader(summaryXML));
	StreamResult out = new StreamResult(htmlWriter);
	InputStream xslInputStream = this.getClass().getClassLoader().getResourceAsStream("summary.xsl");
	if (xslInputStream == null)
		throw new IOException("Could not load summary stylesheet");
	StreamSource xsl = new StreamSource(xslInputStream);

	TransformerFactory tf = TransformerFactory.newInstance();
	Transformer transformer = tf.newTransformer(xsl);
	transformer.transform(in, out);

	Reader rdr = in.getReader();
	if (rdr != null)
		rdr.close();
	htmlWriter.close();
	InputStream is = xsl.getInputStream();
	if (is != null)
		is.close();
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:33,代碼來源:ProjectStats.java

示例5: closeHard

import javax.xml.transform.stream.StreamSource; //導入方法依賴的package包/類
/**
 * Helper method to close StreamSource
 * @param source
 */
private void closeHard(final StreamSource source) {
  try {
    if (source != null) {
      if (source.getInputStream() != null) IoUtils.closeHard(source.getInputStream());
      if (source.getReader() != null) IoUtils.closeHard(source.getReader());
    }
  } catch (Exception e) {
    IoUtils.ignoreExpectedException(e);
  }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:15,代碼來源:AbstractXSLRendererComponent.java

示例6: toXMLInputSource

import javax.xml.transform.stream.StreamSource; //導入方法依賴的package包/類
/**
 * Creates a proper {@link XMLInputSource} from a {@link StreamSource}.
 *
 * @return always return non-null valid object.
 */
public static final XMLInputSource toXMLInputSource( StreamSource in ) {
    if( in.getReader()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getReader(), null );
    if( in.getInputStream()!=null )
        return new XMLInputSource(
        in.getPublicId(), in.getSystemId(), in.getSystemId(),
        in.getInputStream(), null );

    return new XMLInputSource(
    in.getPublicId(), in.getSystemId(), in.getSystemId(), false );
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:19,代碼來源:Util.java

示例7: createSourceReader

import javax.xml.transform.stream.StreamSource; //導入方法依賴的package包/類
public static XMLStreamReader createSourceReader(Source source, boolean rejectDTDs, String charsetName) {
    try {
        if (source instanceof StreamSource) {
            StreamSource streamSource = (StreamSource) source;
            InputStream is = streamSource.getInputStream();

            if (is != null) {
                // Wrap input stream in Reader if charset is specified
                if (charsetName != null) {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), new InputStreamReader(is, charsetName), rejectDTDs);
                }
                else {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), is, rejectDTDs);
                }
            }
            else {
                Reader reader = streamSource.getReader();
                if (reader != null) {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), reader, rejectDTDs);
                }
                else {
                    return XMLStreamReaderFactory.create(
                        source.getSystemId(), new URL(source.getSystemId()).openStream(), rejectDTDs );
                }
            }
        }
        else if (source.getClass() == fastInfosetSourceClass) {
            return FastInfosetUtil.createFIStreamReader((InputStream)
                fastInfosetSource_getInputStream.invoke(source));
        }
        else if (source instanceof DOMSource) {
            DOMStreamReader dsr =  new DOMStreamReader();
            dsr.setCurrentNode(((DOMSource) source).getNode());
            return dsr;
        }
        else if (source instanceof SAXSource) {
            // TODO: need SAX to StAX adapter here -- Use transformer for now
            Transformer tx =  XmlUtil.newTransformer();
            DOMResult domResult = new DOMResult();
            tx.transform(source, domResult);
            return createSourceReader(
                new DOMSource(domResult.getNode()),
                rejectDTDs);
        }
        else {
            throw new XMLReaderException("sourceReader.invalidSource",
                    source.getClass().getName());
        }
    }
    catch (Exception e) {
        throw new XMLReaderException(e);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:57,代碼來源:SourceReaderFactory.java

示例8: getInputStreamFromSource

import javax.xml.transform.stream.StreamSource; //導入方法依賴的package包/類
private InputStream getInputStreamFromSource(StreamSource s)
    throws TransformerException {

    InputStream stream = s.getInputStream();
    if (stream != null)
        return stream;

    if (s.getReader() != null)
        return null;

    String systemId = s.getSystemId();
    if (systemId != null) {
        try {
            String fileURL = systemId;

            if (systemId.startsWith("file:///"))
            {
                /*
                 systemId is:
                 file:///<drive>:/some/path/file.xml
                 or
                 file:///some/path/file.xml
                */

                String absolutePath = systemId.substring(7);
                /*
                 /<drive>:/some/path/file.xml
                 or
                 /some/path/file.xml
                */

                boolean hasDriveDesignator = absolutePath.indexOf(":") > 0;
                if (hasDriveDesignator) {
                  String driveDesignatedPath = absolutePath.substring(1);
                  /*
                  <drive>:/some/path/file.xml */
                  fileURL = driveDesignatedPath;
                }
                else {
                  /*
                  /some/path/file.xml */
                  fileURL = absolutePath;
                }
            }
            //return new FileInputStream(fileURL);
            try {
                return new FileInputStream(new File(new URI(fileURL)));
            } catch (URISyntaxException ex) {
                throw new TransformerException(ex);
            }
        } catch (IOException e) {
            throw new TransformerException(e.toString());
        }
    }

    throw new TransformerException("Unexpected StreamSource object");
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:58,代碼來源:EfficientStreamingTransformer.java


注:本文中的javax.xml.transform.stream.StreamSource.getReader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。