JNIEXPORT jobject JNICALL Java_com_jacob_com_DispatchProxy_MarshalFromStream
  (JNIEnv *env, jobject _this)
{
  IStream *ps = extractStream(env, _this);
  if (!ps) 
  {
    ThrowComFail(env, "Could not get IStream from DispatchProxy", -1);
    return NULL;
  }
  IDispatch *pD;
  HRESULT hr = CoGetInterfaceAndReleaseStream(ps, IID_IDispatch, (void **)&pD);
  // zero out the stream pointer on the object
  // since the stream can only be read once
  jclass argClass = env->GetObjectClass(_this);
  jfieldID ajf = env->GetFieldID( argClass, "m_pStream", "I");
  env->SetIntField(_this, ajf, (unsigned int)0);

  if (!SUCCEEDED(hr))
  {
    ThrowComFail(env, "Could not Marshal Dispatch from IStream", hr);
    return NULL;
  }
  jclass autoClass = env->FindClass("com/jacob/com/Dispatch");
  jmethodID autoCons = env->GetMethodID(autoClass, "<init>", "(I)V");
  // construct a Dispatch object to return
  // I am copying the pointer to java
  if (pD) pD->AddRef();
  jobject newAuto = env->NewObject(autoClass, autoCons, pD);
  return newAuto;
}
JNIEXPORT void JNICALL Java_com_jacob_com_DispatchProxy_release
  (JNIEnv *env, jobject _this)
{
  IStream *ps =  extractStream(env, _this);
  if (ps) {
    ps->Release();
		jclass argClass = env->GetObjectClass(_this);
    jfieldID ajf = env->GetFieldID( argClass, "m_pStream", "I");
    env->SetIntField(_this, ajf, (unsigned int)0);
  }
}
//====================================================
StatusCode InputStreamParser::extractStreams(const StreamSpecs & inputs, StreamSpecs & parsedInputs) {
  m_inCollection = & parsedInputs;
  StatusCode sc = StatusCode::FAILURE;
  MsgStream log(msgSvc(), name());
  for ( std::vector<std::string>::const_iterator itr = inputs.begin(); itr != inputs.end(); ++itr ) {
    sc = extractStream(*itr);
    if (!sc.isSuccess()) {
      log << MSG::ERROR << " Could not access the file(s). " << endmsg;
      ::abort();
    }
  }

  return sc;
}