Ejemplo n.º 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);
        }
Ejemplo n.º 2
0
        public long ReadSmallLong(FastInputStream dis)
        {
            long v = tagByte & 0x0F;

            if ((tagByte & 0x10) != 0)
            {
                v = (ReadVLong(dis) << 4) | v;
            }
            return(v);
        }
Ejemplo n.º 3
0
        public int ReadSmallInt(FastInputStream dis)
        {
            int v = tagByte & 0x0F;

            if ((tagByte & 0x10) != 0)
            {
                v = (ReadVInt(dis) << 4) | v;
            }
            return(v);
        }
Ejemplo n.º 4
0
        public int ReadSize(FastInputStream stream)
        {
            int sz = tagByte & 0x1f;

            if (sz == 0x1f)
            {
                sz += ReadVInt(stream);
            }
            return(sz);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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));
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
            }
        }
Ejemplo n.º 18
0
 public long ReadSmallLong(FastInputStream dis)
 {
     long v = tagByte & 0x0F;
     if ((tagByte & 0x10) != 0)
         v = (ReadVLong(dis) << 4) | v;
     return v;
 }
Ejemplo n.º 19
0
 public int ReadSmallInt(FastInputStream dis)
 {
     int v = tagByte & 0x0F;
     if ((tagByte & 0x10) != 0)
         v = (ReadVInt(dis) << 4) | v;
     return v;
 }
Ejemplo n.º 20
0
 public int ReadSize(FastInputStream stream)
 {
     int sz = tagByte & 0x1f;
     if (sz == 0x1f) sz += ReadVInt(stream);
     return sz;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
     }
 }
Ejemplo n.º 25
0
 public byte[] ReadByteArray(FastInputStream dis)
 {
     byte[] arr = new byte[ReadVInt(dis)];
     dis.ReadFully(arr);
     return arr;
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 27
0
 public byte[] ReadByteArray(FastInputStream dis)
 {
     byte[] arr = new byte[ReadVInt(dis)];
     dis.ReadFully(arr);
     return(arr);
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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;
        }
Ejemplo n.º 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);
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }