org.xml.sax.InputSource#setByteStream ( )源码实例Demo

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

源代码1 项目: openjdk-8-source   文件: SAXSource.java
/**
 * Attempt to obtain a SAX InputSource object from a Source
 * object.
 *
 * @param source Must be a non-null Source reference.
 *
 * @return An InputSource, or null if Source can not be converted.
 */
public static InputSource sourceToInputSource(Source source) {

    if (source instanceof SAXSource) {
        return ((SAXSource) source).getInputSource();
    } else if (source instanceof StreamSource) {
        StreamSource ss      = (StreamSource) source;
        InputSource  isource = new InputSource(ss.getSystemId());

        isource.setByteStream(ss.getInputStream());
        isource.setCharacterStream(ss.getReader());
        isource.setPublicId(ss.getPublicId());

        return isource;
    } else {
        return null;
    }
}
 
源代码2 项目: ontopia   文件: RemoteTopicIndex.java
protected InputSource getInputSource(String method, String params,
                                     boolean compress)
  throws IOException {
  
  String baseuri = viewBaseuri == null ? editBaseuri : viewBaseuri;
  String url = baseuri + method + "?" + params;
  URLConnection conn = this.getConnection(url, 0);
  InputSource src = new InputSource(url);

  if (!compress) {
    src.setByteStream(conn.getInputStream());
  
    String ctype = conn.getContentType();
    if (ctype != null && ctype.startsWith("text/xml")) {
      int pos = ctype.indexOf("charset=");
      if (pos != -1) src.setEncoding(ctype.substring(pos + 8));
    }
  } else
    src.setByteStream(new java.util.zip.GZIPInputStream(conn.getInputStream()));
  
  return src;
}
 
源代码3 项目: jdk1.8-source-analysis   文件: SAXSource.java
/**
 * Attempt to obtain a SAX InputSource object from a Source
 * object.
 *
 * @param source Must be a non-null Source reference.
 *
 * @return An InputSource, or null if Source can not be converted.
 */
public static InputSource sourceToInputSource(Source source) {

    if (source instanceof SAXSource) {
        return ((SAXSource) source).getInputSource();
    } else if (source instanceof StreamSource) {
        StreamSource ss      = (StreamSource) source;
        InputSource  isource = new InputSource(ss.getSystemId());

        isource.setByteStream(ss.getInputStream());
        isource.setCharacterStream(ss.getReader());
        isource.setPublicId(ss.getPublicId());

        return isource;
    } else {
        return null;
    }
}
 
源代码4 项目: hottub   文件: SAXSource.java
/**
 * Attempt to obtain a SAX InputSource object from a Source
 * object.
 *
 * @param source Must be a non-null Source reference.
 *
 * @return An InputSource, or null if Source can not be converted.
 */
public static InputSource sourceToInputSource(Source source) {

    if (source instanceof SAXSource) {
        return ((SAXSource) source).getInputSource();
    } else if (source instanceof StreamSource) {
        StreamSource ss      = (StreamSource) source;
        InputSource  isource = new InputSource(ss.getSystemId());

        isource.setByteStream(ss.getInputStream());
        isource.setCharacterStream(ss.getReader());
        isource.setPublicId(ss.getPublicId());

        return isource;
    } else {
        return null;
    }
}
 
源代码5 项目: JDKSourceCode1.8   文件: ValidatorHandlerImpl.java
/**
 * Resolves the given resource and adapts the <code>LSInput</code>
 * returned into an <code>InputSource</code>.
 */
public InputSource resolveEntity(String name, String publicId,
        String baseURI, String systemId) throws SAXException, IOException {
    if (fEntityResolver != null) {
        LSInput lsInput = fEntityResolver.resolveResource(XML_TYPE, null, publicId, systemId, baseURI);
        if (lsInput != null) {
            final String pubId = lsInput.getPublicId();
            final String sysId = lsInput.getSystemId();
            final String baseSystemId = lsInput.getBaseURI();
            final Reader charStream = lsInput.getCharacterStream();
            final InputStream byteStream = lsInput.getByteStream();
            final String data = lsInput.getStringData();
            final String encoding = lsInput.getEncoding();

            /**
             * An LSParser looks at inputs specified in LSInput in
             * the following order: characterStream, byteStream,
             * stringData, systemId, publicId. For consistency
             * with the DOM Level 3 Load and Save Recommendation
             * use the same lookup order here.
             */
            InputSource inputSource = new InputSource();
            inputSource.setPublicId(pubId);
            inputSource.setSystemId((baseSystemId != null) ? resolveSystemId(systemId, baseSystemId) : systemId);

            if (charStream != null) {
                inputSource.setCharacterStream(charStream);
            }
            else if (byteStream != null) {
                inputSource.setByteStream(byteStream);
            }
            else if (data != null && data.length() != 0) {
                inputSource.setCharacterStream(new StringReader(data));
            }
            inputSource.setEncoding(encoding);
            return inputSource;
        }
    }
    return null;
}
 
