示例#1
0
        protected internal AbstractMatrix(ExtendedDataInput @in)
        {
            byte hasLabels = @in.readByte();

            BasicEntityFactory factory = null;

            DATA_TYPE[] types = Enum.GetValues(typeof(DATA_TYPE)) as DATA_TYPE[];
            if (hasLabels > 0)
            {
                factory = new BasicEntityFactory();
            }
            short flag;
            int   form;
            int   type;

            if ((hasLabels & 1) == 1)
            {
                //contain row labels
                flag = @in.readShort();
                form = flag >> 8;
                type = flag & 0xff;
                if (form != (int)DATA_FORM.DF_VECTOR)
                {
                    throw new IOException("The form of matrix row labels must be vector");
                }
                if (type < 0 || type >= types.Length)
                {
                    throw new IOException("Invalid data type for matrix row labels: " + type);
                }
                rowLabels = (IVector)factory.createEntity(DATA_FORM.DF_VECTOR, types[type], @in);
            }

            if ((hasLabels & 2) == 2)
            {
                //contain columns labels
                flag = @in.readShort();
                form = flag >> 8;
                type = flag & 0xff;
                if (form != (int)DATA_FORM.DF_VECTOR)
                {
                    throw new IOException("The form of matrix columns labels must be vector");
                }
                if (type < 0 || type >= types.Length)
                {
                    throw new IOException("Invalid data type for matrix column labels: " + type);
                }
                columnLabels = (IVector)factory.createEntity(DATA_FORM.DF_VECTOR, types[type], @in);
            }

            flag = @in.readShort();
            type = flag & 0xff;
            if (type < 0 || type >= types.Length)
            {
                throw new IOException("Invalid data type for matrix: " + type);
            }
            _rows    = @in.readInt();
            _columns = @in.readInt();
            readMatrixFromInputStream(_rows, _columns, @in);
        }
示例#2
0
        protected internal BasicAnyVector(ExtendedDataInput @in) : base(DATA_FORM.DF_VECTOR)
        {
            int rows = @in.readInt();
            int cols = @in.readInt();
            int size = rows * cols;

            values = new IEntity[size];

            BasicEntityFactory factory = new BasicEntityFactory();

            for (int i = 0; i < size; ++i)
            {
                short flag     = @in.readShort();
                int   form     = flag >> 8;
                int   type     = flag & 0xff;
                bool  extended = type >= 128;
                if (type >= 128)
                {
                    type -= 128;
                }
                //if (form != 1)
                //assert (form == 1);
                //if (type != 4)
                //assert(type == 4);
                IEntity obj = factory.createEntity((DATA_FORM)form, (DATA_TYPE)type, @in, extended);
                values[i] = obj;
            }
        }
示例#3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public BasicSet(Entity_DATA_TYPE keyType, com.xxdb.io.ExtendedDataInput in) throws java.io.IOException
        public BasicSet(DATA_TYPE keyType, ExtendedDataInput @in)
        {
            this.keyType = keyType;

            BasicEntityFactory factory = new BasicEntityFactory();

            DATA_TYPE[] types = Enum.GetValues(typeof(DATA_TYPE));

            //read key vector
            short flag = @in.readShort();
            int   form = flag >> 8;
            int   type = flag & 0xff;

            if (form != (int)DATA_FORM.DF_VECTOR)
            {
                throw new IOException("The form of set keys must be vector");
            }
            if (type < 0 || type >= types.Length)
            {
                throw new IOException("Invalid key type: " + type);
            }

            Vector keys = (Vector)factory.createEntity(DATA_FORM.DF_VECTOR, types[type], @in);

            int size     = keys.rows();
            int capacity = (int)(size / 0.75);

            set = new HashSet <Scalar>(capacity);
            for (int i = 0; i < size; ++i)
            {
                set.Add(keys.get(i));
            }
        }
        protected internal override void readMatrixFromInputStream(int rows, int columns, ExtendedDataInput @in)
        {
            int size = rows * columns;

            values = new short[size];
            for (int i = 0; i < size; ++i)
            {
                values[i] = @in.readShort();
            }
        }
示例#5
0
 public override void deserialize(int start, int count, ExtendedDataInput @in)
 {
     if (start + count > values.Count)
     {
         values.AddRange(new short[start + count - values.Count]);
     }
     for (int i = 0; i < count; ++i)
     {
         values[start + i] = @in.readShort();
     }
 }
