Package com.substanceofcode.utils

Examples of com.substanceofcode.utils.EncodingUtil


          " to 2nd redirect url:  " + url);
    }
    m_redirect = true;
    m_redirectUrl = url;
    com.substanceofcode.rssreader.businessentities.RssItunesFeed[] feeds =
        HTMLLinkParser.parseFeeds(new EncodingUtil(is),
                  url, null, null, true
                  //#ifdef DLOGGING
                  ,logger,
                  fineLoggable,
                  finerLoggable,
View Full Code Here


    public RssItunesFeed[] parseFeeds(InputStream is)
    throws IOException, CauseMemoryException, CauseException, Exception {
        // Prepare buffer for input data
        StringBuffer inputBuffer = new StringBuffer();
       
    EncodingUtil encUtl = new EncodingUtil(is);
    EncodingStreamReader esr = encUtl.getEncodingStreamReader();

        try {
      // Read all data to buffer.  Use 100 char increments to save on
      // memory.
      inputBuffer = esr.readFile(100);
        } catch (IOException ex) {
      CauseException cex = new CauseException(
          "Error while parsing line by feed " + m_url, ex);
      throw cex;
        }
        String text;
    if (esr.isUtfDoc()) {
      final String fileEncoding = esr.getFileEncoding();
      if (esr.isUtf16Doc()) {
        encUtl.getEncoding(fileEncoding, "UTF-16");
      } else {
        encUtl.getEncoding(fileEncoding, "UTF-8");
      }
      final String docEncoding = encUtl.getDocEncoding();
      if (docEncoding.length() == 0) {
        text = inputBuffer.toString();
      } else {
        try {
          // We read the bytes in as ISO8859_1, so we must get them
View Full Code Here

    */
    public RssItunesFeed[] parseFeeds(InputStream is)
    throws IOException, CauseMemoryException, CauseException, Exception {
    // Init in case we get a severe error.
    try {
      return HTMLLinkParser.parseFeeds(new EncodingUtil(is),
                      m_url,
                      m_feedNameFilter,
                      m_feedURLFilter,
                      m_acceptErrors
                      //#ifdef DLOGGING
View Full Code Here

      }
      if (elementType == XmlParser.END_DOCUMENT ) {
        return null;
      }
           
      EncodingUtil encodingUtil = parser.getEncodingUtil();
            do {
        /** RSS item properties */
        String title = "";
        String link = "";
                       
        String tagName = parser.getName();
        System.out.println("tagname: " + tagName);
        if (tagName.equals("outline")) {
          System.out.println("Parsing <outline> tag");
         
          title = parser.getAttributeValue( "text" );
          if (title != null) {
            title = EncodingUtil.replaceAlphaEntities(true,
                title);
            // No need to convert from UTF-8 to Unicode using replace
            // umlauts now because it is done with new String...,encoding.

            // Replace numeric entities including &#8217;, &#8216;
            // &#8220;, and &#8221;
            title = EncodingUtil.replaceNumEntity(title);

            // Replace special chars like left quote, etc.
            // Since we have already converted to unicode, we want
            // to replace with uni chars.
            title = encodingUtil.replaceSpChars(title);
          }
          /**
           * Create new RSS item and add it do RSS document's item
           * collection.  Account for wrong OPML which is an
           * OPML composed of other OPML.  These have url attribute
View Full Code Here

    public RssItunesFeed[] parseFeeds(InputStream is)
    throws IOException, CauseMemoryException, CauseException, Exception {
    // Init in case we get a severe error.
    try {
      return HTMLAutoLinkParser.parseFeeds(new EncodingUtil(is),
                      m_url,
                      m_needRss,
                      m_needFirstRss,
                      m_feedNameFilter,
                      m_feedURLFilter
View Full Code Here

                    "/"+Common.DATA_FOLDER+"/" + Common.LANGUAGE_FILE);
      if (is == null) {
        throw new IOException("Unable to read file " +
                    "/"+Common.DATA_FOLDER+"/" + Common.LANGUAGE_FILE);
      }
      EncodingUtil encUtl = new EncodingUtil(is);
      EncodingStreamReader esr = encUtl.getEncodingStreamReader();
      StringBuffer inputBuffer;
      try {
        inputBuffer = esr.readFile(Common.LANGUAGE_FILE_LEN);
      } catch (IOException ex) {
        CauseException cex = new CauseException(
            "Error while reading file.", ex);
        throw cex;
      } finally {
        if (is != null) {
          try {
            is.close();
          } catch (Exception e) {
          }
        }
      }
      String text;
      /* If not UTF-8, treat it as one since we use XSL to create UTF-8.
         I couldn't create a file with BOM, so this is the next best
         thing.  */
      final String fileEncoding = esr.getFileEncoding();
      if (!esr.isUtfDoc()) {
        esr.setUtfDoc(true);
        encUtl.getEncoding(fileEncoding, "UTF-8");
      }
      if (esr.isUtfDoc()) {
        if (esr.isUtf16Doc()) {
          encUtl.getEncoding(fileEncoding, "UTF-16");
        } else {
          encUtl.getEncoding(fileEncoding, "UTF-8");
        }
        final String docEncoding = encUtl.getDocEncoding();
        if (docEncoding.length() == 0) {
          text = inputBuffer.toString();
        } else {
          try {
            // We read the bytes in as ISO8859_1, so we must get them
View Full Code Here

                    "/"+Common.DATA_FOLDER+"/" + Common.LANGUAGE_FILE);
      if (is == null) {
        throw new IOException("Unable to read file " +
                    "/"+Common.DATA_FOLDER+"/" + Common.LANGUAGE_FILE);
      }
      EncodingUtil encUtl = new EncodingUtil(is);
      EncodingStreamReader esr = encUtl.getEncodingStreamReader();
      StringBuffer inputBuffer;
      try {
        inputBuffer = esr.readFile(Common.LANGUAGE_FILE_LEN);
      } catch (IOException ex) {
        CauseException cex = new CauseException(
            "Error while reading file.", ex);
        throw cex;
      } finally {
        if (is != null) {
          try {
            is.close();
          } catch (Exception e) {
          }
        }
      }
      String text;
      /* If not UTF-8, treat it as one since we use XSL to create UTF-8.
         I couldn't create a file with BOM, so this is the next best
         thing.  */
      final String fileEncoding = esr.getFileEncoding();
      if (!esr.isUtfDoc()) {
        esr.setUtfDoc(true);
        encUtl.getEncoding(fileEncoding, "UTF-8");
      }
      if (esr.isUtfDoc()) {
        if (esr.isUtf16Doc()) {
          encUtl.getEncoding(fileEncoding, "UTF-16");
        } else {
          encUtl.getEncoding(fileEncoding, "UTF-8");
        }
        final String docEncoding = encUtl.getDocEncoding();
        if (docEncoding.length() == 0) {
          text = inputBuffer.toString();
        } else {
          try {
            // We read the bytes in as ISO8859_1, so we must get them
View Full Code Here

        final String isoEncoding, final boolean hasWinEncoding,
        final String winEncoding, final String encoding,
        final String expEncoding) {
    String data = "ab";
    ByteArrayInputStream bin = new ByteArrayInputStream( data.getBytes() );
    EncodingUtil encUtl = new EncodingUtil(bin);
    super.append("----------");
    super.append(new StringItem("hasIso8859Encoding=",
          new Boolean(hasIso8859Encoding).toString()));
    super.append(new StringItem("isoEncoding=", isoEncoding));
    super.append(new StringItem("hasWinEncoding=",
          new Boolean(hasWinEncoding).toString()));
    super.append(new StringItem("winEncoding=", winEncoding));
    super.append(new StringItem("encoding=", encoding));
    encUtl.getEncoding(hasIso8859Encoding, isoEncoding, hasWinEncoding,
        winEncoding, "BIG-5", encoding);
    super.append(new StringItem("(" + tstName + ") Exp Result:", "\n" +
        expEncoding));
    final String actEncoding = encUtl.getDocEncoding();
    super.append(new StringItem("(" + tstName + ") Act Result: ", "\n" +
        actEncoding));
    super.append("\n" + new Boolean(actEncoding.equals(
            expEncoding)).toString());
    Vector excs = encUtl.getExcs();
    for (int ic = 0; ic < excs.size(); ic++) {
      Exception exc = (Exception)excs.elementAt(ic);
      super.append(new StringItem("exc " + ic, "\n" +
          exc.getMessage()));
    }
View Full Code Here

          " to 2nd redirect url:  " + url);
    }
    m_redirect = true;
    m_redirectUrl = url;
    com.substanceofcode.rssreader.businessentities.RssItunesFeed[] feeds =
        HTMLLinkParser.parseFeeds(new EncodingUtil(is),
                  url, null, null, true
                  //#ifdef DLOGGING
//@                  ,logger,
//@                  fineLoggable,
//@                  finerLoggable,
View Full Code Here

    public RssItunesFeed[] parseFeeds(InputStream is)
    throws IOException, CauseMemoryException, CauseException, Exception {
        // Prepare buffer for input data
        StringBuffer inputBuffer = new StringBuffer();
       
    EncodingUtil encUtl = new EncodingUtil(is);
    EncodingStreamReader esr = encUtl.getEncodingStreamReader();

        try {
      // Read all data to buffer.  Use 100 char increments to save on
      // memory.
      inputBuffer = esr.readFile(100);
        } catch (IOException ex) {
      CauseException cex = new CauseException(
          "Error while parsing line by feed " + m_url, ex);
      throw cex;
        }
        String text;
    if (esr.isUtfDoc()) {
      final String fileEncoding = esr.getFileEncoding();
      if (esr.isUtf16Doc()) {
        encUtl.getEncoding(fileEncoding, "UTF-16");
      } else {
        encUtl.getEncoding(fileEncoding, "UTF-8");
      }
      final String docEncoding = encUtl.getDocEncoding();
      if (docEncoding.length() == 0) {
        text = inputBuffer.toString();
      } else {
        try {
          // We read the bytes in as ISO8859_1, so we must get them
View Full Code Here

TOP

Related Classes of com.substanceofcode.utils.EncodingUtil

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.