InputSource setEncoding - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for InputSource setEncoding method.

This code example shows how to use the following methods:setEncoding
			xr.setContentHandler(responsesHandler);
 
			ByteArrayInputStream tobeparsed = new ByteArrayInputStream(
					responseAsXML.getBytes("UTF-8"));
 
			InputSource is = new InputSource(tobeparsed);
			is.setEncoding("UTF-8");
			xr.parse(is);
 
			/* Parsing has finished. */ 
 
		} catch (FactoryConfigurationError e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
		} catch (SAXException e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
7
CodeRank
This code example shows how to use the following methods:setEncoding, setSystemId
      if (dictFile != null) // the dictionary can be empty.
        dictionary = getWordSet(loader, dictFile, false);
      // TODO: Broken, because we cannot resolve real system id 
      // ResourceLoader should also supply method like ClassLoader to get resource URL 
      stream = loader.openResource(hypFile);
      final InputSource is = new InputSource(stream);
      is.setEncoding(encoding); // if it's null let xml parser decide
      is.setSystemId(hypFile);
      hyphenator = HyphenationCompoundWordTokenFilter.getHyphenationTree(is);
    } finally { 
      IOUtils.closeWhileHandlingException(stream);
    } 
  } 
   
  @Override 
  public TokenFilter create(TokenStream input) {
    return new HyphenationCompoundWordTokenFilter(input, hyphenator, dictionary, minWordSize, minSubwordSize, maxSubwordSize, onlyLongestMatch);
  } 
} 
7
CodeRank
This code example shows how to use the following methods:setEncoding
         SAXParser sp = spf.newSAXParser();
         XMLReader xr = sp.getXMLReader();
 
         XMLMapRoute my_handler = new XMLMapRoute();
         xr.setContentHandler(my_handler);
         InputSource input_source = new InputSource(i_stream);
         input_source.setEncoding("utf-8");
         xr.parse(input_source);
 
         route = my_handler;
      } 
      catch (Exception e)
      { 
         Log.i("GMaps_route_parse", e.getMessage());
      } 
 
      return (route);
   } 
} 
6
CodeRank
This code example shows how to use the following methods:setEncoding
                SAXParser sParser = factory.newSAXParser();
                XMLReader parser = sParser.getXMLReader();
                JSONSAXHandler jsonHandler = new JSONSAXHandler(JSONStream, verbose);
                parser.setContentHandler(jsonHandler);
                parser.setErrorHandler(jsonHandler);
                InputSource source = new InputSource(new BufferedInputStream(XMLStream));
 
                if (logger.isLoggable(Level.FINEST)) {
                    logger.logp(Level.FINEST, className, "transform", "Parsing the XML content to JSON");
                } 
 
                /**  
                 * Parse it. 
                 */ 
                source.setEncoding("UTF-8");
                parser.parse(source);                 
                jsonHandler.flushBuffer();
            } catch (javax.xml.parsers.ParserConfigurationException pce) {
                throw new SAXException("Could not get a parser: " + pce.toString());
            } 
        } 
6
CodeRank
This code example shows how to use the following methods:setEncoding
    } 
    public Document readDocumentFromString(String body) throws ParserConfigurationException, IOException, SAXException {
        DocumentBuilderFactory fact = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = fact.newDocumentBuilder();
        StringReader reader = new StringReader(body);
        InputSource inputSource = new InputSource(reader);
        inputSource.setEncoding("UTF-8");
        Document doc = builder.parse(inputSource);
        reader.close();
        return doc;
    } 
    @SuppressWarnings({"ConstantConditions"}) 
    public String readStringFromUrl(String url) throws IOException {
 
        HttpURLConnection connection = null;
        try { 
            URL serverAddress = new URL(url);
            //set up out communications stuff 
            connection = null;
 
6
CodeRank
This code example shows how to use the following methods:setEncoding
        try { 
            SAXParserFactory spf = SAXParserFactory.newInstance();
            SAXParser sp = spf.newSAXParser();
            XMLReader xr = sp.getXMLReader();
            xr.setContentHandler(this);
            input.setEncoding("UTF-8");
            xr.parse(input);
        } catch (IOException e) {
            Log.e(TAG, e.toString());
            throw new SpotifyGatewayParseException(); 
        } catch (SAXException e) {
            Log.e(TAG, e.toString());
            throw new SpotifyGatewayParseException(); 
        } catch (ParserConfigurationException e) {
            Log.e(TAG, e.toString());
            throw new SpotifyGatewayParseException(); 
        } 
 
        return mTracks;
    } 
6
CodeRank
This code example shows how to use the following methods:setEncoding
			// On applique la classe handler qui va etre parsée 
			MeteoHandler meteoHandler = new MeteoHandler();
			xmlReader.setContentHandler(meteoHandler);
 
			// On ouvre l'URL qui correspond à la meteo en Java 
			InputSource input = new InputSource(url.openStream());
			input.setEncoding("ISO-8859-1");
			xmlReader.parse(input);
 
			// On stocke le contenu parsé 
			ParsedMeteoDataSet parsedExampleDataSet = meteoHandler
					.getParsedData(); 
 
			this.temperature = parsedExampleDataSet.getTemperatureCelsius();
			this.humidite = parsedExampleDataSet.getHumidity();
			this.ville = parsedExampleDataSet.getVille();
 
		} catch (Exception e) {
			// TODO Auto-generated catch block 
			e.printStackTrace();
6
CodeRank
This code example shows how to use the following methods:setEncoding
		if (streamSource.getInputStream() != null) {
			if (isProcessExternalEntities()) {
				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()) {
				return unmarshalReader(streamSource.getReader());
			} 
			else { 
				return unmarshalSaxSource(new SAXSource(new InputSource(streamSource.getReader())));
			} 
		} 
		else { 
			return unmarshalSaxSource(new SAXSource(new InputSource(streamSource.getSystemId())));
6
CodeRank
This code example shows how to use the following methods:setEncoding
        SAXParserFactory factory = SAXParserFactory.newInstance();
        try { 
            SAXParser parser = factory.newSAXParser();
            SurveyHandler handler = new SurveyHandler();   
            Reader reader = new InputStreamReader(inputStream,"UTF-8");
            InputSource source = new InputSource(reader);
            source.setEncoding("UTF-8");            
            parser.parse(source, handler);
            return handler.getSurvey();
        } catch (Exception e) {
            throw new RuntimeException(e);
        } 
    } 
 
} 
6
CodeRank
This code example shows how to use the following methods:setCharacterStream, setEncoding
        /* Create a new ContentHandler and apply it to the XML-Reader*/  
        ProjectXMLHandler mProjectXMLHandler = new ProjectXMLHandler(mContext);
        xr.setContentHandler(mProjectXMLHandler);
         
        /* Parse the xml-data from our URL. */ 
        InputSource inputSource = new InputSource();
        inputSource.setEncoding("UTF-8");
        inputSource.setCharacterStream(new StringReader(projectXmlResponce));
         
        /* Parse the xml-data from our URL. */ 
        xr.parse(inputSource);
        /* Parsing has finished. */ 
	} 
} 
6
CodeRank

Related InputSource setEncoding Questions & Answers:

setEncoding Method Overview
Set the character encoding, if known.
See Code Examples for other Java 8 InputSource Methods: