title: ObjectInputStream.read(byte[], int, int) missing data?
body: <p>I'm trying to serialize/deserialize a bitmap.  The answers at <a href="https://stackoverflow.com/questions/3628016/android-how-to-save-a-bitmap-buggy-code">android how to save a bitmap - buggy code</a> are very helpful.  However, when I go to read my array:</p>
  
  <pre><code>private void readObject(ObjectInputStream in) throws IOException,
      ClassNotFoundException {
    int rowBytes = in.readInt();
    int height = in.readInt();
    int width = in.readInt();
    int bmSize = rowBytes * height;    // Ends up being 398208
  
    ByteBuffer byteBuffer = ByteBuffer.allocate(bmSize);
    int bytesRead = in.read(byteBuffer.array(), 0, bmSize);
    // Use array to create bitmap here
  }
  </code></pre>
  
  <p>it is reading 1008 bytes, not the 398208 bytes that I wrote.  I've replaced the call with a loop, which works fine:</p>
  
  <pre><code>for (int i = 0; i &lt; bmSize; i++) {
    byteBuffer.array()[i] = in.readByte();
  }
  </code></pre>
  
  <p>What could be going wrong?  No exception is thrown.  The documentation for <a href="http://developer.android.com/reference/java/io/ObjectInputStream.html" rel="nofollow noreferrer">ObjectInputStream.read(byte[], int, int)</a> indicates the only reason it should return early is if it hits the end of the stream, which clearly it isn't because my work-around doesn't throw any exceptions.</p>