STDMETHODIMP CPPToJavaInStream::Seek(Int64 offset, UInt32 seekOrigin, UInt64 *newPosition) { TRACE_OBJECT_CALL("Seek"); TRACE("SEEK(offset=" << offset << ", origin=" << seekOrigin << ")"); JNIEnvInstance jniEnvInstance(_jbindingSession); if (newPosition) { *newPosition = 0; } jlong returnedNewPosition = _iSeekableStream->seek(jniEnvInstance, _javaImplementation, (jlong) offset, (jint) seekOrigin); if (jniEnvInstance.exceptionCheck()) { return S_FALSE; } if (newPosition) { *newPosition = (UInt64) returnedNewPosition; } TRACE("SEEK: New Pos: " << (UInt64)returnedNewPosition) return S_OK; }
STDMETHODIMP CPPToJavaArchiveOpenVolumeCallback::GetProperty(PROPID propID, PROPVARIANT *value) { TRACE_OBJECT_CALL("GetProperty"); TRACE1("GetProperty(%i)", propID) JNIInstance jniInstance(_nativeMethodContext); JNIEnv * env = jniInstance.GetEnv(); if (value) { value->vt = VT_NULL; } jniInstance.PrepareCall(); jobject propIDObject = env->CallStaticObjectMethod(_propIDClass, _propIDGetPropIDByIndexMethodID, (jint) propID); if (jniInstance.IsExceptionOccurs()) { return S_FALSE; } jniInstance.PrepareCall(); jobject result = env->CallObjectMethod(_javaImplementation, _getPropertyMethodID, propIDObject); if (jniInstance.IsExceptionOccurs()) { return S_FALSE; } ObjectToPropVariant(&jniInstance, result, value); return S_OK; }
STDMETHODIMP CPPToJavaArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode) { TRACE_OBJECT_CALL("GetStream"); JNIEnvInstance jniEnvInstance(_jbindingSession); if (outStream) { *outStream = NULL; } jobject askExtractModeObject = jni::ExtractAskMode::getExtractAskModeByIndex(jniEnvInstance, (jint) askExtractMode); if (jniEnvInstance.exceptionCheck()) { return S_FALSE; } // public SequentialOutStream getStream(int index, ExtractAskMode extractAskMode); jobject result = _iArchiveExtractCallback->getStream(jniEnvInstance, _javaImplementation, (jint) index, askExtractModeObject); if (jniEnvInstance.exceptionCheck()) { return S_FALSE; } if (result == NULL) { *outStream = NULL; return S_OK; } CMyComPtr<ISequentialOutStream> outStreamComPtr = new CPPToJavaSequentialOutStream( _jbindingSession, jniEnvInstance, result); *outStream = outStreamComPtr.Detach(); return S_OK; }
STDMETHODIMP CPPToJavaSequentialOutStream::Write(const void *data, UInt32 size, UInt32 *processedSize) { TRACE_OBJECT_CALL("Write"); if (processedSize) { *processedSize = 0; } if (size == 0) { return S_OK; } JNIEnvInstance jniEnvInstance(_jbindingSession); jbyteArray dataArray = jniEnvInstance->NewByteArray(size); jniEnvInstance->SetByteArrayRegion(dataArray, 0, (jsize) size, (const jbyte*) data); // public int write(byte[] data); jint result = _iSequentialOutStream->write(jniEnvInstance, _javaImplementation, dataArray); if (jniEnvInstance.exceptionCheck()) { jniEnvInstance->DeleteLocalRef(dataArray); return S_FALSE; } jniEnvInstance->DeleteLocalRef(dataArray); *processedSize = (UInt32) result; if (result <= 0) { jniEnvInstance.reportError("Implementation of 'int ISequentialOutStream.write(byte[])' " "should write at least one byte. Returned amount of written bytes: %i", result); return S_FALSE; } return S_OK; }
STDMETHODIMP CPPToJavaProgress::SetCompleted(const UInt64 * completeValue) { TRACE_OBJECT_CALL("SetCompleted"); JNIInstance jniInstance(_nativeMethodContext); jniInstance.PrepareCall(); jniInstance.GetEnv()->CallVoidMethod(_javaImplementation, _setCompletedMethodID, (jlong)(*completeValue)); return jniInstance.IsExceptionOccurs() ? S_FALSE : S_OK; }
STDMETHODIMP CPPToJavaProgress::SetTotal(UINT64 total) { TRACE_OBJECT_CALL("SetTotal"); JNIInstance jniInstance(_nativeMethodContext); jniInstance.PrepareCall(); jniInstance.GetEnv()->CallVoidMethod(_javaImplementation, _setTotalMethodID, (jlong)total); return jniInstance.IsExceptionOccurs() ? S_FALSE : S_OK ; }
STDMETHODIMP CPPToJavaArchiveExtractCallback::PrepareOperation(Int32 askExtractMode) { TRACE_OBJECT_CALL("PrepareOperation"); JNIInstance jniInstance(_nativeMethodContext); JNIEnv * env = jniInstance.GetEnv(); jobject askExtractModeObject = env->CallStaticObjectMethod(_extractAskModeClass, _extractAskModeGetExtractAskModeByIndexMethodID, (jint)askExtractMode); // public boolean prepareOperation(ExtractAskMode extractAskMode); jniInstance.PrepareCall(); env->CallVoidMethod(_javaImplementation, _prepareOperationMethodID, askExtractModeObject); return jniInstance.IsExceptionOccurs() ? S_FALSE : S_OK; }
STDMETHODIMP CPPToJavaArchiveExtractCallback::SetOperationResult(Int32 resultEOperationResult) { TRACE_OBJECT_CALL("SetOperationResult"); JNIInstance jniInstance(_nativeMethodContext); JNIEnv * env = jniInstance.GetEnv(); jobject resultEOperationResultObject = env->CallStaticObjectMethod(_extractOperationResultClass, _extractOperationResultGetOperationResultMethodID, (jint)resultEOperationResult); // public void setOperationResult(ExtractOperationResult extractOperationResult); jniInstance.PrepareCall(); env->CallVoidMethod(_javaImplementation, _setOperationResultMethodID, resultEOperationResultObject); return jniInstance.IsExceptionOccurs() ? S_FALSE : S_OK; }
void CPPToJavaArchiveOpenVolumeCallback::Init(JNIEnv * initEnv) { TRACE_OBJECT_CALL("Init") // public Object getProperty(PropID propID); _getPropertyMethodID = GetMethodId(initEnv, "getProperty", "(" PROPID_CLASS_T ")" JAVA_OBJECT_T); // public IInStream getStream(String filename); _getStreamMethodID = GetMethodId(initEnv, "getStream", "(" JAVA_STRING_T ")" INSTREAM_CLASS_T); _propIDClass = GetClass(initEnv, PROPID_CLASS); _propIDGetPropIDByIndexMethodID = GetStaticMethodId(initEnv, _propIDClass, "getPropIDByIndex", "(I)" PROPID_CLASS_T); }
STDMETHODIMP CPPToJavaArchiveExtractCallback::PrepareOperation(Int32 askExtractMode) { TRACE_OBJECT_CALL("PrepareOperation"); JNIEnvInstance jniEnvInstance(_jbindingSession); jobject askExtractModeObject = jni::ExtractAskMode::getExtractAskModeByIndex(jniEnvInstance, (jint) askExtractMode); if (jniEnvInstance.exceptionCheck()) { return S_FALSE; } // public void prepareOperation(ExtractAskMode extractAskMode); _iArchiveExtractCallback->prepareOperation(jniEnvInstance, _javaImplementation, askExtractModeObject); return jniEnvInstance.exceptionCheck() ? S_FALSE : S_OK; }
STDMETHODIMP CPPToJavaArchiveExtractCallback::SetOperationResult(Int32 resultEOperationResult) { TRACE_OBJECT_CALL("SetOperationResult"); JNIEnvInstance jniEnvInstance(_jbindingSession); jobject resultEOperationResultObject = jni::ExtractOperationResult::getOperationResult( jniEnvInstance, (jint) resultEOperationResult); if (jniEnvInstance.exceptionCheck()) { return S_FALSE; } // public void setOperationResult(ExtractOperationResult extractOperationResult); _iArchiveExtractCallback->setOperationResult(jniEnvInstance, _javaImplementation, resultEOperationResultObject); return jniEnvInstance.exceptionCheck() ? S_FALSE : S_OK; }
void CPPToJavaArchiveExtractCallback::Init(JNIEnv * initEnv) { TRACE_OBJECT_CALL("Init") _cryptoGetTextPasswordImpl = NULL; jclass cryptoGetTextPasswordClass = initEnv->FindClass(CRYPTOGETTEXTPASSWORD_CLASS); FATALIF(cryptoGetTextPasswordClass == NULL, "Can't find class " CRYPTOGETTEXTPASSWORD_CLASS); if (initEnv->IsInstanceOf(_javaImplementation, cryptoGetTextPasswordClass)) { CMyComPtr<ICryptoGetTextPassword> cryptoGetTextPasswordComPtr = new CPPToJavaCryptoGetTextPassword(_nativeMethodContext, initEnv, _javaImplementation); _cryptoGetTextPasswordImpl = cryptoGetTextPasswordComPtr.Detach(); } // public SequentialOutStream getStream(int index, ExtractAskMode extractAskMode); _getStreamMethodID = GetMethodId(initEnv, "getStream", "(I" EXTRACTASKMODE_CLASS_T ")" SEQUENTIALOUTSTREAM_CLASS_T); // public void prepareOperation(ExtractAskMode extractAskMode); _prepareOperationMethodID = GetMethodId(initEnv, "prepareOperation", "(" EXTRACTASKMODE_CLASS_T ")V"); // public void setOperationResult(ExtractOperationResult extractOperationResult); _setOperationResultMethodID = GetMethodId(initEnv, "setOperationResult", "(" EXTRACTOPERATIONRESULT_CLASS_T ")V"); _extractOperationResultClass = GetClass(initEnv, EXTRACTOPERATIONRESULT_CLASS); // public static ExtractOperationResult getOperationResult(int index) _extractOperationResultGetOperationResultMethodID = GetStaticMethodId(initEnv, _extractOperationResultClass, "getOperationResult", "(I)" EXTRACTOPERATIONRESULT_CLASS_T); _extractAskModeClass = GetClass(initEnv, EXTRACTASKMODE_CLASS); // public static ExtractAskMode getExtractAskModeByIndex(int index) _extractAskModeGetExtractAskModeByIndexMethodID = GetStaticMethodId(initEnv, _extractAskModeClass, "getExtractAskModeByIndex", "(I)" EXTRACTASKMODE_CLASS_T); }
STDMETHODIMP CPPToJavaSequentialInStream::Read(void *data, UInt32 size, UInt32 *processedSize) { TRACE_OBJECT_CALL("Read"); JNIInstance jniInstance(_nativeMethodContext); JNIEnv * env = jniInstance.GetEnv(); if (processedSize) { *processedSize = 0; } jbyteArray byteArray = env->NewByteArray(size); FATALIF(byteArray == NULL, "Out of local resource of out of memory: byteArray == NULL") // TODO Change to EXCEPTION_IF() // jintArray intArray = env->NewIntArray(1); // FATALIF(intArray == NULL, "Out of local resource of out of memory: intArray == NULL"); jniInstance.PrepareCall(); jint wasRead = env->CallIntMethod(_javaImplementation, _readMethodID, byteArray); if (jniInstance.IsExceptionOccurs()) { env->DeleteLocalRef(byteArray); // env->DeleteLocalRef(intArray); return S_FALSE; } if (processedSize) { *processedSize = (UInt32)wasRead; } jbyte * buffer = env->GetByteArrayElements(byteArray, NULL); memcpy(data, buffer, size); env->ReleaseByteArrayElements(byteArray, buffer, JNI_ABORT); env->DeleteLocalRef(byteArray); // env->DeleteLocalRef(intArray); // env->ReleaseIntArrayElements(intArray, read, JNI_ABORT); return S_OK; }
STDMETHODIMP CPPToJavaArchiveOpenVolumeCallback::GetStream(const wchar_t *name, IInStream **inStream) { TRACE_OBJECT_CALL("GetStream"); JNIInstance jniInstance(_nativeMethodContext); JNIEnv * env = jniInstance.GetEnv(); if (inStream) { *inStream = NULL; } jstring nameString = env->NewString(UnicodeHelper(name), (jsize) wcslen( name)); jniInstance.PrepareCall(); jobject inStreamImpl = env->CallObjectMethod(_javaImplementation, _getStreamMethodID, nameString); if (jniInstance.IsExceptionOccurs()) { return S_FALSE; } if (inStream) { if (inStreamImpl) { CPPToJavaInStream * newInStream = new CPPToJavaInStream( _nativeMethodContext, env, inStreamImpl); lastVolume->AddInStream(newInStream); lastVolume = newInStream; CMyComPtr<IInStream> inStreamComPtr = newInStream; *inStream = inStreamComPtr.Detach(); } else { // jniInstance.ThrowSevenZipException( // "IArchiveOpenVolumeCallback.GetStream() returns stream=null. " // "Use non-zero return value if requested volume doesn't exists"); return S_FALSE; } } return S_OK; }
STDMETHODIMP CPPToJavaArchiveExtractCallback::GetStream(UInt32 index, ISequentialOutStream **outStream, Int32 askExtractMode) { TRACE_OBJECT_CALL("GetStream"); JNIInstance jniInstance(_nativeMethodContext); JNIEnv * env = jniInstance.GetEnv(); if (outStream) { *outStream = NULL; } jniInstance.PrepareCall(); jobject askExtractModeObject = env->CallStaticObjectMethod(_extractAskModeClass, _extractAskModeGetExtractAskModeByIndexMethodID, (jint)askExtractMode); if (jniInstance.IsExceptionOccurs()) { return S_FALSE; } // public SequentialOutStream getStream(int index, ExtractAskMode extractAskMode); jniInstance.PrepareCall(); jobject result = env->CallObjectMethod(_javaImplementation, _getStreamMethodID, (jint)index, askExtractModeObject); if (jniInstance.IsExceptionOccurs()) { return S_FALSE; } if (result == NULL) { *outStream = NULL; EndCPPToJavaCall(); return S_OK; } CMyComPtr<ISequentialOutStream> outStreamComPtr = new CPPToJavaSequentialOutStream(_nativeMethodContext, env, result); *outStream = outStreamComPtr.Detach(); return S_OK; }