示例#1
0
        public SolrInputDocument ReadSolrInputDocument(FastInputStream dis)
        {
            int               sz       = ReadVInt(dis);
            float?            docBoost = (float?)ReadVal(dis);
            SolrInputDocument sdoc     = new SolrInputDocument();

            sdoc.Boost = docBoost;
            for (int i = 0; i < sz; i++)
            {
                float  boost = 1.0f;
                String fieldName;
                Object boostOrFieldName = ReadVal(dis);
                if (boostOrFieldName is float)
                {
                    boost     = (float)boostOrFieldName;
                    fieldName = (String)ReadVal(dis);
                }
                else
                {
                    fieldName = (String)boostOrFieldName;
                }
                Object fieldVal = ReadVal(dis);
                sdoc[fieldName] = new SolrInputField(fieldName, fieldVal, boost);
            }
            return(sdoc);
        }
示例#2
0
        public long ReadSmallLong(FastInputStream dis)
        {
            long v = tagByte & 0x0F;

            if ((tagByte & 0x10) != 0)
            {
                v = (ReadVLong(dis) << 4) | v;
            }
            return(v);
        }
示例#3
0
        public int ReadSmallInt(FastInputStream dis)
        {
            int v = tagByte & 0x0F;

            if ((tagByte & 0x10) != 0)
            {
                v = (ReadVInt(dis) << 4) | v;
            }
            return(v);
        }
示例#4
0
        public int ReadSize(FastInputStream stream)
        {
            int sz = tagByte & 0x1f;

            if (sz == 0x1f)
            {
                sz += ReadVInt(stream);
            }
            return(sz);
        }
示例#5
0
        public IList ReadArray(FastInputStream dis)
        {
            int       sz = ReadSize(dis);
            ArrayList l  = new ArrayList(sz);

            for (int i = 0; i < sz; i++)
            {
                l.Add(ReadVal(dis));
            }
            return(l);
        }
示例#6
0
 /**
  * The counterpart for {@link #writeVInt(int, FastOutputStream)}
  *
  * @ If there is a low-level I/O error.
  */
 public static int ReadVInt(FastInputStream stream)
 {
     byte b = (byte)stream.ReadByte();
     int i = b & 0x7F;
     for (int shift = 7; (b & 0x80) != 0; shift += 7)
     {
         b = (byte)stream.ReadByte();
         i |= (b & 0x7F) << shift;
     }
     return i;
 }
示例#7
0
        /**
         * The counterpart for {@link #writeVInt(int, FastOutputStream)}
         *
         * @ If there is a low-level I/O error.
         */
        public static int ReadVInt(FastInputStream stream)
        {
            byte b = (byte)stream.ReadByte();
            int  i = b & 0x7F;

            for (int shift = 7; (b & 0x80) != 0; shift += 7)
            {
                b  = (byte)stream.ReadByte();
                i |= (b & 0x7F) << shift;
            }
            return(i);
        }
示例#8
0
        public static long ReadVLong(FastInputStream stream)
        {
            byte b = (byte)stream.ReadByte();
            long i = b & 0x7F;

            for (int shift = 7; (b & 0x80) != 0; shift += 7)
            {
                b  = (byte)stream.ReadByte();
                i |= (long)(b & 0x7F) << shift;
            }
            return(i);
        }
示例#9
0
        public Object Unmarshal(Stream inputStream)
        {
            FastInputStream dis = new FastInputStream(inputStream);

            version = (byte)dis.ReadByte();
            if (version != VERSION)
            {
                throw new ApplicationException("Invalid version (expected " + VERSION +
                                               ", but " + version + ") or the data in not in 'javabin' format");
            }
            return(ReadVal(dis));
        }
示例#10
0
        public IDictionary <Object, Object> ReadMap(FastInputStream dis)
        {
            int sz = ReadVInt(dis);
            IDictionary <Object, Object> m = new LinkedHashMap <Object, Object>();

            for (int i = 0; i < sz; i++)
            {
                Object key = ReadVal(dis);
                Object val = ReadVal(dis);
                m[key] = val;
            }
            return(m);
        }
示例#11
0
        public SolrDocument ReadSolrDocument(FastInputStream dis)
        {
            NamedList    nl  = (NamedList)ReadVal(dis);
            SolrDocument doc = new SolrDocument();

            for (int i = 0; i < nl.Count; i++)
            {
                String name = nl.GetName(i);
                Object val  = nl.GetVal(i);
                doc.SetField(name, val);
            }
            return(doc);
        }
示例#12
0
        public SimpleOrderedMap ReadOrderedMap(FastInputStream dis)
        {
            int sz = ReadSize(dis);
            SimpleOrderedMap nl = new SimpleOrderedMap();

            for (int i = 0; i < sz; i++)
            {
                String name = (String)ReadVal(dis);
                Object val  = ReadVal(dis);
                nl.Add(name, val);
            }
            return(nl);
        }
示例#13
0
        public NamedList ReadNamedList(FastInputStream dis)
        {
            int       sz = ReadSize(dis);
            NamedList nl = new NamedList();

            for (int i = 0; i < sz; i++)
            {
                String name = (String)ReadVal(dis);
                Object val  = ReadVal(dis);
                nl.Add(name, val);
            }
            return(nl);
        }
示例#14
0
        public String ReadStr(FastInputStream dis)
        {
            int sz = ReadSize(dis);

            if (chars == null || chars.Length < sz)
            {
                chars = new char[sz];
            }
            if (bytes == null || bytes.Length < sz)
            {
                bytes = new byte[sz];
            }
            dis.ReadFully(bytes, 0, sz);

            int outUpto = 0;

            for (int i = 0; i < sz;)
            {
                int b = bytes[i++] & 0xff;
                int ch;
                if (b < 0xc0)
                {
                    ch = b;
                }
                else if (b < 0xe0)
                {
                    ch = ((b & 0x1f) << 6) + (bytes[i++] & 0x3f);
                }
                else if (b < 0xf0)
                {
                    ch = ((b & 0xf) << 12) + ((bytes[i++] & 0x3f) << 6) + (bytes[i++] & 0x3f);
                }
                else
                {
                    ch = ((b & 0x7) << 18) + ((bytes[i++] & 0x3f) << 12) + ((bytes[i++] & 0x3f) << 6) + (bytes[i++] & 0x3f);
                }
                if (ch <= 0xFFFF)
                {
                    // target is a character <= 0xFFFF
                    chars[outUpto++] = (char)ch;
                }
                else
                {
                    // target is a character in range 0xFFFF - 0x10FFFF
                    int chHalf = ch - 0x10000;
                    chars[outUpto++] = (char)((chHalf >> 0xA) + 0xD800);
                    chars[outUpto++] = (char)((chHalf & 0x3FF) + 0xDC00);
                }
            }
            return(new String(chars, 0, outUpto));
        }
示例#15
0
        public IList ReadIterator(FastInputStream fis)
        {
            ArrayList l = new ArrayList();

            while (true)
            {
                Object o = ReadVal(fis);
                if (o == END_OBJ)
                {
                    break;
                }
                l.Add(o);
            }
            return(l);
        }
示例#16
0
        public SolrDocumentList ReadSolrDocumentList(FastInputStream dis)
        {
            SolrDocumentList solrDocs = new SolrDocumentList();
            IList            list     = (IList)ReadVal(dis);

            solrDocs.NumFound = (long)list[0];
            solrDocs.Start    = (long)list[1];
            solrDocs.MaxScore = (float?)list[2];

            ArrayList l = (ArrayList)ReadVal(dis);

            foreach (SolrDocument doc in l)
            {
                solrDocs.Add(doc);
            }
            return(solrDocs);
        }
示例#17
0
        public String ReadExternString(FastInputStream fis)
        {
            int idx = ReadSize(fis);

            if (idx != 0)
            {// idx != 0 is the index of the extern string
                return(stringsList[idx - 1]);
            }
            else
            {// idx == 0 means it has a string value
                String s = (String)ReadVal(fis);
                if (stringsList == null)
                {
                    stringsList = new List <String>();
                }
                stringsList.Add(s);
                return(s);
            }
        }
示例#18
0
 public long ReadSmallLong(FastInputStream dis)
 {
     long v = tagByte & 0x0F;
     if ((tagByte & 0x10) != 0)
         v = (ReadVLong(dis) << 4) | v;
     return v;
 }
示例#19
0
 public int ReadSmallInt(FastInputStream dis)
 {
     int v = tagByte & 0x0F;
     if ((tagByte & 0x10) != 0)
         v = (ReadVInt(dis) << 4) | v;
     return v;
 }
示例#20
0
 public int ReadSize(FastInputStream stream)
 {
     int sz = tagByte & 0x1f;
     if (sz == 0x1f) sz += ReadVInt(stream);
     return sz;
 }
示例#21
0
 public SimpleOrderedMap ReadOrderedMap(FastInputStream dis)
 {
     int sz = ReadSize(dis);
     SimpleOrderedMap nl = new SimpleOrderedMap();
     for (int i = 0; i < sz; i++)
     {
         String name = (String)ReadVal(dis);
         Object val = ReadVal(dis);
         nl.Add(name, val);
     }
     return nl;
 }
示例#22
0
        public Object ReadVal(FastInputStream dis)
        {
            tagByte = (byte)dis.ReadByte();

            // if ((tagByte & 0xe0) == 0) {
            // if top 3 bits are clear, this is a normal tag

            // OK, try type + size in single byte
            switch (tagByte >> 5)
            {
                case STR >> 5:
                    return ReadStr(dis);
                case SINT >> 5:
                    return ReadSmallInt(dis);
                case SLONG >> 5:
                    return ReadSmallLong(dis);
                case ARR >> 5:
                    return ReadArray(dis);
                case ORDERED_MAP >> 5:
                    return ReadOrderedMap(dis);
                case NAMED_LST >> 5:
                    return ReadNamedList(dis);
                case EXTERN_STRING >> 5:
                    return ReadExternString(dis);
            }

            switch (tagByte)
            {
                case NULL:
                    return null;
                case DATE:
                    try
                    {
                        return dis.ReadLong().ConvertToDateTime();
                    }
                    catch
                    {
                        return null;
                    }
                case INT:
                    return dis.ReadInt();
                case BOOL_TRUE:
                    return true;
                case BOOL_FALSE:
                    return false;
                case FLOAT:
                    return dis.ReadFloat();
                case DOUBLE:
                    return dis.ReadDouble();
                case LONG:
                    return dis.ReadLong();
                case BYTE:
                    return dis.ReadByte();
                case SHORT:
                    return dis.ReadShort();
                case MAP:
                    return ReadMap(dis);
                case SOLRDOC:
                    return ReadSolrDocument(dis);
                case SOLRDOCLST:
                    return ReadSolrDocumentList(dis);
                case BYTEARR:
                    return ReadByteArray(dis);
                case ITERATOR:
                    return ReadIterator(dis);
                case END:
                    return END_OBJ;
                case SOLRINPUTDOC:
                    return ReadSolrInputDocument(dis);
            }

            throw new ApplicationException("Unknown type " + tagByte);
        }
示例#23
0
 public SolrInputDocument ReadSolrInputDocument(FastInputStream dis)
 {
     int sz = ReadVInt(dis);
     float? docBoost = (float?)ReadVal(dis);
     SolrInputDocument sdoc = new SolrInputDocument();
     sdoc.Boost = docBoost;
     for (int i = 0; i < sz; i++)
     {
         float boost = 1.0f;
         String fieldName;
         Object boostOrFieldName = ReadVal(dis);
         if (boostOrFieldName is float)
         {
             boost = (float)boostOrFieldName;
             fieldName = (String)ReadVal(dis);
         }
         else
         {
             fieldName = (String)boostOrFieldName;
         }
         Object fieldVal = ReadVal(dis);
         sdoc[fieldName] = new SolrInputField(fieldName, fieldVal, boost);
     }
     return sdoc;
 }
示例#24
0
 public String ReadExternString(FastInputStream fis)
 {
     int idx = ReadSize(fis);
     if (idx != 0)
     {// idx != 0 is the index of the extern string
         return stringsList[idx - 1];
     }
     else
     {// idx == 0 means it has a string value
         String s = (String)ReadVal(fis);
         if (stringsList == null) stringsList = new List<String>();
         stringsList.Add(s);
         return s;
     }
 }
示例#25
0
 public byte[] ReadByteArray(FastInputStream dis)
 {
     byte[] arr = new byte[ReadVInt(dis)];
     dis.ReadFully(arr);
     return arr;
 }
示例#26
0
        public Object ReadVal(FastInputStream dis)
        {
            tagByte = (byte)dis.ReadByte();

            // if ((tagByte & 0xe0) == 0) {
            // if top 3 bits are clear, this is a normal tag

            // OK, try type + size in single byte
            switch (tagByte >> 5)
            {
            case STR >> 5:
                return(ReadStr(dis));

            case SINT >> 5:
                return(ReadSmallInt(dis));

            case SLONG >> 5:
                return(ReadSmallLong(dis));

            case ARR >> 5:
                return(ReadArray(dis));

            case ORDERED_MAP >> 5:
                return(ReadOrderedMap(dis));

            case NAMED_LST >> 5:
                return(ReadNamedList(dis));

            case EXTERN_STRING >> 5:
                return(ReadExternString(dis));
            }

            switch (tagByte)
            {
            case NULL:
                return(null);

            case DATE:
                try
                {
                    return(dis.ReadLong().ConvertToDateTime());
                }
                catch
                {
                    return(null);
                }

            case INT:
                return(dis.ReadInt());

            case BOOL_TRUE:
                return(true);

            case BOOL_FALSE:
                return(false);

            case FLOAT:
                return(dis.ReadFloat());

            case DOUBLE:
                return(dis.ReadDouble());

            case LONG:
                return(dis.ReadLong());

            case BYTE:
                return(dis.ReadByte());

            case SHORT:
                return(dis.ReadShort());

            case MAP:
                return(ReadMap(dis));

            case SOLRDOC:
                return(ReadSolrDocument(dis));

            case SOLRDOCLST:
                return(ReadSolrDocumentList(dis));

            case BYTEARR:
                return(ReadByteArray(dis));

            case ITERATOR:
                return(ReadIterator(dis));

            case END:
                return(END_OBJ);

            case SOLRINPUTDOC:
                return(ReadSolrInputDocument(dis));
            }

            throw new ApplicationException("Unknown type " + tagByte);
        }
示例#27
0
 public byte[] ReadByteArray(FastInputStream dis)
 {
     byte[] arr = new byte[ReadVInt(dis)];
     dis.ReadFully(arr);
     return(arr);
 }
示例#28
0
 public SolrDocument ReadSolrDocument(FastInputStream dis)
 {
     NamedList nl = (NamedList)ReadVal(dis);
     SolrDocument doc = new SolrDocument();
     for (int i = 0; i < nl.Count; i++)
     {
         String name = nl.GetName(i);
         Object val = nl.GetVal(i);
         doc.SetField(name, val);
     }
     return doc;
 }
示例#29
0
        public SolrDocumentList ReadSolrDocumentList(FastInputStream dis)
        {
            SolrDocumentList solrDocs = new SolrDocumentList();
            IList list = (IList)ReadVal(dis);
            solrDocs.NumFound = (long)list[0];
            solrDocs.Start = (long)list[1];
            solrDocs.MaxScore = (float?)list[2];

            ArrayList l = (ArrayList)ReadVal(dis);
            foreach (SolrDocument doc in l)
            {
                solrDocs.Add(doc);
            }
            return solrDocs;
        }
