title: Effective way to read file and parse each line
body: <p>I have a text file of next format: each line starts with a string which is followed by sequence of numbers. Each line has unknown length (unknown amount of numbers, amount from 0 to 1000).</p>
  
  <pre><code>string_1 3 90 12 0 3
  string_2 49 0 12 94 13 8 38 1 95 3
  .......
  string_n 9 43
  </code></pre>
  
  <p>Afterwards I must handle each line with <code>handleLine</code> method which accept two arguments: string name and numbers set (<em>see code below</em>). </p>
  
  <p><em>How to read the file and handle each line with <code>handleLine</code> efficiently?</em> </p>
  
  <p>My workaround:</p>
  
  <ol>
  <li>Read file line by line with java8 streams <code>Files.lines</code>. <em>Is it blocking?</em></li>
  <li>Split each line with regexp</li>
  <li>Convert each line into header string and set of numbers</li>
  </ol>
  
  <p>I think it's pretty uneffective due 2nd and 3rd steps. 1st step mean that java convert file bytes to string first and then in 2nd and 3rd steps I convert them back to <code>String</code>/<code>Set&lt;Integer&gt;</code>. <em>Does that influence performance a lot? If yes - how to do better?</em></p>
  
  <pre><code>public handleFile(String filePath) {
      try (Stream&lt;String&gt; stream = Files.lines(Paths.get(filePath))) {
          stream.forEach(this::indexLine);
      } catch (IOException e) {
          e.printStackTrace();
      }
  }
  
  private void handleLine(String line) {
      List&lt;String&gt; resultList = this.parse(line);
      String string_i = resultList.remove(0);
      Set&lt;Integer&gt; numbers = resultList.stream().map(Integer::valueOf).collect(Collectors.toSet());
      handleLine(string_i, numbers); // Here is te final computation which must to be done only with string_i &amp; numbers arguments
  }
  
  private List&lt;String&gt; parse(String str) {
      List&lt;String&gt; output = new LinkedList&lt;String&gt;();
      Matcher match = Pattern.compile("[0-9]+|[a-z]+|[A-Z]+").matcher(str);
      while (match.find()) {
          output.add(match.group());
      }
      return output;
  }
  </code></pre>