javax.xml.transform.stream.StreamSource#getReader ( )源码实例Demo

下面列出了javax.xml.transform.stream.StreamSource#getReader ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: hottub   文件: XMLInputFactoryImpl.java
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());
}
 
/**
 * Template method for handling {@code StreamSource}s.
 * <p>This implementation delegates to {@code unmarshalInputStream} or {@code unmarshalReader}.
 * @param streamSource the {@code StreamSource}
 * @return the object graph
 * @throws IOException if an I/O exception occurs
 * @throws XmlMappingException if the given source cannot be mapped to an object
 */
protected Object unmarshalStreamSource(StreamSource streamSource) throws XmlMappingException, IOException {
	if (streamSource.getInputStream() != null) {
		if (isProcessExternalEntities() && isSupportDtd()) {
			return unmarshalInputStream(streamSource.getInputStream());
		}
		else {
			InputSource inputSource = new InputSource(streamSource.getInputStream());
			inputSource.setEncoding(getDefaultEncoding());
			return unmarshalSaxSource(new SAXSource(inputSource));
		}
	}
	else if (streamSource.getReader() != null) {
		if (isProcessExternalEntities() && isSupportDtd()) {
			return unmarshalReader(streamSource.getReader());
		}
		else {
			return unmarshalSaxSource(new SAXSource(new InputSource(streamSource.getReader())));
		}
	}
	else {
		return unmarshalSaxSource(new SAXSource(new InputSource(streamSource.getSystemId())));
	}
}
 
源代码3 项目: openjdk-8-source   文件: XMLInputFactoryImpl.java
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());
}
 
/**
 * Template method for handling {@code StreamSource}s.
 * <p>This implementation delegates to {@code unmarshalInputStream} or {@code unmarshalReader}.
 * @param streamSource the {@code StreamSource}
 * @return the object graph
 * @throws IOException if an I/O exception occurs
 * @throws XmlMappingException if the given source cannot be mapped to an object
 */
protected Object unmarshalStreamSource(StreamSource streamSource) throws XmlMappingException, IOException {
	if (streamSource.getInputStream() != null) {
		if (isProcessExternalEntities() && isSupportDtd()) {
			return unmarshalInputStream(streamSource.getInputStream());
		}
		else {
			InputSource inputSource = new InputSource(streamSource.getInputStream());
			inputSource.setEncoding(getDefaultEncoding());
			return unmarshalSaxSource(new SAXSource(inputSource));
		}
	}
	else if (streamSource.getReader() != null) {
		if (isProcessExternalEntities() && isSupportDtd()) {
			return unmarshalReader(streamSource.getReader());
		}
		else {
			return unmarshalSaxSource(new SAXSource(new InputSource(streamSource.getReader())));
		}
	}
	else {
		return unmarshalSaxSource(new SAXSource(new InputSource(streamSource.getSystemId())));
	}
}
 
源代码5 项目: openjdk-jdk9   文件: XMLInputFactoryImpl.java
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());
}
 
源代码6 项目: jdk8u60   文件: XMLInputFactoryImpl.java
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());
}
 
源代码7 项目: spring-analysis-note   文件: XStreamMarshaller.java
@Override
protected Object unmarshalStreamSource(StreamSource streamSource) throws XmlMappingException, IOException {
	if (streamSource.getInputStream() != null) {
		return unmarshalInputStream(streamSource.getInputStream());
	}
	else if (streamSource.getReader() != null) {
		return unmarshalReader(streamSource.getReader());
	}
	else {
		throw new IllegalArgumentException("StreamSource contains neither InputStream nor Reader");
	}
}
 
源代码8 项目: jdk1.8-source-analysis   文件: Util.java
/**
 * 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() );
}
 
源代码9 项目: java-technology-stack   文件: XStreamMarshaller.java
@Override
protected Object unmarshalStreamSource(StreamSource streamSource) throws XmlMappingException, IOException {
	if (streamSource.getInputStream() != null) {
		return unmarshalInputStream(streamSource.getInputStream());
	}
	else if (streamSource.getReader() != null) {
		return unmarshalReader(streamSource.getReader());
	}
	else {
		throw new IllegalArgumentException("StreamSource contains neither InputStream nor Reader");
	}
}
 
源代码10 项目: openjdk-jdk9   文件: Util.java
/**
 * 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 );
}
 
源代码11 项目: sis   文件: Store.java
/**
 * Returns the input stream or reader set in the given source, or {@code null} if none.
 */
private static Closeable input(final StreamSource source) {
    Closeable in = null;
    if (source != null) {
        in = source.getInputStream();
        if (in == null) {
            in = source.getReader();
        }
    }
    return in;
}
 
源代码12 项目: openjdk-jdk8u   文件: Util.java
/**
 * 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() );
}
 
源代码13 项目: validator   文件: SourceInput.java
private boolean isConsumed() throws IOException {
    if (isStreamSource()) {

        final StreamSource ss = (StreamSource) this.source;
        try {
            return (ss.getInputStream() != null && ss.getInputStream().available() == 0)
                    || (ss.getReader() != null && !ss.getReader().ready());
        } catch (final IOException e) {
            log.error("Error checking consumed state", e);
            return true;
        }
    }
    return false;
}
 
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");
}
 
源代码15 项目: hottub   文件: EfficientStreamingTransformer.java
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");
}
 
源代码16 项目: jdk8u60   文件: SourceReaderFactory.java
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);
    }
}
 
源代码17 项目: jdk8u60   文件: EfficientStreamingTransformer.java
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");
}
 
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");
}
 
源代码19 项目: openjdk-jdk9   文件: SourceReaderFactory.java
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);
    }
}
 
源代码20 项目: openjdk-jdk8u-backup   文件: SourceReaderFactory.java
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);
    }
}