/**
 * Resolves the given resource and adapts the <code>LSInput</code>
 * returned into an <code>InputSource</code>.
 */
public InputSource resolveEntity(String name, String publicId,
        String baseURI, String systemId) throws SAXException, IOException {
    if (fEntityResolver != null) {
        LSInput lsInput = fEntityResolver.resolveResource(XML_TYPE, null, publicId, systemId, baseURI);
        if (lsInput != null) {
            final String pubId = lsInput.getPublicId();
            final String sysId = lsInput.getSystemId();
            final String baseSystemId = lsInput.getBaseURI();
            final Reader charStream = lsInput.getCharacterStream();
            final InputStream byteStream = lsInput.getByteStream();
            final String data = lsInput.getStringData();
            final String encoding = lsInput.getEncoding();

            /**
             * An LSParser looks at inputs specified in LSInput in
             * the following order: characterStream, byteStream,
             * stringData, systemId, publicId. For consistency
             * with the DOM Level 3 Load and Save Recommendation
             * use the same lookup order here.
             */
            InputSource inputSource = new InputSource();
            inputSource.setPublicId(pubId);
            inputSource.setSystemId((baseSystemId != null) ? resolveSystemId(systemId, baseSystemId) : systemId);

            if (charStream != null) {
                inputSource.setCharacterStream(charStream);
            }
            else if (byteStream != null) {
                inputSource.setByteStream(byteStream);
            }
            else if (data != null && data.length() != 0) {
                inputSource.setCharacterStream(new StringReader(data));
            }
            inputSource.setEncoding(encoding);
            return inputSource;
        }
    }
    return null;
}
 
@Override
public void scan(File file, String webappPath, boolean isWebapp) throws IOException {

    WebXml fragment = new WebXml();
    fragment.setWebappJar(isWebapp);
    fragment.setDelegate(delegate);

    File fragmentFile = new File(file, FRAGMENT_LOCATION);
    try {
        if (fragmentFile.isFile()) {
            try (InputStream stream = new FileInputStream(fragmentFile)) {
                InputSource source =
                    new InputSource(fragmentFile.toURI().toURL().toString());
                source.setByteStream(stream);
                if (!webXmlParser.parseWebXml(source, fragment, true)) {
                    ok = false;
                }
            }
        } else {
            // If there is no web.xml, normal folder no impact on
            // distributable
            fragment.setDistributable(true);
        }
    } finally {
        addFragment(fragment, file.toURI().toURL());
    }
}
 
源代码8 项目: openjdk-jdk9   文件: ValidatorHandlerImpl.java
/**
 * Resolves the given resource and adapts the <code>LSInput</code>
 * returned into an <code>InputSource</code>.
 */
public InputSource resolveEntity(String name, String publicId,
        String baseURI, String systemId) throws SAXException, IOException {
    if (fEntityResolver != null) {
        LSInput lsInput = fEntityResolver.resolveResource(XML_TYPE, null, publicId, systemId, baseURI);
        if (lsInput != null) {
            final String pubId = lsInput.getPublicId();
            final String sysId = lsInput.getSystemId();
            final String baseSystemId = lsInput.getBaseURI();
            final Reader charStream = lsInput.getCharacterStream();
            final InputStream byteStream = lsInput.getByteStream();
            final String data = lsInput.getStringData();
            final String encoding = lsInput.getEncoding();

            /**
             * An LSParser looks at inputs specified in LSInput in
             * the following order: characterStream, byteStream,
             * stringData, systemId, publicId. For consistency
             * with the DOM Level 3 Load and Save Recommendation
             * use the same lookup order here.
             */
            InputSource inputSource = new InputSource();
            inputSource.setPublicId(pubId);
            inputSource.setSystemId((baseSystemId != null) ? resolveSystemId(sysId, baseSystemId) : sysId);

            if (charStream != null) {
                inputSource.setCharacterStream(charStream);
            }
            else if (byteStream != null) {
                inputSource.setByteStream(byteStream);
            }
            else if (data != null && data.length() != 0) {
                inputSource.setCharacterStream(new StringReader(data));
            }
            inputSource.setEncoding(encoding);
            return inputSource;
        }
    }
    return null;
}
 
