Mark() публичный Метод

Marks the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point.
public Mark ( int readAheadLimit ) : void
readAheadLimit int Limit on the number of characters that may be read while still preserving the mark. An attempt /// to reset the stream after reading characters up to this limit or beyond may fail. A limit value larger than the size of the /// input buffer will cause a new buffer to be allocated whose size is no smaller than limit. Therefore large values should be /// used with care.
Результат void
        /// <summary>
        /// Default constructor that takes a <seealso cref="TextReader"/>. </summary>
        public MappingCharFilter(NormalizeCharMap normMap, TextReader @in) : base(@in)
        {
            //LUCENENET support to reset the reader.
            _input = GetBufferedReader(@in);
            _input.Mark(BufferedCharFilter.defaultCharBufferSize);
            buffer.Reset(_input);
            //buffer.Reset(@in);

            map = normMap.map;
            cachedRootArcs = normMap.cachedRootArcs;

            if (map != null)
            {
                fstReader = map.BytesReader;
            }
            else
            {
                fstReader = null;
            }
        }
Пример #2
0
        public void Test_Reset_IOException()
        {
            int[]
            expected = new int[] { '1', '2', '3', '4', '5', '6', '7', '8',
                                   '9', '0', -1 };
            br = new BufferedCharFilter(new StringReader("1234567890"), 9);
            br.Mark(9);
            for (int i = 0; i < 11; i++)
            {
                assertEquals(expected[i], br.Read());
            }
            try
            {
                br.Reset();
                fail("should throw IOException");
            }
#pragma warning disable 168
            catch (IOException e)
#pragma warning restore 168
            {
                // Expected
            }
            for (int i = 0; i < 11; i++)
            {
                assertEquals(-1, br.Read());
            }

            br = new BufferedCharFilter(new StringReader("1234567890"));
            br.Mark(10);
            for (int i = 0; i < 10; i++)
            {
                assertEquals(expected[i], br.Read());
            }
            br.Reset();
            for (int i = 0; i < 11; i++)
            {
                assertEquals(expected[i], br.Read());
            }
        }
Пример #3
0
        public void Test_MarkI()
        {
            // Test for method void java.io.BufferedReader.mark(int)
            char[] buf = null;
            br = new BufferedCharFilter(new StringReader(testString));
            br.Skip(500);
            br.Mark(1000);
            br.Skip(250);
            br.Reset();
            buf = new char[testString.Length];
            br.Read(buf, 0, 500);

            assertTrue("Failed to set mark properly", testString.Substring(500,
                                                                           1000 - 500).Equals(new string(buf, 0, 500), StringComparison.Ordinal));

            try
            {
                br = new BufferedCharFilter(new StringReader(testString), 800);
                br.Skip(500);
                br.Mark(250);
                br.Read(buf, 0, 1000);
                br.Reset();

                fail("Failed to invalidate mark properly");
            }
#pragma warning disable 168
            catch (IOException x)
#pragma warning restore 168
            {
                // Expected
            }

            char[] chars = new char[256];
            for (int i = 0; i < 256; i++)
            {
                chars[i] = (char)i;
            }
            BufferedCharFilter @in = new BufferedCharFilter(new StringReader(new String(
                                                                                 chars)), 12);

            @in.Skip(6);
            @in.Mark(14);
            @in.Read(new char[14], 0, 14);
            @in.Reset();

            assertTrue("Wrong chars", @in.Read() == (char)6 &&
                       @in.Read() == (char)7);

            @in = new BufferedCharFilter(new StringReader(new String(chars)), 12);
            @in.Skip(6);
            @in.Mark(8);
            @in.Skip(7);
            @in.Reset();

            assertTrue("Wrong chars 2", @in.Read() == (char)6 &&
                       @in.Read() == (char)7);

            BufferedCharFilter br2 = new BufferedCharFilter(new StringReader("01234"), 2);
            br2.Mark(3);
            char[] carray = new char[3];
            int    result = br2.read(carray);
            assertEquals(3, result);
            assertEquals("Assert 0:", '0', carray[0]);
            assertEquals("Assert 1:", '1', carray[1]);
            assertEquals("Assert 2:", '2', carray[2]);
            assertEquals("Assert 3:", '3', br2.Read());

            br2 = new BufferedCharFilter(new StringReader("01234"), 2);
            br2.Mark(3);
            carray = new char[4];
            result = br2.read(carray);
            assertEquals("Assert 4:", 4, result);
            assertEquals("Assert 5:", '0', carray[0]);
            assertEquals("Assert 6:", '1', carray[1]);
            assertEquals("Assert 7:", '2', carray[2]);
            assertEquals("Assert 8:", '3', carray[3]);
            assertEquals("Assert 9:", '4', br2.Read());
            assertEquals("Assert 10:", -1, br2.Read());

            BufferedCharFilter reader = new BufferedCharFilter(new StringReader("01234"));
            reader.Mark(int.MaxValue);
            reader.Read();
            reader.Dispose();
        }