private async void Forward()
 {
     if (readerEOF == false)
     {
         int cnt = 0;
         try {
             // This throws OOB excpetion at the end....
             // cnt = reader.read(buff, curTextReaderIndex, READER_BUFF_SIZE);
             cnt = await reader.ReadAsync(buff, 0, READER_BUFF_SIZE);
         } catch (ArgumentOutOfRangeException e) {
             // ???
             // Why does this happen? Does it happen for StringReader only???
             //    Does read(,,) ever return -1 in the case of StringReader ???
             System.Diagnostics.Debug.WriteLine("Looks like we have reached the end of the reader.", e);
         }
         if (cnt == -1 || cnt == 0)
         {
             readerEOF = true;
         }
         else
         {
             bool suc = charQueue.AddAll(buff, cnt);
             if (suc)
             {
                 curTextReaderIndex += cnt;
             }
             else
             {
                 // ???
                 throw new DotJsonMiniException("Unexpected internal error occurred. chars were not added to CharQueue: cnt = " + cnt);
             }
         }
     }
 }
Exemplo n.º 2
0
 private void Forward()
 {
     if (readerEOF == false)
     {
         // if (reader.ready()) { // To avoid blocking
         int cnt = 0;
         try {
             // Java: This throws OOB excpetion at the end....
             // cnt = reader.read(buff, curReaderIndex, READER_BUFF_SIZE);
             // ???
             cnt = reader.Read(buff, 0, READER_BUFF_SIZE);
         } catch (System.IndexOutOfRangeException e) {
             // ???
             // Why does this happen? Does it happen for StringReader only???
             //    Does read(,,) ever return -1 in the case of StringReader ???
             //if (log.isLoggable(Level.INFO)) {
             //    // log.log(Level.INFO, "Looks like we have reached the end of the reader.", e);
             //}
         }
         if (cnt == -1 || cnt == 0)
         {
             readerEOF = true;
         }
         else
         {
             bool suc = charQueue.AddAll(buff, cnt);
             if (suc)
             {
                 curReaderIndex += cnt;
             }
             else
             {
                 // ???
                 // Is this because the json file includes a loooooong string???
                 // temporarily change the LookAheadParsing flag and try again???
                 // --->
                 // Unfortunately this does not work because we are already in the middle of parsing string..
                 //    Unless we can rewind the stack in some way, this does not really help...
                 // if(isLookAheadParsing()) {
                 //     DisableLookAheadParsing();
                 //     // log.warning("Unexpected internal error occurred. Characters were not added to CharQueue: cnt = " + cnt + ". Trying again after calling DisableLookAheadParsing().");
                 //     forward();   // We should be careful not to get into the infinite loop....
                 // } else {
                 //     throw new JsonTokenizerException("Unexpected internal error occurred. Characters were not added to CharQueue: cnt = " + cnt, GetTailCharStream());
                 // }
                 throw new UnexpectedEndOfStreamException("Unexpected internal error occurred. Characters were not added to CharQueue: cnt = " + cnt, GetTailCharStream());
             }
         }
         //} else {
         //    // ????
         //    readerEOF = true;
         //    // Why does this happen ????
         //    // if(log.isLoggable(Level.INFO)) // log.log(Level.INFO, "Looks like we have not read all characters because the reader is blocked. We'll likely have a parser error down the line.");
         //    // throw new UnexpectedEndOfStreamException("Read is blocked. Bailing out.");
         //}
     }
 }
Exemplo n.º 3
0
        public void TestCharQueueAddAll()
        {
            var charQueue = new CharQueue(10);

            int size1 = charQueue.Size;

            System.Diagnostics.Debug.WriteLine("size1 = " + size1);

            char[] buff1 = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h' };
            charQueue.AddAll(buff1);
            System.Diagnostics.Debug.WriteLine("charQueue = " + charQueue);

            int size2 = charQueue.Size;

            System.Diagnostics.Debug.WriteLine("size2 = " + size2);
            Assert.AreEqual(size1 + 8, size2);

            char c1 = charQueue.Poll();

            System.Diagnostics.Debug.WriteLine("charQueue = " + charQueue);
            System.Diagnostics.Debug.WriteLine("c1 = " + c1);
            Assert.AreEqual('a', c1);
            char c2 = charQueue.Poll();

            System.Diagnostics.Debug.WriteLine("charQueue = " + charQueue);
            System.Diagnostics.Debug.WriteLine("c2 = " + c2);
            Assert.AreEqual('b', c2);
            char c3 = charQueue.Poll();

            System.Diagnostics.Debug.WriteLine("charQueue = " + charQueue);
            System.Diagnostics.Debug.WriteLine("c3 = " + c3);
            Assert.AreEqual('c', c3);
            char[] cc = charQueue.Poll(3);
            System.Diagnostics.Debug.WriteLine("charQueue = " + charQueue);
            System.Diagnostics.Debug.WriteLine("cc = " + String.Join(",", cc));
            Assert.AreEqual('d', cc[0]);
            Assert.AreEqual('e', cc[1]);
            Assert.AreEqual('f', cc[2]);
            char c4 = charQueue.Peek();

            System.Diagnostics.Debug.WriteLine("charQueue = " + charQueue);
            System.Diagnostics.Debug.WriteLine("c4 = " + c4);
            Assert.AreEqual('g', c4);

            int size3 = charQueue.Size;

            System.Diagnostics.Debug.WriteLine("size3 = " + size3);
            Assert.AreEqual(size2 - 6, size3);

            char[] buff2 = new char[] { 'i', 'j', 'k', 'l' };
            charQueue.AddAll(buff2);
            System.Diagnostics.Debug.WriteLine("charQueue = " + charQueue);

            int size4 = charQueue.Size;

            System.Diagnostics.Debug.WriteLine("size4 = " + size4);
            Assert.AreEqual(size3 + 4, size4);

            charQueue.Add('m');
            charQueue.Add('n');
            charQueue.Add('o');
            System.Diagnostics.Debug.WriteLine("charQueue = " + charQueue);

            bool suc = charQueue.Add('p');

            System.Diagnostics.Debug.WriteLine("charQueue = " + charQueue);
            Assert.AreEqual(false, suc);

            char c7 = charQueue.Poll();

            System.Diagnostics.Debug.WriteLine("charQueue = " + charQueue);
            Assert.AreEqual('g', c7);
            char c8 = charQueue.Poll();

            System.Diagnostics.Debug.WriteLine("charQueue = " + charQueue);
            Assert.AreEqual('h', c8);
            char c9 = charQueue.Poll();

            System.Diagnostics.Debug.WriteLine("charQueue = " + charQueue);
            Assert.AreEqual('i', c9);
            char c10 = charQueue.Poll();

            System.Diagnostics.Debug.WriteLine("charQueue = " + charQueue);
            Assert.AreEqual('j', c10);
            char c11 = charQueue.Peek();

            System.Diagnostics.Debug.WriteLine("charQueue = " + charQueue);
            Assert.AreEqual('k', c11);
            char c12 = charQueue.Poll();

            System.Diagnostics.Debug.WriteLine("charQueue = " + charQueue);
            Assert.AreEqual('k', c12);

            charQueue.Add('p');
            System.Diagnostics.Debug.WriteLine("charQueue = " + charQueue);

            charQueue.Clear();
            System.Diagnostics.Debug.WriteLine("charQueue = " + charQueue);
            int size9 = charQueue.Size;

            System.Diagnostics.Debug.WriteLine("size9 = " + size9);
            Assert.AreEqual(0, size9);

            System.Diagnostics.Debug.WriteLine("charQueue = {0}", charQueue);
        }