Exemple #1
0
        private static byte[] getInputByCompress(byte[] toByteArray)
        {
            TransferInputStream fis = new TransferInputStream(toByteArray);
            int unCompressedLength  = fis.readInt();
            int compressedLength    = fis.readInt();

            byte[] input = new byte[compressedLength];
            fis.readFully(input, 0, compressedLength);

            byte[]              output       = new byte[unCompressedLength];
            MemoryStream        memoryStream = new MemoryStream(input);
            Inflater            decompresser = new Inflater();
            InflaterInputStream infis        = new InflaterInputStream(memoryStream, decompresser);

            int currentIndex = 0;
            int count        = output.Length;

            while (true)
            {
                int numRead = infis.Read(output, currentIndex, count);
                if (numRead <= 0)
                {
                    break;
                }
                currentIndex += numRead;
                count        -= numRead;
            }

            memoryStream.Close();
            infis.Close();

            return(getInputByNormal(output));
        }
Exemple #2
0
 public TransferObjectWrapper getObjectWrapper(TransferInputStream tins)
 {
     account = new TestAccount();
     account.setId(tins.readInt());
     account.setName(tins.readString());
     account.setAddress(tins.readString());
     return(this);
 }
Exemple #3
0
        private static byte[] getInputByNormal(byte[] toByteArray)
        {
            TransferInputStream fis = new TransferInputStream(toByteArray);
            int blength             = fis.readInt();

            byte[] buf = new byte[blength];
            Array.Copy(toByteArray, TransferUtil.getLengthOfInt(), buf, 0, blength);

            return(buf);
        }
 public TransferObjectWrapper getObjectWrapper(TransferInputStream tins)
 {
     allTypeBean = new AllTypeBean();
     allTypeBean.setAboolean(tins.readBoolean());
     allTypeBean.setAbyte(tins.readByte());
     allTypeBean.setAshort(tins.readShort());
     allTypeBean.setAchar(tins.readChar());
     allTypeBean.setAint(tins.readInt());
     allTypeBean.setAlong(tins.readLong());
     allTypeBean.setAfloat(tins.readFloat());
     allTypeBean.setAdouble(tins.readDouble());
     allTypeBean.setAdate(tins.readDate());
     allTypeBean.setAstring(tins.readString());
     return(this);
 }
Exemple #5
0
        public static int getExpectReceiveLength(byte[] receiveData)
        {
            int expectReceiveLength = 0;
            TransferInputStream fis = new TransferInputStream(receiveData);

            if (TransferUtil.isCompress(fis.readByte()))
            {
                fis.readInt();//uncompresslength
                expectReceiveLength = TransferUtil.getLengthOfByte() + TransferUtil.getLengthOfInt() + TransferUtil.getLengthOfInt() + fis.readInt();
            }
            else
            {
                expectReceiveLength = TransferUtil.getLengthOfByte() + TransferUtil.getLengthOfInt() + fis.readInt();
            }
            return(expectReceiveLength);
        }
        // server call
        public override void setByteData(byte[] buf)
        {
            TransferInputStream tins = new TransferInputStream(buf);

            this.calleeClass  = tins.readString();
            this.calleeMethod = tins.readString();
            this.returnType   = tins.readByte();
            this.compress     = tins.readBoolean();

            while (!tins.isFinished())
            {
                byte type = tins.readByte();
                if (type == DATATYPE_BOOLEAN)
                {
                    putBoolean(tins.readBoolean());
                }
                else if (type == DATATYPE_BYTE)
                {
                    putByte(tins.readByte());
                }
                else if (type == DATATYPE_SHORT)
                {
                    putShort(tins.readShort());
                }
                else if (type == DATATYPE_CHAR)
                {
                    putChar(tins.readChar());
                }
                else if (type == DATATYPE_INT)
                {
                    putInt(tins.readInt());
                }
                else if (type == DATATYPE_LONG)
                {
                    putLong(tins.readLong());
                }
                else if (type == DATATYPE_FLOAT)
                {
                    putFloat(tins.readFloat());
                }
                else if (type == DATATYPE_DOUBLE)
                {
                    putDouble(tins.readDouble());
                }
                else if (type == DATATYPE_DATE)
                {
                    putDate(tins.readDate());
                }
                else if (type == DATATYPE_STRING)
                {
                    putString(tins.readString());
                }
                else if (type == DATATYPE_BYTEARRAY)
                {
                    putByteArray(tins.readByteArray());
                }
                else if (type == DATATYPE_INTARRAY)
                {
                    putIntArray(tins.readIntArray());
                }
                else if (type == DATATYPE_LONGARRAY)
                {
                    putLongArray(tins.readLongArray());
                }
                else if (type == DATATYPE_FLOATARRAY)
                {
                    putFloatArray(tins.readFloatArray());
                }
                else if (type == DATATYPE_DOUBLEARRAY)
                {
                    putDoubleArray(tins.readDoubleArray());
                }
                else if (type == DATATYPE_STRINGARRAY)
                {
                    putStringArray(tins.readStringArray());
                }
                else if (type == DATATYPE_WRAPPER)
                {
                    putWrapper(tins.readWrapper());
                }
            }
        }
        public static Object convertReturnByteArray(byte[] buf)
        {
            Object returnObject = null;

            TransferInputStream tins = new TransferInputStream(buf);
            byte returnType          = tins.readByte();

            if (returnType == DATATYPE_BOOLEAN)
            {
                returnObject = tins.readBoolean();
            }
            else if (returnType == DATATYPE_BYTE)
            {
                returnObject = tins.readByte();
            }
            else if (returnType == DATATYPE_SHORT)
            {
                returnObject = tins.readShort();
            }
            else if (returnType == DATATYPE_CHAR)
            {
                returnObject = tins.readChar();
            }
            else if (returnType == DATATYPE_INT)
            {
                returnObject = tins.readInt();
            }
            else if (returnType == DATATYPE_LONG)
            {
                returnObject = tins.readLong();
            }
            else if (returnType == DATATYPE_FLOAT)
            {
                returnObject = tins.readFloat();
            }
            else if (returnType == DATATYPE_DOUBLE)
            {
                returnObject = tins.readDouble();
            }
            else if (returnType == DATATYPE_DATE)
            {
                returnObject = tins.readDate();
            }
            else if (returnType == DATATYPE_STRING)
            {
                returnObject = tins.readString();
            }
            else if (returnType == DATATYPE_WRAPPER)
            {
                returnObject = (TransferObjectWrapper)tins.readWrapper();
            }
            else if (returnType == DATATYPE_VOID)
            {
                returnObject = null;
            }
            else if (returnType == DATATYPE_BYTEARRAY)
            {
                returnObject = tins.readByteArray();
            }
            else if (returnType == DATATYPE_INTARRAY)
            {
                returnObject = tins.readIntArray();
            }
            else if (returnType == DATATYPE_LONGARRAY)
            {
                returnObject = tins.readLongArray();
            }
            else if (returnType == DATATYPE_FLOATARRAY)
            {
                returnObject = tins.readFloatArray();
            }
            else if (returnType == DATATYPE_DOUBLEARRAY)
            {
                returnObject = tins.readDoubleArray();
            }
            else if (returnType == DATATYPE_STRINGARRAY)
            {
                returnObject = tins.readStringArray();
            }

            return(returnObject);
        }