源代码9 项目: Bytecoder   文件: ValidatorHandlerImpl.java
/**
 * Resolves the given resource and adapts the <code>LSInput</code>
 * returned into an <code>InputSource</code>.
 */
public InputSource resolveEntity(String name, String publicId,
        String baseURI, String systemId) throws SAXException, IOException {
    if (fEntityResolver != null) {
        LSInput lsInput = fEntityResolver.resolveResource(XML_TYPE, null, publicId, systemId, baseURI);
        if (lsInput != null) {
            final String pubId = lsInput.getPublicId();
            final String sysId = lsInput.getSystemId();
            final String baseSystemId = lsInput.getBaseURI();
            final Reader charStream = lsInput.getCharacterStream();
            final InputStream byteStream = lsInput.getByteStream();
            final String data = lsInput.getStringData();
            final String encoding = lsInput.getEncoding();

            /**
             * An LSParser looks at inputs specified in LSInput in
             * the following order: characterStream, byteStream,
             * stringData, systemId, publicId. For consistency
             * with the DOM Level 3 Load and Save Recommendation
             * use the same lookup order here.
             */
            InputSource inputSource = new InputSource();
            inputSource.setPublicId(pubId);
            inputSource.setSystemId((baseSystemId != null) ? resolveSystemId(sysId, baseSystemId) : sysId);

            if (charStream != null) {
                inputSource.setCharacterStream(charStream);
            }
            else if (byteStream != null) {
                inputSource.setByteStream(byteStream);
            }
            else if (data != null && data.length() != 0) {
                inputSource.setCharacterStream(new StringReader(data));
            }
            inputSource.setEncoding(encoding);
            return inputSource;
        }
    }
    return null;
}
 
源代码10 项目: openjdk-8-source   文件: UnmarshallerImpl.java
private static InputSource streamSourceToInputSource( StreamSource ss ) {
    InputSource is = new InputSource();
    is.setSystemId( ss.getSystemId() );
    is.setByteStream( ss.getInputStream() );
    is.setCharacterStream( ss.getReader() );

    return is;
}
 
源代码11 项目: openjdk-8   文件: AbstractUnmarshallerImpl.java
private static InputSource streamSourceToInputSource( StreamSource ss ) {
    InputSource is = new InputSource();
    is.setSystemId( ss.getSystemId() );
    is.setByteStream( ss.getInputStream() );
    is.setCharacterStream( ss.getReader() );

    return is;
}
 
源代码12 项目: openjdk-jdk8u-backup   文件: CatalogResolver.java
/**
 * Implements the <code>resolveEntity</code> method
 * for the SAX interface.
 *
 * <p>Presented with an optional public identifier and a system
 * identifier, this function attempts to locate a mapping in the
 * catalogs.</p>
 *
 * <p>If such a mapping is found, the resolver attempts to open
 * the mapped value as an InputSource and return it. Exceptions are
 * ignored and null is returned if the mapped value cannot be opened
 * as an input source.</p>
 *
 * <p>If no mapping is found (or an error occurs attempting to open
 * the mapped value as an input source), null is returned and the system
 * will use the specified system identifier as if no entityResolver
 * was specified.</p>
 *
 * @param publicId  The public identifier for the entity in question.
 * This may be null.
 *
 * @param systemId  The system identifier for the entity in question.
 * XML requires a system identifier on all external entities, so this
 * value is always specified.
 *
 * @return An InputSource for the mapped identifier, or null.
 */
public InputSource resolveEntity (String publicId, String systemId) {
  String resolved = getResolvedEntity(publicId, systemId);

  if (resolved != null) {
    try {
      InputSource iSource = new InputSource(resolved);
      iSource.setPublicId(publicId);

      // Ideally this method would not attempt to open the
      // InputStream, but there is a bug (in Xerces, at least)
      // that causes the parser to mistakenly open the wrong
      // system identifier if the returned InputSource does
      // not have a byteStream.
      //
      // It could be argued that we still shouldn't do this here,
      // but since the purpose of calling the entityResolver is
      // almost certainly to open the input stream, it seems to
      // do little harm.
      //
      URL url = new URL(resolved);
      InputStream iStream = url.openStream();
      iSource.setByteStream(iStream);

      return iSource;
    } catch (Exception e) {
      catalogManager.debug.message(1, "Failed to create InputSource", resolved);
      return null;
    }
  }

  return null;
}
 
