title: java.lang.IllegalStateException: Iterator already obtained
body: <p>I modified this code to do several tasks in one directory:</p>
  
  <pre><code>public class HDDSerialNumber
  {
  
      public void getHDDSerialNumber() throws IOException
      {
          try (DirectoryStream&lt;Path&gt; ds = Files.newDirectoryStream(Paths.get("/sys/block"), "sd*"))
          {
              // Get HDD Model
              StreamSupport.stream(ds.spliterator(), false)
                  .map(p -&gt; p.resolve("device/model")).flatMap(wrap(Files::lines))
                  .forEach(System.out::println);
  
              // Get HDD Vendor
              StreamSupport.stream(ds.spliterator(), false)
                  .map(p -&gt; p.resolve("device/vendor")).flatMap(wrap(Files::lines))
                  .forEach(System.out::println);
  
              // Get HDD Vendor
              StreamSupport.stream(ds.spliterator(), false)
                  .map(p -&gt; p.resolve("device/state")).flatMap(wrap(Files::lines))
                  .forEach(System.out::println);
          }
      }
  
      static &lt;T, R&gt; Function&lt;T, R&gt; wrap(IOFunction&lt;T, R&gt; f)
      {
          return t -&gt;
          {
              try
              {
                  return f.apply(t);
              }
              catch (IOException ex)
              {
                  throw new UncheckedIOException(ex);
              }
          };
      }
  
      interface IOFunction&lt;T, R&gt;
      {
          R apply(T in) throws IOException;
      }
  }
  </code></pre>
  
  <p>But when I run the code I get this error stack:</p>
  
  <pre><code>run:
  ST320LT012-9WS14
  Exception in thread "main" java.lang.IllegalStateException: Iterator already obtained
      at sun.nio.fs.UnixDirectoryStream.iterator(UnixDirectoryStream.java:118)
      at sun.nio.fs.UnixSecureDirectoryStream.iterator(UnixSecureDirectoryStream.java:73)
      at java.lang.Iterable.spliterator(Iterable.java:101)
      at hardware.HDDSerialNumber.getHDDSerialNumber(HDDSerialNumber.java:25)
      at hardware.Hardware.main(Hardware.java:12)
  Java Result: 1
  </code></pre>
  
  <p>Can you help me to fix the code, please? I suppose that Iterator already obtained must be used only once in this example but I don't have idea how to fix this.</p>