code:     private Foo writeAndRead(Foo foo) throws IOException, ClassNotFoundException {
          writeObject(oos, foo);
          ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray());
          inputStream = new ObjectInputStream(bis);
          Foo fooBack = readFooObject(inputStream);
          inputStream.close();
          return fooBack;
      }
  
  