Esempio n. 1
0
  private void processList(final List<String> lst) {
    lg.entering(getClass().getName(), "processList");

    try {

      String firstline = lst.remove(0);

      if (firstline.startsWith(tc.get_BOM())) {

        lg.info("First line starts with a BOM (Byte Order Mark)");
        /* We don’t keep it since we don't really need a BOM with UTF-8 encoding */
        firstline = firstline.substring(1, firstline.length());
      }

      /* the first line is either empty or an index number */
      System.out.println(firstline);

      // we don’t need to keep a reference on the InputStreamReader as
      // every underlying streams will be closed as soon as br will be…
      // br = new BufferedReader (new InputStreamReader (fis, StandardCharsets.UTF_8));
      // while ((s = br.readLine ()) != null) {

      /* for each string of our list */
      for (String s : lst) {

        // check first that s is not an index number (regex 1 digit or
        // more) nor a timecode (contains « --> »)
        // if (! s.matches ("\\d+") && ! s.isEmpty ()) {
        // by using a slightly different regex i.e., 0 or more digit(s)
        // we use the same call to check for empty lines
        if (!s.matches("\\d*") && !s.contains(" --> ")) {

          // System.out.println ("Before => " + s);

          /* process each matching line sequentially */
          s = processLineSeq(s);

          // System.out.println ("After  => " + s);
        }
        /* write the line to stdout (whether it has been processed or
         * not doesn’t really matter here) */
        System.out.println(s);
        /* for debugging only, very verbose since it’s in the (tight) loop
         * + not very useful, the BufferedReader implementation seems
         * to be using a 8192 bytes buffer */
        /* lg.info (String.format ("%d remaining bytes to read…", fis.available ())); */
      }

    } catch (Throwable t) {

      lg.severe(t.getLocalizedMessage());
    } /* finally {

          if (br != null) {

              try { br.close (); } catch (Throwable t) {

                  lg.warning (t.getLocalizedMessage ());
              }
          }
      } */

    lg.exiting(getClass().getName(), "processList");
  }