Skip() public method

public Skip ( int n ) : long
n int
return long
Exemplo n.º 1
0
        /**
         * @tests java.io.BufferedReader#reset()
         */
        public void Test_Reset()
        {
            // Test for method void java.io.BufferedReader.reset()
            try
            {
                br = new BufferedCharFilter(new StringReader(testString));
                br.Skip(500);
                br.Mark(900);
                br.Skip(500);
                br.Reset();
                char[] buf = new char[testString.Length];
                br.Read(buf, 0, 500);
                assertTrue("Failed to reset properly", testString.Substring(500,
                                                                            1000 - 500).Equals(new string(buf, 0, 500), StringComparison.Ordinal));
            }
#pragma warning disable 168
            catch (IOException e)
#pragma warning restore 168
            {
                fail("Exception during reset test");
            }
            try
            {
                br = new BufferedCharFilter(new StringReader(testString));
                br.Skip(500);
                br.Reset();
                fail("Reset succeeded on unmarked stream");
            }
#pragma warning disable 168
            catch (IOException x)
#pragma warning restore 168
            {
                return;
            }
        }
Exemplo n.º 2
0
 public void Test_SkipJ()
 {
     // Test for method long java.io.BufferedReader.skip(long)
     try
     {
         br = new BufferedCharFilter(new StringReader(testString));
         br.Skip(500);
         char[] buf = new char[testString.Length];
         br.Read(buf, 0, 500);
         assertTrue("Failed to set skip properly", testString.Substring(500,
                                                                        1000 - 500).Equals(new string(buf, 0, 500), StringComparison.Ordinal));
     }
     catch (Exception e) when(e.IsIOException())
     {
         fail("Exception during skip test");
     }
 }
Exemplo n.º 3
0
        public void Test_SkipJ()
        {
            // Test for method long java.io.BufferedReader.skip(long)
            try
            {
                br = new BufferedCharFilter(new StringReader(testString));
                br.Skip(500);
                char[] buf = new char[testString.Length];
                br.Read(buf, 0, 500);
                assertTrue("Failed to set skip properly", testString.Substring(500,
                                                                               1000 - 500).equals(new String(buf, 0, 500)));
            }
#pragma warning disable 168
            catch (IOException e)
#pragma warning restore 168
            {
                fail("Exception during skip test");
            }
        }
Exemplo n.º 4
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();
        }