示例#1
0
        public static string Uncompress(string data)
        {
            MemoryStream    ss = new MemoryStream(Decode(data));
            GZipInputStream zs = new GZipInputStream(ss);

            MemoryStream ms = new MemoryStream();

            byte[] buf  = new byte[1024];
            int    size = 0;

            while ((size = zs.Read(buf, 0, buf.Length)) > 0)
            {
                ms.Write(buf, 0, size);
            }
            return(StrUtil.FromByteArray(ms.ToArray()));
        }
示例#2
0
        public static string TestZip(string data)
        {
            FileStream       fs  = new FileStream("D:\\test.zip", FileMode.Create);
            GZipOutputStream zos = new GZipOutputStream(fs);

            byte[] buf = StrUtil.ToByteArray(data);

            zos.Write(buf, 0, buf.Length);
            zos.Flush();
            fs.Flush();

            //FileStream fs2 = new FileStream("D:\\test2.zip", FileMode.Create);
            //StreamUtils.Copy(fs,fs2,new byte[1024]);
            //fs2.Flush();
            //fs2.Close();

            MemoryStream s1 = new MemoryStream();

            //StreamUtils.Copy(fs, s1, new byte[1024]);
            fs.CopyTo(s1);
            s1.Seek(0, SeekOrigin.Begin);

            zos.Close();
            fs.Close();

            //fs = new FileStream("D:\\test.zip", FileMode.Open);

            //MemoryStream s1 = new MemoryStream();
            //StreamUtils.Copy(fs,s1,new byte[1024]);
            //s1.Seek(0, SeekOrigin.Begin);
            GZipInputStream zis = new GZipInputStream(s1);

            MemoryStream rs = new MemoryStream();

            buf = new byte[1024];
            int size = 0;

            while ((size = zis.Read(buf, 0, buf.Length)) > 0)
            {
                rs.Write(buf, 0, size);
            }

            zis.Close();
            fs.Close();

            return(StrUtil.FromByteArray(rs.ToArray()));
        }
示例#3
0
        private static void FillTableData(DataTable table, string body, int offset, int length)
        {
            string            colFlag = "<F", curColFlag, curRow, curCol, curBody = body;
            DataRowCollection datarows = table.Rows;
            DataRow           row      = null;

            DataColumnCollection columns = table.Columns;
            DataColumn           column;
            int sdpDataType = 0;

            int index, subindex;

            string[] rows = StrUtil.GetParamList(curBody, "<R>");

            table.Clear();
            if (offset < 0)
            {
                offset = 0;
            }
            if (length < 0)
            {
                length = rows.Length - offset;
            }

            int limit = offset + length >= rows.Length ? rows.Length : offset + length;

            for (int i = 0; i < length; i++)
            {
                if (offset + i >= limit)
                {
                    break;
                }

                curRow = rows[offset + i];
                if (curRow.Equals(""))
                {
                    continue;
                }
                curRow = StrUtil.ReplaceStr(curRow, SignConstant.RowReplace, SignConstant.RowSign);

                row = table.NewRow();
                for (int j = 0; j < columns.Count; j++)
                {
                    curColFlag = colFlag + Convert.ToString(j) + ">";
                    index      = curRow.IndexOf(curColFlag);
                    if (index > 0)
                    {
                        curCol   = curRow.Substring(0, index);
                        subindex = curRow.Length - index - curColFlag.Length;
                        curRow   = curRow.Substring(index + curColFlag.Length, subindex);
                        if (!curCol.Equals(""))
                        {
                            curCol      = StrUtil.ReplaceStr(curCol, SignConstant.FieldReplace, SignConstant.FieldSign);
                            column      = columns[j];
                            sdpDataType = TableUtil.IntProperty(column, "SDPDataType");

                            if (sdpDataType == 0)
                            {
                                sdpDataType = DataTypes.ToDataType(column.DataType);
                            }

                            switch (sdpDataType)
                            {
                            case DataTypes.dtBLOB:
                                row[j] = BCUtil.Decode(curCol);
                                break;

                            case DataTypes.dtCLOB:
                                row[j] = StrUtil.FromByteArray(BCUtil.Decode(curCol));
                                break;

                            case DataTypes.dtXMLType:
                                row[j] = StrUtil.FromByteArray(BCUtil.Decode(curCol));
                                break;

                            case DataTypes.dtBoolean:
                                row[j] = curCol.Equals("1") ? true : false;
                                break;

                            //case DataTypes.dtDateTime:
                            //    row[j] = Convert.ToDateTime(curCol);
                            //    break;
                            //case DataTypes.dtDate:
                            //    row[j] = Convert.ToDateTime(curCol);
                            //    break;
                            //case DataTypes.dtTime:
                            //    row[j] = Convert.ToDateTime(curCol);
                            //    break;
                            default:
                                row[j] = curCol;
                                break;
                            }
                        }
                    }
                }
                datarows.Add(row);
            }
            if (length > 0)
            {
                table.AcceptChanges();
            }
        }