源代码13 项目: openjdk-jdk9   文件: CatalogResolver.java
/**
 * Implements the <code>resolveEntity</code> method
 * for the SAX interface.
 *
 * <p>Presented with an optional public identifier and a system
 * identifier, this function attempts to locate a mapping in the
 * catalogs.</p>
 *
 * <p>If such a mapping is found, the resolver attempts to open
 * the mapped value as an InputSource and return it. Exceptions are
 * ignored and null is returned if the mapped value cannot be opened
 * as an input source.</p>
 *
 * <p>If no mapping is found (or an error occurs attempting to open
 * the mapped value as an input source), null is returned and the system
 * will use the specified system identifier as if no entityResolver
 * was specified.</p>
 *
 * @param publicId  The public identifier for the entity in question.
 * This may be null.
 *
 * @param systemId  The system identifier for the entity in question.
 * XML requires a system identifier on all external entities, so this
 * value is always specified.
 *
 * @return An InputSource for the mapped identifier, or null.
 */
public InputSource resolveEntity (String publicId, String systemId) {
  String resolved = getResolvedEntity(publicId, systemId);

  if (resolved != null) {
    try {
      InputSource iSource = new InputSource(resolved);
      iSource.setPublicId(publicId);

      // Ideally this method would not attempt to open the
      // InputStream, but there is a bug (in Xerces, at least)
      // that causes the parser to mistakenly open the wrong
      // system identifier if the returned InputSource does
      // not have a byteStream.
      //
      // It could be argued that we still shouldn't do this here,
      // but since the purpose of calling the entityResolver is
      // almost certainly to open the input stream, it seems to
      // do little harm.
      //
      URL url = new URL(resolved);
      InputStream iStream = url.openStream();
      iSource.setByteStream(iStream);

      return iSource;
    } catch (Exception e) {
      catalogManager.debug.message(1,
                                   "Failed to create InputSource ("
                                   + e.toString()
                                   + ")", resolved);
      return null;
    }
  }

  return null;
}
 
源代码14 项目: TranskribusCore   文件: XmlUtils.java
/**
 * @param xmlFile the full path of the xml document 2 parse
 * @param encoding set the encoding in which the file should be read
 * @return an xml-Document object based on the file content
 */
public static Document getDocumentFromFile(File xmlFile, String encoding) throws ParserConfigurationException,
		SAXException, IOException
{
	/*
	 * InputSource input = new InputSource(new FileInputStream(xmlFile));
	 * input.setEncoding("ISO-8859-1");
	 */ 
	InputSource input = new InputSource();
	input.setEncoding(encoding);
	input.setByteStream(new FileInputStream(xmlFile));
	return getDocument(input);
}
 
源代码15 项目: TencentKona-8   文件: UnmarshallerImpl.java
private static InputSource streamSourceToInputSource( StreamSource ss ) {
    InputSource is = new InputSource();
    is.setSystemId( ss.getSystemId() );
    is.setByteStream( ss.getInputStream() );
    is.setCharacterStream( ss.getReader() );

    return is;
}
 
源代码16 项目: jdk8u60   文件: AbstractUnmarshallerImpl.java
private static InputSource streamSourceToInputSource( StreamSource ss ) {
    InputSource is = new InputSource();
    is.setSystemId( ss.getSystemId() );
    is.setByteStream( ss.getInputStream() );
    is.setCharacterStream( ss.getReader() );

    return is;
}
 
源代码17 项目: openjdk-jdk9   文件: BootstrapResolver.java
/** SAX resolveEntity API. */
public InputSource resolveEntity (String publicId, String systemId) {
  String resolved = null;

  if (systemId != null && systemMap.containsKey(systemId)) {
    resolved = systemMap.get(systemId);
  } else if (publicId != null && publicMap.containsKey(publicId)) {
    resolved = publicMap.get(publicId);
  }

  if (resolved != null) {
    try {
      InputSource iSource = new InputSource(resolved);
      iSource.setPublicId(publicId);

      // Ideally this method would not attempt to open the
      // InputStream, but there is a bug (in Xerces, at least)
      // that causes the parser to mistakenly open the wrong
      // system identifier if the returned InputSource does
      // not have a byteStream.
      //
      // It could be argued that we still shouldn't do this here,
      // but since the purpose of calling the entityResolver is
      // almost certainly to open the input stream, it seems to
      // do little harm.
      //
      URL url = new URL(resolved);
      InputStream iStream = url.openStream();
      iSource.setByteStream(iStream);

      return iSource;
    } catch (Exception e) {
      // FIXME: silently fail?
      return null;
    }
  }

  return null;
}
 
