List of usage examples for org.xml.sax InputSource setByteStream
public void setByteStream(InputStream byteStream)
From source file:com.adaptris.transform.Source.java
public InputSource getInputSource() throws IOException, URISyntaxException { InputSource is = new InputSource(); if (this.url != null) { is.setSystemId(this.url); is.setCharacterStream(this.charStream); is.setByteStream(URLHelper.connect(url)); } else {/* w w w . java2 s.com*/ is.setSystemId(this.url); is.setCharacterStream(this.charStream); } return is; }
From source file:net.ontopia.topicmaps.nav2.portlets.pojos.TMRAP.java
private InputSource getInputSource(String endpoint, Collection psis) throws IOException { String uri = addParameters(endpoint, psis); URL url = new URL(uri); InputSource src = new InputSource(uri); src.setByteStream(url.openStream()); return src;// www. j a v a2s . co m }
From source file:de.smartics.maven.alias.MavenAliasMojo.java
private InputSource createSource() throws MojoExecutionException { final File file = new File(aliasLocation); try {/*from ww w. j a v a 2 s . c o m*/ final InputStream in = new BufferedInputStream(new FileInputStream(file)); final InputSource source = new InputSource(); source.setSystemId(aliasLocation); source.setByteStream(in); return source; } catch (final FileNotFoundException e) { throw new MojoExecutionException("Cannot read alias XML file '" + aliasLocation + "'.", e); } }
From source file:org.getwheat.harvest.library.dom.DomHelper.java
/** * Parses the entity content and returns a DOM Document. * <p />//from w w w . ja v a2 s . co m * This method uses the default system DocumentBuilderFactory to parse the entity's content * stream. * * @param entity * @return a DOM Document * @throws ParserConfigurationException * @throws IllegalStateException * @throws IOException * @throws SAXException * @see DocumentBuilderFactory */ public Document getDomDocument(final HttpEntity entity) throws ParserConfigurationException, IllegalStateException, IOException, SAXException { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); final DocumentBuilder builder = factory.newDocumentBuilder(); final InputSource input = new InputSource(); input.setByteStream(entity.getContent()); return builder.parse(input); }
From source file:javax.faces.webapp.ConfigFileTestCase.java
protected ConfigBase parseConfig(URL config) throws Exception { digester.clear();/*from www . ja va 2 s . c o m*/ digester.push(new ConfigBase()); InputSource iso = new InputSource(config.toExternalForm()); InputStream ist = config.openStream(); iso.setByteStream(ist); ConfigBase base = (ConfigBase) digester.parse(iso); ist.close(); return (base); }
From source file:hudson.XmlFile.java
/** * Parses the beginning of the file and determines the encoding. * * @throws IOException/* w ww . j a v a 2s. co m*/ * if failed to detect encoding. * @return * always non-null. */ public String sniffEncoding() throws IOException { class Eureka extends SAXException { final String encoding; public Eureka(String encoding) { this.encoding = encoding; } } try (InputStream in = Files.newInputStream(file.toPath())) { InputSource input = new InputSource(file.toURI().toASCIIString()); input.setByteStream(in); JAXP.newSAXParser().parse(input, new DefaultHandler() { private Locator loc; @Override public void setDocumentLocator(Locator locator) { this.loc = locator; } @Override public void startDocument() throws SAXException { attempt(); } @Override public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { attempt(); // if we still haven't found it at the first start element, then we are not going to find it. throw new Eureka(null); } private void attempt() throws Eureka { if (loc == null) return; if (loc instanceof Locator2) { Locator2 loc2 = (Locator2) loc; String e = loc2.getEncoding(); if (e != null) throw new Eureka(e); } } }); // can't reach here throw new AssertionError(); } catch (Eureka e) { if (e.encoding != null) return e.encoding; // the environment can contain old version of Xerces and others that do not support Locator2 // in such a case, assume UTF-8 rather than fail, since Jenkins internally always write XML in UTF-8 return "UTF-8"; } catch (SAXException e) { throw new IOException("Failed to detect encoding of " + file, e); } catch (InvalidPathException e) { throw new IOException(e); } catch (ParserConfigurationException e) { throw new AssertionError(e); // impossible } }
From source file:com.icesoft.jsfmeta.MetadataXmlParser.java
public FacesConfigBean parse(URL url, FacesConfigBean metadata) throws IOException, SAXException { configure();//from ww w.j av a2 s . c om digester.clear(); digester.push(metadata); InputSource source = null; InputStream stream = null; FacesConfigBean fcb = null; try { URLConnection urlConnection = url.openConnection(); stream = new BufferedInputStream(urlConnection.getInputStream()); source = new InputSource(url.toString()); source.setByteStream(stream); fcb = (FacesConfigBean) digester.parse(source); } catch (SAXException e) { System.err.println("Please check the syntax for the following file: " + url.getFile()); e.printStackTrace(); System.exit(1); } catch (IOException e) { System.err.println("Please check the syntax for the following file: " + url.getFile()); e.printStackTrace(); System.exit(1); } finally { if (stream != null) try { stream.close(); } catch (IOException e) { System.err.println("Please check the following file:" + url.getFile()); e.printStackTrace(); System.exit(1); } stream = null; } return fcb; }
From source file:net.ontopia.topicmaps.utils.tmrap.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)); }//from ww w. j ava2 s . com } else src.setByteStream(new java.util.zip.GZIPInputStream(conn.getInputStream())); return src; }
From source file:catalina.startup.Catalina.java
/** * Stop an existing server instance.//from w w w . j a v a2 s .co m */ protected void stop() { // Create and execute our Digester Digester digester = createStopDigester(); File file = configFile(); try { InputSource is = new InputSource("file://" + file.getAbsolutePath()); FileInputStream fis = new FileInputStream(file); is.setByteStream(fis); digester.push(this); digester.parse(is); fis.close(); } catch (Exception e) { System.out.println("Catalina.stop: " + e); e.printStackTrace(System.out); System.exit(1); } // Stop the existing server try { Socket socket = new Socket("127.0.0.1", server.getPort()); OutputStream stream = socket.getOutputStream(); String shutdown = server.getShutdown(); for (int i = 0; i < shutdown.length(); i++) stream.write(shutdown.charAt(i)); stream.flush(); stream.close(); socket.close(); } catch (IOException e) { System.out.println("Catalina.stop: " + e); e.printStackTrace(System.out); System.exit(1); } }
From source file:catalina.startup.Catalina.java
/** * Start a new server instance./*from www .ja va2 s . c o m*/ */ protected void start() { // Create and execute our Digester Digester digester = createStartDigester(); File file = configFile(); try { InputSource is = new InputSource("file://" + file.getAbsolutePath()); FileInputStream fis = new FileInputStream(file); is.setByteStream(fis); digester.push(this); digester.parse(is); fis.close(); } catch (Exception e) { System.out.println("Catalina.start: " + e); e.printStackTrace(System.out); System.exit(1); } // Setting additional variables if (!useNaming) { System.setProperty("catalina.useNaming", "false"); } else { System.setProperty("catalina.useNaming", "true"); String value = "org.apache.naming"; String oldValue = System.getProperty(javax.naming.Context.URL_PKG_PREFIXES); if (oldValue != null) { value = value + ":" + oldValue; } System.setProperty(javax.naming.Context.URL_PKG_PREFIXES, value); value = System.getProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY); if (value == null) { System.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory"); } } // If a SecurityManager is being used, set properties for // checkPackageAccess() and checkPackageDefinition if (System.getSecurityManager() != null) { String access = Security.getProperty("package.access"); if (access != null && access.length() > 0) access += ","; else access = "sun.,"; Security.setProperty("package.access", access + "org.apache.catalina.,org.apache.jasper."); String definition = Security.getProperty("package.definition"); if (definition != null && definition.length() > 0) definition += ","; else definition = "sun.,"; Security.setProperty("package.definition", // FIX ME package "javax." was removed to prevent HotSpot // fatal internal errors definition + "java.,org.apache.catalina.,org.apache.jasper."); } // Replace System.out and System.err with a custom PrintStream SystemLogHandler log = new SystemLogHandler(System.out); System.setOut(log); System.setErr(log); Thread shutdownHook = new CatalinaShutdownHook(); // Start the new server if (server instanceof Lifecycle) { try { server.initialize(); ((Lifecycle) server).start(); try { // Register shutdown hook Runtime.getRuntime().addShutdownHook(shutdownHook); } catch (Throwable t) { // This will fail on JDK 1.2. Ignoring, as Tomcat can run // fine without the shutdown hook. } // Wait for the server to be told to shut down server.await(); } catch (LifecycleException e) { System.out.println("Catalina.start: " + e); e.printStackTrace(System.out); if (e.getThrowable() != null) { System.out.println("----- Root Cause -----"); e.getThrowable().printStackTrace(System.out); } } } // Shut down the server if (server instanceof Lifecycle) { try { try { // Remove the ShutdownHook first so that server.stop() // doesn't get invoked twice Runtime.getRuntime().removeShutdownHook(shutdownHook); } catch (Throwable t) { // This will fail on JDK 1.2. Ignoring, as Tomcat can run // fine without the shutdown hook. } ((Lifecycle) server).stop(); } catch (LifecycleException e) { System.out.println("Catalina.stop: " + e); e.printStackTrace(System.out); if (e.getThrowable() != null) { System.out.println("----- Root Cause -----"); e.getThrowable().printStackTrace(System.out); } } } }