code: public static List<SmileEnvelopeEvent> extractEvents(final InputStream in) throws IOException
      {
          final PushbackInputStream pbIn = new PushbackInputStream(in);
  
          final byte firstByte = (byte) pbIn.read();
  
          // EOF?
          if (firstByte == -1) {
              return null;
          }
  
          pbIn.unread(firstByte);
  
          SmileEnvelopeEventDeserializer deser = (firstByte == SMILE_MARKER) ?
                  new SmileEnvelopeEventDeserializer(pbIn, false) :
                  new SmileEnvelopeEventDeserializer(pbIn, true);
          final List<SmileEnvelopeEvent> events = new LinkedList<SmileEnvelopeEvent>();
  
          while (deser.hasNextEvent()) {
              SmileEnvelopeEvent event = deser.getNextEvent();
              if (event == null) {
                  // TODO: this is NOT expected, should warn
                  break;
              }
              events.add(event);
          }
          return events;
      }
docs: Extracts all events in the stream
  Note: Stream must be formatted as an array of (serialized) SmileEnvelopeEvents.
  
  @param in InputStream containing events
  @return A list of SmileEnvelopeEvents
  @throws IOException generic I/O exception