源代码18 项目: TencentKona-8   文件: ResolvingXMLFilter.java
/**
 * Implements the <code>resolveEntity</code> method
 * for the SAX interface, using an underlying CatalogResolver
 * to do the real work.
 */
public InputSource resolveEntity (String publicId, String systemId) {
  allowXMLCatalogPI = false;
  String resolved = catalogResolver.getResolvedEntity(publicId, systemId);

  if (resolved == null && piCatalogResolver != null) {
    resolved = piCatalogResolver.getResolvedEntity(publicId, systemId);
  }

  if (resolved != null) {
    try {
      InputSource iSource = new InputSource(resolved);
      iSource.setPublicId(publicId);

      // Ideally this method would not attempt to open the
      // InputStream, but there is a bug (in Xerces, at least)
      // that causes the parser to mistakenly open the wrong
      // system identifier if the returned InputSource does
      // not have a byteStream.
      //
      // It could be argued that we still shouldn't do this here,
      // but since the purpose of calling the entityResolver is
      // almost certainly to open the input stream, it seems to
      // do little harm.
      //
      URL url = new URL(resolved);
      InputStream iStream = url.openStream();
      iSource.setByteStream(iStream);

      return iSource;
    } catch (Exception e) {
      catalogManager.debug.message(1, "Failed to create InputSource", resolved);
      return null;
    }
  } else {
    return null;
  }
}
 
源代码19 项目: openjdk-8   文件: ValidatorHandlerImpl.java
/**
 * Resolves the given resource and adapts the <code>LSInput</code>
 * returned into an <code>InputSource</code>.
 */
public InputSource resolveEntity(String name, String publicId,
        String baseURI, String systemId) throws SAXException, IOException {
    if (fEntityResolver != null) {
        LSInput lsInput = fEntityResolver.resolveResource(XML_TYPE, null, publicId, systemId, baseURI);
        if (lsInput != null) {
            final String pubId = lsInput.getPublicId();
            final String sysId = lsInput.getSystemId();
            final String baseSystemId = lsInput.getBaseURI();
            final Reader charStream = lsInput.getCharacterStream();
            final InputStream byteStream = lsInput.getByteStream();
            final String data = lsInput.getStringData();
            final String encoding = lsInput.getEncoding();

            /**
             * An LSParser looks at inputs specified in LSInput in
             * the following order: characterStream, byteStream,
             * stringData, systemId, publicId. For consistency
             * with the DOM Level 3 Load and Save Recommendation
             * use the same lookup order here.
             */
            InputSource inputSource = new InputSource();
            inputSource.setPublicId(pubId);
            inputSource.setSystemId((baseSystemId != null) ? resolveSystemId(systemId, baseSystemId) : systemId);

            if (charStream != null) {
                inputSource.setCharacterStream(charStream);
            }
            else if (byteStream != null) {
                inputSource.setByteStream(byteStream);
            }
            else if (data != null && data.length() != 0) {
                inputSource.setCharacterStream(new StringReader(data));
            }
            inputSource.setEncoding(encoding);
            return inputSource;
        }
    }
    return null;
}
 
源代码20 项目: openjdk-jdk9   文件: ResolvingParser.java
/**
 * Implements the <code>resolveEntity</code> method
 * for the SAX interface, using an underlying CatalogResolver
 * to do the real work.
 */
public InputSource resolveEntity (String publicId, String systemId) {
  allowXMLCatalogPI = false;
  String resolved = catalogResolver.getResolvedEntity(publicId, systemId);

  if (resolved == null && piCatalogResolver != null) {
    resolved = piCatalogResolver.getResolvedEntity(publicId, systemId);
  }

  if (resolved != null) {
    try {
      InputSource iSource = new InputSource(resolved);
      iSource.setPublicId(publicId);

      // Ideally this method would not attempt to open the
      // InputStream, but there is a bug (in Xerces, at least)
      // that causes the parser to mistakenly open the wrong
      // system identifier if the returned InputSource does
      // not have a byteStream.
      //
      // It could be argued that we still shouldn't do this here,
      // but since the purpose of calling the entityResolver is
      // almost certainly to open the input stream, it seems to
      // do little harm.
      //
      URL url = new URL(resolved);
      InputStream iStream = url.openStream();
      iSource.setByteStream(iStream);

      return iSource;
    } catch (Exception e) {
      catalogManager.debug.message(1,
                                   "Failed to create InputSource ("
                                   + e.toString()
                                   + ")", resolved);
      return null;
    }
  } else {
    return null;
  }
}