title: Java SequenceInputStream
body: <p>I try to send multiple Files from my Server (NanoHttpd) to my Client (Apache DefaultHttpClient).<br>
  My approach is to send multiple files via one Response of NanoHttpd.<br>
  For this purpose i wanted to use SequenceInputStream.<br>
  I am trying to concatenate multiple Files, send them via the Response (InputStream) and write every File again in a seperate File with my Client.<br>
  On the Serverside i call this:  </p>
  
  <pre><code>List&lt;InputStream&gt; data = new ArrayList&lt;InputStream&gt;(o_file_path.size());
  for (String file_name : files)
  {
      File file = new File(file_name);
      data.add(new FileInputStream(file));
  }
  InputStream is = new SequenceInputStream(Collections.enumeration(data));
  return new NanoHTTPD.Response(HTTP_OK, "application/octet-stream", is);
  </code></pre>
  
  <p>Now my Question is how to receive and split the Files correctly.<br>
  I have tried it this way on my client, but it does not work:</p>
  
  <pre><code>int read = 0;
  int remaining = 0;
  byte[] bytes = new byte[buffer];
  
  // Read till the end of the Stream
  while ( (read != -1) &amp;&amp; (counter &lt; files.size()))
  {
      // Create a .o file for the current file
      read = 0;
      remaining = is.available();
  
      // Should open each Stream          
      while (remaining &gt; 0)
      {
          read = is.read(bytes);
          remaining = remaining - read;
          os.write(bytes, 0, read);
      }
  
      os.flush();
      os.close();
  }
  </code></pre>
  
  <p>This way I want to go over all Stream (untill read == 1, or i know there is no file anymore), and read any stream into a file.  </p>
  
  <p>I clearly seem to understand something groundbreaking wrong, since is.available() always is 0.<br>
  Could anyone please tell me how to read properly from this SequencedInputStream, or how to solve my Problem.  </p>
  
  <p>Thanks in advance.</p>