List of usage examples for org.xml.sax InputSource getByteStream
public InputStream getByteStream()
From source file:Main.java
/** * Unmarshals an XML ({@link InputSource}) to a bean. * //from w ww.j av a 2 s.co m * @param is {@link InputSource} * @param clazz {@link Class} * @return bean * @throws JAXBException */ public static <T> T unmarshal(InputSource is, Class<T> clazz) throws JAXBException { return unmarshal(is.getByteStream(), clazz); }
From source file:net.sf.eclipsecs.core.builder.CheckerFactory.java
/** * Determines the additional data for a given configuration file. * * @param config/*from w w w .j a v a 2 s.com*/ * the check configuration * @param project * the project to create the checker for * @return the checker for the given configuration file * @throws CheckstylePluginException * the configuration could not be read */ public static ConfigurationReader.AdditionalConfigData getAdditionalData(ICheckConfiguration config, IProject project) throws CheckstylePluginException { String cacheKey = getCacheKey(config, project); AdditionalConfigData additionalData = sAdditionalDataMap.get(cacheKey); // no cache hit - create the additional data if (additionalData == null) { CheckstyleConfigurationFile configFileData = config.getCheckstyleConfiguration(); InputSource in = null; try { in = configFileData.getCheckConfigFileInputSource(); additionalData = ConfigurationReader.getAdditionalConfigData(in); } finally { IOUtils.closeQuietly(in.getByteStream()); } sAdditionalDataMap.put(cacheKey, additionalData); } return additionalData; }
From source file:net.sf.eclipsecs.core.builder.CheckerFactory.java
/** * Creates a checker for a given configuration file. * * @param config//from ww w . java 2s . c om * the check configuration data * @param project * the project to create the checker for * @return the checker for the given configuration file * @throws CheckstyleException * the configuration file had errors * @throws CheckstylePluginException * the configuration could not be read */ public static Checker createChecker(ICheckConfiguration config, IProject project) throws CheckstyleException, CheckstylePluginException { String cacheKey = getCacheKey(config, project); CheckstyleConfigurationFile configFileData = config.getCheckstyleConfiguration(); Checker checker = tryCheckerCache(cacheKey, configFileData.getModificationStamp()); // workaround for issue 377 applyTreeWalkerCacheWorkaround(checker); // no cache hit if (checker == null) { PropertyResolver resolver = configFileData.getPropertyResolver(); // set the project context if the property resolver needs the // context if (resolver instanceof IContextAware) { ((IContextAware) resolver).setProjectContext(project); } InputSource in = null; try { in = configFileData.getCheckConfigFileInputSource(); checker = createCheckerInternal(in, resolver, project); } finally { IOUtils.closeQuietly(in.getByteStream()); } // store checker in cache Long modified = new Long(configFileData.getModificationStamp()); sCheckerMap.put(cacheKey, checker); sModifiedMap.put(cacheKey, modified); } return checker; }
From source file:Main.java
public static Document getDocument(InputSource xml, InputStream xsd) throws ParserConfigurationException, SAXException, IOException { Document doc = null;//from w ww .j av a 2 s . c o m try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); if (xsd != null) { dbf.setNamespaceAware(true); } DocumentBuilder builder = dbf.newDocumentBuilder(); doc = builder.parse(xml); if (xsd != null) validateXml(doc, xsd); } finally { closeStream(xml.getByteStream()); } return doc; }
From source file:com.zotoh.core.io.StreamUte.java
/** * @param iso// w w w . j a v a2 s . com */ public static void resetInputSource(InputSource iso) { if (iso != null) { Reader rdr = iso.getCharacterStream(); InputStream ism = iso.getByteStream(); try { if (ism != null) ism.reset(); } catch (Exception e) { } try { if (rdr != null) rdr.reset(); } catch (Exception e) { } } }
From source file:com.meterware.httpunit.HttpUnitUtils.java
/** * parse the given inputSource with a new Parser * @param inputSource// w ww . j a va 2 s .com * @return the document parsed from the input Source */ public static Document parse(InputSource inputSource) throws SAXException, IOException { DocumentBuilder db = newParser(); try { Document doc = db.parse(inputSource); return doc; } catch (java.net.MalformedURLException mue) { if (EXCEPTION_DEBUG) { String msg = mue.getMessage(); if (msg != null) { System.err.println(msg); } InputStream is = inputSource.getByteStream(); is.reset(); String content = parseISToString(is); System.err.println(content); } throw mue; } }
From source file:com.eurelis.tools.xml.transformation.opencms.OpenCmsDocumentFeeder.java
@Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { InputSource constructedSource = null; InputSource originalSource = this.cmsXmlEntityResolver.resolveEntity(publicId, systemId); byte[] bytes = org.opencms.util.CmsFileUtil.readFully(originalSource.getByteStream()); String originalSourceString = org.opencms.i18n.CmsEncoder.createString(bytes, "UTF-8"); for (String entity : alreadyResolvedEntitySet) { originalSourceString = originalSourceString.replaceAll( "<xsd:include(?:/(?!>)|[^/])*schemaLocation=\"" + entity + "\"(?:/(?!>)|[^/])*/>", ""); }/*from w ww. j av a2 s . c o m*/ alreadyResolvedEntitySet.add(systemId); constructedSource = new InputSource(new StringReader(originalSourceString)); return constructedSource; }
From source file:com.adamrosenfield.wordswithcrosses.net.derstandard.SolutionParser.java
private Reader getReader(InputSource s) throws SAXException, IOException { Reader r = s.getCharacterStream(); InputStream i = s.getByteStream(); String encoding = s.getEncoding(); String publicid = s.getPublicId(); String systemid = s.getSystemId(); if (r == null) { if (i == null) i = getInputStream(publicid, systemid); // i = new BufferedInputStream(i); if (encoding == null) { r = theAutoDetector.autoDetectingReader(i); } else {/* www . j av a2 s. c om*/ try { r = new InputStreamReader(i, encoding); } catch (UnsupportedEncodingException e) { r = new InputStreamReader(i); } } } // r = new BufferedReader(r); return r; }
From source file:org.callimachusproject.xml.XdmNodeFactory.java
public XdmNode parse(String systemId) throws SAXException, IOException { InputSource isource = resolveEntity(null, systemId); if (isource == null) return null; try {/*ww w . j av a 2 s.com*/ return parse(isource); } finally { InputStream in = isource.getByteStream(); if (in != null) { in.close(); } Reader reader = isource.getCharacterStream(); if (reader != null) { reader.close(); } } }
From source file:de.ii.xtraplatform.ogc.api.gml.parser.GMLDictionaryParser.java
public void parse(InputSource is) { SMInputCursor root = null;//from ww w .jav a 2s. c o m try { root = staxFactory.rootElementCursor(is.getByteStream()).advance(); if (checkForExceptionReport(root)) { return; } parseNamespaces(root); //analyzer.analyzeVersion(root.getAttrValue(WFS.getWord(WFS.VOCABULARY.VERSION))); SMInputCursor dictionaryChild = root.childElementCursor().advance(); while (dictionaryChild.readerAccessible()) { switch (dictionaryChild.getLocalName()) { case "identifier": analyzer.analyzeIdentifier(dictionaryChild.collectDescendantText().trim()); break; case "name": analyzer.analyzeName(dictionaryChild.collectDescendantText().trim()); break; case "dictionaryEntry": parseEntry(dictionaryChild); break; } dictionaryChild = dictionaryChild.advance(); } } catch (XMLStreamException ex) { // TODO: move to analyzer for XtraProxy //LOGGER.error(FrameworkMessages.ERROR_PARSING_WFS_CAPABILITIES); //throw new ParseError(FrameworkMessages.ERROR_PARSING_WFS_CAPABILITIES); analyzer.analyzeFailed(ex); } finally { if (root != null) { try { root.getStreamReader().closeCompletely(); } catch (XMLStreamException ex) { // ignore } } } }