title: How can I use Java 8 Streams with an InputStream?
body: <p>I would like to wrap a <code>java.util.streams.Stream</code> around an <code>InputStream</code> to process one Byte or one Character at a time. I didn't find any simple way of doing this.</p>
  
  <p>Consider the following exercise: We wish to count the number of times each letter appears in a text file. We can store this in an array so that <code>tally[0]</code> will store the number of times a appears in the file, <code>tally[1]</code> stores the number of time b appears and so on. Since I couldn't find a way of streaming the file directly, I did this:</p>
  
  <pre><code> int[] tally = new int[26];
   Stream&lt;String&gt; lines = Files.lines(Path.get(aFile)).map(s -&gt; s.toLowerCase());
   Consumer&lt;String&gt; charCount = new Consumer&lt;String&gt;() {
     public void accept(String t) {
        for(int i=0; i&lt;t.length(); i++)
           if(Character.isLetter(t.charAt(i) )
              tall[t.charAt(i) - 'a' ]++;
     }
   };
   lines.forEach(charCount);
  </code></pre>
  
  <p>Is there a way of accomplishing this without using the <code>lines</code> method? Can I just process each character directly as a Stream or Stream instead of creating Strings for each line in the text file.</p>
  
  <p>Can I more direcly convert <code>java.io.InputStream</code> into <code>java.util.Stream.stream</code> ?</p>