title: How InputStream's read() method is implemented?
body: <p>For the specific task I am trying to override <code>read()</code> method for my custom class that extends InputStream.</p>
  
  <p>So far my implementation is:</p>
  
  <pre><code>private ArrayList&lt;byte[]&gt; inputBuffer = new ArrayList&lt;&gt;(); 
  ...
  @Override
  public int read(@NonNull byte[] b) throws IOException {
      if (inputBuffer.size() &gt; 0) {
          b = inputBuffer.get(0);
          inputBuffer.remove(0);
      } else
          return -1;
  
      return b.length;
  }
  </code></pre>
  
  <p>And I am adding data to my <code>InputStream</code> like this:</p>
  
  <pre><code>boolean writeDataToInputStream(byte[] data) {
      int arrSize = inputBuffer.size();
      if (data.length &gt; 0) {
          inputBuffer.add(data);
      }
      return arrSize &lt; inputBuffer.size();
  }
  </code></pre>
  
  <p>I've read documentation, I know how this method works by default. But I need somehow to pass <code>ArrayList</code> element to input parameter <code>byte[] b</code>.</p>
  
  <p>I've been coding in java for few years and yet I've never put attention to how this method is actually implemented. How can I pass data to an incoming parameter and return the number of bytes from my ArrayList's element written?</p>
  
  <p>I have to use custom Socket specifically for BLE w/ Input and Output stream due to my architecture, where I use WiFi socket, BT socket. </p>
  
  <p>Please uncover this mystery for me.</p>