title: Clone InputStream
body: <p>I'm trying to read data from an InputStream, which could either be a FileInputStream or an ObjectInputStream. In order to achieve this I'wanted to clone the stream and try to read the Object and  in case of an exception convert the stream to a String using apache commons io.</p>
  
  <pre><code>    PipedInputStream in = new PipedInputStream();
      TeeInputStream tee = new TeeInputStream(stream, new PipedOutputStream(in));
  
      Object body;
      try {
          ObjectInput ois = new ObjectInputStream(tee);
          body = ois.readObject();
      } catch (Exception e) {
          try {
              body = IOUtils.toString(in, Charset.forName("UTF-8"));
          } catch (Exception e2) {
              throw new MarshallerException("Could not convert inputStream");
          }
      }
  </code></pre>
  
  <p>Unfortunately this does not work as the program waits for incoming data when trying to convert the stream <code>in</code> to a String.</p>