示例#6
0
        protected internal BasicShortVector(DATA_FORM df, ExtendedDataInput @in) : base(df)
        {
            int rows = @in.readInt();
            int cols = @in.readInt();
            int size = rows * cols;

            values = new short[size];
            for (int i = 0; i < size; ++i)
            {
                values[i] = @in.readShort();
            }
        }
示例#7
0
        public object getObject()
        {
            BasicEntityFactory factory = new BasicEntityFactory();

            if (currentIndex >= size)
            {
                return(null);
            }

            short flag     = instream.readShort();
            int   form     = flag >> 8;
            int   type     = flag & 0xff;
            bool  extended = type >= 128;

            if (type >= 128)
            {
                type -= 128;
            }
            currentValue = factory.createEntity((DATA_FORM)form, (DATA_TYPE)type, instream, extended);
            currentIndex++;
            return(currentValue);
        }
示例#8
0
        public BasicChunkMeta(ExtendedDataInput @in)
        {
            @in.readShort();             //skip the length of the data
            path = @in.readString();
            id   = new sbyte[16];
            @in.readFully(id);
            version      = @in.readInt();
            size_Renamed = @in.readInt();
            flag         = @in.readByte();
            sites        = new List <>();
            int copyCount = @in.readByte();

            for (int i = 0; i < copyCount; ++i)
            {
                sites.Add(@in.readString());
            }
        }
示例#9
0
        public BasicTable(ExtendedDataInput @in)
        {
            int rows = @in.readInt();
            int cols = @in.readInt();

            _tableName = @in.readString();

            //read column names
            for (int i = 0; i < cols; ++i)
            {
                string name = @in.readString();
                name2index_[name] = name2index_.Count;
                names_.Add(name);
            }

            BasicEntityFactory factory = new BasicEntityFactory();

            //read columns
            for (int i = 0; i < cols; ++i)
            {
                short flag = @in.readShort();
                int   form = flag >> 8;
                int   type = flag & 0xff;

                DATA_FORM df = (DATA_FORM)form;
                DATA_TYPE dt = (DATA_TYPE)type;
                if (df != DATA_FORM.DF_VECTOR)
                {
                    throw new IOException("Invalid form for column [" + names_[i] + "] for table " + _tableName);
                }
                Console.WriteLine("vector create " + i + ":" + DateTime.Now);
                IVector vector = (IVector)factory.createEntity(df, dt, @in);
                Console.WriteLine("vector end create " + i + ":" + DateTime.Now);
                if (vector.rows() != rows && vector.rows() != 1)
                {
                    throw new IOException("The number of rows for column " + names_[i] + " is not consistent with other columns");
                }
                columns_.Add(vector);
            }
        }
示例#10
0
        public BasicDictionary(DATA_TYPE valueType, ExtendedDataInput @in)
        {
            this.valueType = valueType;

            BasicEntityFactory factory = new BasicEntityFactory();

            DATA_TYPE[] types = Enum.GetValues(typeof(DATA_TYPE)) as DATA_TYPE[];

            //read key vector
            short flag = @in.readShort();
            int   form = flag >> 8;
            int   type = flag & 0xff;

            if (form != (int)DATA_FORM.DF_VECTOR)
            {
                throw new IOException("The form of dictionary keys must be vector");
            }
            if (type < 0 || type >= types.Length)
            {
                throw new IOException("Invalid key type: " + type);
            }
            keyType = types[type];
            IVector keys = (IVector)factory.createEntity(DATA_FORM.DF_VECTOR, types[type], @in);

            //read value vector
            flag = @in.readShort();
            form = flag >> 8;
            type = flag & 0xff;
            if (form != (int)DATA_FORM.DF_VECTOR)
            {
                throw new IOException("The form of dictionary values must be vector");
            }
            if (type < 0 || type >= types.Length)
            {
                throw new IOException("Invalid value type: " + type);
            }

            IVector values = (IVector)factory.createEntity(DATA_FORM.DF_VECTOR, types[type], @in);

            if (keys.rows() != values.rows())
            {
                throw new IOException("The key size doesn't equate to value size.");
            }

            int size     = keys.rows();
            int capacity = (int)(size / 0.75);

            dict = new Dictionary <IScalar, IEntity>(capacity);
            if (values.getDataType() == DATA_TYPE.DT_ANY)
            {
                BasicAnyVector entityValues = (BasicAnyVector)values;
                for (int i = 0; i < size; ++i)
                {
                    dict[keys.get(i)] = entityValues.getEntity(i);
                }
            }
            else
            {
                for (int i = 0; i < size; ++i)
                {
                    dict[keys.get(i)] = values.get(i);
                }
            }
        }
