示例#1
0
        public TR InObjectStreamOutObjectStream <TR>(int type, Action <IBinaryStream> writeAction,
                                                     Func <IBinaryStream, IPlatformTargetInternal, TR> readAction, IPlatformTargetInternal arg)
        {
            PlatformMemoryStream outStream = null;
            long outPtr = 0;

            PlatformMemoryStream inStream = null;
            long inPtr = 0;

            try
            {
                if (writeAction != null)
                {
                    outStream = IgniteManager.Memory.Allocate().GetStream();
                    writeAction(outStream);
                    outPtr = outStream.SynchronizeOutput();
                }

                if (readAction != null)
                {
                    inStream = IgniteManager.Memory.Allocate().GetStream();
                    inPtr    = inStream.MemoryPointer;
                }

                var res = UU.TargetInObjectStreamOutObjectStream(_target, type,
                                                                 ((PlatformJniTarget)arg).Target, outPtr, inPtr);

                if (readAction == null)
                {
                    return(default(TR));
                }

                inStream.SynchronizeInput();

                var target = res == null ? null : new PlatformJniTarget(res, _marsh);

                return(readAction(inStream, target));
            }
            catch (JavaException jex)
            {
                throw ConvertException(jex);
            }
            finally
            {
                try
                {
                    if (inStream != null)
                    {
                        inStream.Dispose();
                    }
                }
                finally
                {
                    if (outStream != null)
                    {
                        outStream.Dispose();
                    }
                }
            }
        }
示例#2
0
        /** <inheritdoc /> */
        public T InObjectStreamOutObjectStream <T>(int type, IPlatformTarget arg,
                                                   Action <IBinaryRawWriter> writeAction, Func <IBinaryRawReader, IPlatformTarget, T> readAction)
        {
            PlatformMemoryStream outStream = null;
            long outPtr = 0;

            PlatformMemoryStream inStream = null;
            long inPtr = 0;

            try
            {
                if (writeAction != null)
                {
                    outStream = IgniteManager.Memory.Allocate().GetStream();
                    var writer = _marsh.StartMarshal(outStream);
                    writeAction(writer);
                    FinishMarshal(writer);
                    outPtr = outStream.SynchronizeOutput();
                }

                if (readAction != null)
                {
                    inStream = IgniteManager.Memory.Allocate().GetStream();
                    inPtr    = inStream.MemoryPointer;
                }

                var res = UU.TargetInObjectStreamOutObjectStream(_target, type, GetTargetPtr(arg), outPtr, inPtr);

                if (readAction == null)
                {
                    return(default(T));
                }

                inStream.SynchronizeInput();

                return(readAction(_marsh.StartUnmarshal(inStream), GetPlatformTarget(res)));
            }
            catch (JavaException jex)
            {
                throw ConvertException(jex);
            }
            finally
            {
                try
                {
                    if (inStream != null)
                    {
                        inStream.Dispose();
                    }
                }
                finally
                {
                    if (outStream != null)
                    {
                        outStream.Dispose();
                    }
                }
            }
        }