示例#30
0
 public IList ReadIterator(FastInputStream fis)
 {
     ArrayList l = new ArrayList();
     while (true)
     {
         Object o = ReadVal(fis);
         if (o == END_OBJ) break;
         l.Add(o);
     }
     return l;
 }
示例#31
0
        public String ReadStr(FastInputStream dis)
        {
            int sz = ReadSize(dis);
            if (chars == null || chars.Length < sz) chars = new char[sz];
            if (bytes == null || bytes.Length < sz) bytes = new byte[sz];
            dis.ReadFully(bytes, 0, sz);

            int outUpto = 0;
            for (int i = 0; i < sz; )
            {
                int b = bytes[i++] & 0xff;
                int ch;
                if (b < 0xc0)
                {
                    ch = b;
                }
                else if (b < 0xe0)
                {
                    ch = ((b & 0x1f) << 6) + (bytes[i++] & 0x3f);
                }
                else if (b < 0xf0)
                {
                    ch = ((b & 0xf) << 12) + ((bytes[i++] & 0x3f) << 6) + (bytes[i++] & 0x3f);
                }
                else
                {
                    ch = ((b & 0x7) << 18) + ((bytes[i++] & 0x3f) << 12) + ((bytes[i++] & 0x3f) << 6) + (bytes[i++] & 0x3f);
                }
                if (ch <= 0xFFFF)
                {
                    // target is a character <= 0xFFFF
                    chars[outUpto++] = (char)ch;
                }
                else
                {
                    // target is a character in range 0xFFFF - 0x10FFFF
                    int chHalf = ch - 0x10000;
                    chars[outUpto++] = (char)((chHalf >> 0xA) + 0xD800);
                    chars[outUpto++] = (char)((chHalf & 0x3FF) + 0xDC00);
                }
            }
            return new String(chars, 0, outUpto);
        }
示例#32
0
        public IDictionary<Object, Object> ReadMap(FastInputStream dis)
        {
            int sz = ReadVInt(dis);
            IDictionary<Object, Object> m = new LinkedHashMap<Object, Object>();
            for (int i = 0; i < sz; i++)
            {
                Object key = ReadVal(dis);
                Object val = ReadVal(dis);
                m[key] = val;

            }
            return m;
        }
示例#33
0
 public Object Unmarshal(Stream inputStream)
 {
     FastInputStream dis = new FastInputStream(inputStream);
     version = (byte)dis.ReadByte();
     if (version != VERSION)
     {
         throw new ApplicationException("Invalid version (expected " + VERSION +
             ", but " + version + ") or the data in not in 'javabin' format");
     }
     return ReadVal(dis);
 }
示例#34
0
 public NamedList ReadNamedList(FastInputStream dis)
 {
     int sz = ReadSize(dis);
     NamedList nl = new NamedList();
     for (int i = 0; i < sz; i++)
     {
         String name = (String)ReadVal(dis);
         Object val = ReadVal(dis);
         nl.Add(name, val);
     }
     return nl;
 }
示例#35
0
 public static long ReadVLong(FastInputStream stream)
 {
     byte b = (byte)stream.ReadByte();
     long i = b & 0x7F;
     for (int shift = 7; (b & 0x80) != 0; shift += 7)
     {
         b = (byte)stream.ReadByte();
         i |= (long)(b & 0x7F) << shift;
     }
     return i;
 }
示例#36
0
 public IList ReadArray(FastInputStream dis)
 {
     int sz = ReadSize(dis);
     ArrayList l = new ArrayList(sz);
     for (int i = 0; i < sz; i++)
     {
         l.Add(ReadVal(dis));
     }
     return l;
 }