示例#11
0
 public BasicShort(ExtendedDataInput @in)
 {
     value = @in.readShort();
 }
示例#12
0
        public virtual IEntity run(string function, IList <IEntity> arguments)
        {
            lock (threadLock)
            {
                try
                {
                    bool reconnect = false;
                    if (socket == null || !socket.Connected)
                    {
                        if (sessionID.Length == 0)
                        {
                            throw new IOException("Database connection is not established yet.");
                        }
                        else
                        {
                            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                            socket.Connect(hostName, port);
                            @out = new LittleEndianDataOutputStream(new BufferedStream(new NetworkStream(socket)));
                        }
                    }

                    string body = "function\n" + function;
                    body += ("\n" + arguments.Count + "\n");
                    body += remoteLittleEndian ? "1" : "0";

                    ExtendedDataInput @in     = null;
                    string[]          headers = null;
                    try
                    {
                        @out.writeBytes("API " + sessionID + " ");
                        @out.writeBytes(body.Length.ToString());
                        @out.writeByte('\n');
                        @out.writeBytes(body);
                        for (int i = 0; i < arguments.Count; ++i)
                        {
                            arguments[i].write(@out);
                        }
                        @out.flush();

                        @in     = remoteLittleEndian ? (ExtendedDataInput) new LittleEndianDataInputStream(new BufferedStream(new NetworkStream(socket))) : (ExtendedDataInput) new BigEndianDataInputStream(new BufferedStream(new NetworkStream(socket)));
                        headers = @in.readLine().Split(' ');
                    }
                    catch (IOException ex)
                    {
                        if (reconnect)
                        {
                            socket = null;
                            throw ex;
                        }

                        try
                        {
                            tryReconnect();
                            @out = new LittleEndianDataOutputStream(new BufferedStream(new NetworkStream(socket)));
                            @out.writeBytes("API " + sessionID + " ");
                            @out.writeBytes(body.Length.ToString());
                            @out.writeByte('\n');
                            @out.writeBytes(body);
                            for (int i = 0; i < arguments.Count; ++i)
                            {
                                arguments[i].write(@out);
                            }
                            @out.flush();

                            @in       = remoteLittleEndian ? (ExtendedDataInput) new LittleEndianDataInputStream(new BufferedStream(new NetworkStream(socket))) : (ExtendedDataInput) new BigEndianDataInputStream(new BufferedStream(new NetworkStream(socket)));
                            headers   = @in.readLine().Split(' ');
                            reconnect = true;
                        }
                        catch (Exception e)
                        {
                            socket = null;
                            throw e;
                        }
                    }

                    if (headers.Length != 3)
                    {
                        socket = null;
                        throw new IOException("Received invalid header.");
                    }

                    if (reconnect)
                    {
                        sessionID = headers[0];
                        if (this.userId.Length > 0 && this.password.Length > 0)
                        {
                            login();
                        }
                        if (this.initialScript != "")
                        {
                            run(initialScript);
                        }
                    }
                    int numObject = int.Parse(headers[1]);

                    string msg = @in.readLine();
                    if (!msg.Equals("OK"))
                    {
                        throw new IOException(msg);
                    }

                    if (numObject == 0)
                    {
                        return(new data.Void());
                    }

                    try
                    {
                        short flag = @in.readShort();
                        int   form = flag >> 8;
                        int   type = flag & 0xff;

                        if (form < 0 || form > MAX_FORM_VALUE)
                        {
                            throw new IOException("Invalid form value: " + form);
                        }
                        if (type < 0 || type > MAX_TYPE_VALUE)
                        {
                            throw new IOException("Invalid type value: " + type);
                        }

                        DATA_FORM df = (DATA_FORM)Enum.GetValues(typeof(DATA_FORM)).GetValue(form);
                        DATA_TYPE dt = (DATA_TYPE)Enum.GetValues(typeof(DATA_TYPE)).GetValue(type);

                        return(factory.createEntity(df, dt, @in));
                    }
                    catch (IOException ex)
                    {
                        socket = null;
                        throw ex;
                    }
                }
                finally
                {
                }
            }
        }
