title: OutputStream with ByteArrayOutputStream not writing
body: <p>So i'm trying to write out an object to a ByteArray, but for some reason it's not writting anything, which i see by the fact that the return value is 0, and that by the fact that reading it results in an exception.</p>
  
  <pre><code>BAoutput = new ByteArrayOutputStream();  
  Oout = new ObjectOutputStream(BAoutput);  
  Oout.writeObject(receiver);
  </code></pre>
  
  <p>where <code>receiver</code> is an object i get through a parameter.
  and the exceptions are always the same:</p>
  
  <pre><code>java.io.EOFException
    at java.io.ObjectInputStream$BlockDataInputStream.peekByte(Unknown Source)
    at java.io.ObjectInputStream.readObject0(Unknown Source)
    at java.io.ObjectInputStream.readObject(Unknown Source)
  </code></pre>
  
  <p>Any ideas?</p>
  
  <p>most of the code: (there are a couple of definitions above it, nothing interesting really)  </p>
  
  <pre><code>try {
          BAoutput = new ByteArrayOutputStream();
          Oout = new ObjectOutputStream(BAoutput);
          BAinput = new ByteArrayInputStream(BAoutput.toByteArray());
          Oin = new ObjectInputStream(BAinput);
  
          Oout.writeObject(receiver);
          retval = method.invoke(receiver, args);
          for (Method curr: postMethods){
              curr.setAccessible(true);
              if (curr.invoke(receiver).equals(false)){
                  receiver = Oin.readObject();
                  throw new PostconditionFailure();
              }
          }           
      } catch (IOException e) {
          e.printStackTrace();
      } catch (ClassNotFoundException e) {
          e.printStackTrace();
      } finally {
          try {
              Oin.close();
              Oout.close();
              BAinput.close();
              BAoutput.close();
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  </code></pre>