示例#13
0
        public virtual IEntity run(string script, ProgressListener listener)
        {
            lock (threadLock)
            {
                bool reconnect = false;
                if (socket == null || !socket.Connected)
                {
                    if (sessionID.Length == 0)
                    {
                        throw new IOException("Database connection is not established yet.");
                    }
                    else
                    {
                        socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                        socket.Connect(hostName, port);

                        @out = new LittleEndianDataOutputStream(new BufferedStream(new NetworkStream(socket)));
                    }
                }

                string            body   = "script\n" + script;
                ExtendedDataInput @in    = null;
                string            header = null;
                try
                {
                    @out.writeBytes((listener != null ? "API2 " : "API ") + sessionID + " ");
                    @out.writeBytes(AbstractExtendedDataOutputStream.getUTFlength(body, 0, 0).ToString());
                    @out.writeByte('\n');
                    @out.writeBytes(body);
                    @out.flush();

                    @in = remoteLittleEndian ? (ExtendedDataInput) new LittleEndianDataInputStream(new BufferedStream(new NetworkStream(socket))) : (ExtendedDataInput) new BigEndianDataInputStream(new BufferedStream(new NetworkStream(socket)));

                    header = @in.readLine();
                }
                catch (IOException ex)
                {
                    if (reconnect)
                    {
                        socket = null;
                        throw ex;
                    }

                    try
                    {
                        tryReconnect();
                        @out.writeBytes((listener != null ? "API2 " : "API ") + sessionID + " ");
                        @out.writeBytes(AbstractExtendedDataOutputStream.getUTFlength(body, 0, 0).ToString());
                        @out.writeByte('\n');
                        @out.writeBytes(body);
                        @out.flush();

                        @in       = remoteLittleEndian ? (ExtendedDataInput) new LittleEndianDataInputStream(new BufferedStream(new NetworkStream(socket))) : (ExtendedDataInput) new BigEndianDataInputStream(new BufferedStream(new NetworkStream(socket)));
                        header    = @in.readLine();
                        reconnect = true;
                    }
                    catch (Exception e)
                    {
                        socket = null;
                        throw e;
                    }
                }
                string msg;

                while (header.Equals("MSG"))
                {
                    //read intermediate message to indicate the progress
                    msg = @in.readString();
                    if (listener != null)
                    {
                        listener.progress(msg);
                    }
                    header = @in.readLine();
                }

                string[] headers = header.Split(' ');
                if (headers.Length != 3)
                {
                    socket = null;
                    throw new IOException("Received invalid header: " + header);
                }

                if (reconnect)
                {
                    sessionID = headers[0];
                    if (this.userId.Length > 0 && this.password.Length > 0)
                    {
                        login();
                    }
                    if (this.initialScript != "")
                    {
                        run(initialScript);
                    }
                }
                int numObject = int.Parse(headers[1]);

                msg = @in.readLine();
                if (!msg.Equals("OK"))
                {
                    throw new IOException(msg);
                }

                if (numObject == 0)
                {
                    return(new data.Void());
                }
                try
                {
                    short flag = @in.readShort();
                    int   form = flag >> 8;
                    int   type = flag & 0xff;

                    if (form < 0 || form > MAX_FORM_VALUE)
                    {
                        throw new IOException("Invalid form value: " + form);
                    }
                    if (type < 0 || type > MAX_TYPE_VALUE)
                    {
                        throw new IOException("Invalid type value: " + type);
                    }

                    DATA_FORM df = (DATA_FORM)Enum.GetValues(typeof(DATA_FORM)).GetValue(form);
                    DATA_TYPE dt = (DATA_TYPE)Enum.GetValues(typeof(DATA_TYPE)).GetValue(type);

                    return(factory.createEntity(df, dt, @in));
                }
                catch (IOException ex)
                {
                    socket = null;
                    throw ex;
                }
            }
        }
示例#14
0
        public BasicTable(ExtendedDataInput @in)
        {
            int rows = @in.readInt();
            int cols = @in.readInt();

            _tableName = @in.readString();

            //read column names
            for (int i = 0; i < cols; ++i)
            {
                string name = @in.readString();
                name2index_[name] = name2index_.Count;
                names_.Add(name);
            }

            BasicEntityFactory   factory      = new BasicEntityFactory();
            VectorDecompressor   decompressor = null;
            SymbolBaseCollection collection   = null;

            //read columns
            for (int i = 0; i < cols; ++i)
            {
                short flag     = @in.readShort();
                int   form     = flag >> 8;
                int   type     = flag & 0xff;
                bool  extended = type >= 128;
                if (type >= 128)
                {
                    type -= 128;
                }

                DATA_FORM df = (DATA_FORM)form;
                DATA_TYPE dt = (DATA_TYPE)type;
                if (df != DATA_FORM.DF_VECTOR)
                {
                    throw new IOException("Invalid form for column [" + names_[i] + "] for table " + _tableName);
                }
                IVector vector;
                if (dt == DATA_TYPE.DT_SYMBOL && extended)
                {
                    if (collection == null)
                    {
                        collection = new SymbolBaseCollection();
                    }
                    vector = new BasicSymbolVector(df, @in, collection);
                }
                else if (dt == DATA_TYPE.DT_COMPRESS)
                {
                    if (decompressor == null)
                    {
                        decompressor = new VectorDecompressor();
                    }
                    vector = decompressor.Decompress(factory, @in, false, true);
                }
                else
                {
                    vector = (IVector)factory.createEntity(df, dt, @in, extended);
                }
                if (vector.rows() != rows && vector.rows() != 1)
                {
                    int tmp = vector.rows();
                    throw new IOException("The number of rows for column " + names_[i] + " is not consistent with other columns");
                }
                columns_.Add(vector);
            }
        }
示例#15
0
        public BasicArrayVector(DATA_TYPE type, ExtendedDataInput @in) : base(DATA_FORM.DF_VECTOR)
        {
            this.type = type;
            int rows = @in.readInt();
            int cols = @in.readInt();

            rowIndices = new List <int>(new int[rows]);
            DATA_TYPE valueType = type - 64;

            valueVec             = (AbstractVector)BasicEntityFactory.instance().createVectorWithDefaultValue(valueType, cols);
            this.baseUnitLength_ = valueVec.getUnitLength();

            int rowsRead        = 0;
            int rowsReadInBlock = 0;
            int prevIndex       = 0;
            int totalBytes      = 0;

            while (rowsRead < rows)
            {
                //read block header
                int blockRows  = @in.readShort();
                int countBytes = @in.readChar();
                @in.skipBytes(1);

                //read array of count
                totalBytes      = blockRows * countBytes;
                rowsReadInBlock = 0;
                int offect = 0;
                while (offect < totalBytes)
                {
                    int len = Math.Min(BUF_SIZE, totalBytes - offect);
                    @in.readFully(buf, 0, len);
                    int curRows = len / countBytes;
                    if (countBytes == 1)
                    {
                        for (int i = 0; i < curRows; i++)
                        {
                            int curRowCells = buf[i];
                            rowIndices[rowsRead + rowsReadInBlock + i] = prevIndex + curRowCells;
                            prevIndex += curRowCells;
                        }
                    }
                    else if (countBytes == 2)
                    {
                        for (int i = 0; i < curRows; ++i)
                        {
                            int curRowCells = BitConverter.ToInt16(buf, i * 2);
                            rowIndices[rowsRead + rowsReadInBlock + i] = prevIndex + curRowCells;
                            prevIndex += curRowCells;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < curRows; ++i)
                        {
                            int curRowCells = BitConverter.ToInt32(buf, i * 4);
                            rowIndices[rowsRead + rowsReadInBlock + i] = prevIndex + curRowCells;
                            prevIndex += curRowCells;
                        }
                    }
                    rowsReadInBlock += curRows;
                    offect          += len;
                }

                //read array of values
                int rowStart   = rowsRead == 0 ? 0 : rowIndices[rowsRead - 1];
                int valueCount = rowIndices[rowsRead + rowsReadInBlock - 1] - rowStart;
                valueVec.deserialize(rowStart, valueCount, @in);

                rowsRead += rowsReadInBlock;
            }
        }