Package org.htmlparser.lexer

Examples of org.htmlparser.lexer.Source


    /**
     * Test initialization with a null value.
     */
    public void testInputStreamSourceNull () throws IOException
    {
        Source source;

        source = new InputStreamSource (null);
        assertTrue ("erroneous character", -1 == source.read ());
    }
View Full Code Here


    /**
     * Test initialization of a InputStreamSource with a zero length byte array.
     */
    public void testInputStreamSourceEmpty () throws IOException
    {
        Source source;

        source = new InputStreamSource (new Stream (new ByteArrayInputStream (new byte[0])), null);
        assertTrue ("erroneous character", -1 == source.read ());
    }
View Full Code Here

    /**
     * Test initialization of a InputStreamSource with an input stream having only one byte.
     */
    public void testInputStreamSourceOneByte () throws IOException
    {
        Source source;

        source = new InputStreamSource (new Stream (new ByteArrayInputStream (new byte[] { (byte)0x42 })), null);
        assertTrue ("erroneous character", 'B' == source.read ());
        assertTrue ("extra character", -1 == source.read ());
    }
View Full Code Here

    /**
     * Test closing a InputStreamSource.
     */
    public void testInputStreamSourceClose () throws IOException
    {
        Source source;

        source = new InputStreamSource (new Stream (new ByteArrayInputStream ("hello word".getBytes ())), null);
        assertTrue ("no character", -1 != source.read ());
        source.destroy ();
        try
        {
            source.read ();
            fail ("not closed");
        }
        catch (IOException ioe)
        {
            // expected outcome
View Full Code Here

     * Test resetting a InputStreamSource.
     */
    public void testInputStreamSourceReset () throws IOException
    {
        String reference;
        Source source;
        StringBuffer buffer;
        int c;

        reference = "Now is the time for all good men to come to the aid of the party";
        source = new InputStreamSource (new Stream (new ByteArrayInputStream (reference.getBytes (DEFAULT_CHARSET))), null);
        buffer = new StringBuffer (reference.length ());
        while (-1 != (c = source.read ()))
            buffer.append ((char)c);
        assertTrue ("string incorrect", reference.equals (buffer.toString ()));
        source.reset ();
        buffer.setLength (0);
        while (-1 != (c = source.read ()))
            buffer.append ((char)c);
        assertTrue ("string incorrect", reference.equals (buffer.toString ()));
        source.close ();
    }
View Full Code Here

     * Test resetting a InputStreamSource in the middle of reading.
     */
    public void testInputStreamSourceMidReset () throws IOException
    {
        String reference;
        Source source;
        StringBuffer buffer;
        int c;

        reference = "Now is the time for all good men to come to the aid of the party";
        source = new InputStreamSource (new Stream (new ByteArrayInputStream (reference.getBytes (DEFAULT_CHARSET))), null);
        buffer = new StringBuffer (reference.length ());
        for (int i = 0; i < 25; i++)
            buffer.append ((char)source.read ());
        source.reset ();
        for (int i = 0; i < 25; i++)
            source.read ();
        while (-1 != (c = source.read ()))
            buffer.append ((char)c);
        assertTrue ("string incorrect", reference.equals (buffer.toString ()));
        source.close ();
    }
View Full Code Here

     * Test mark/reset of a InputStreamSource in the middle of reading.
     */
    public void testInputStreamSourceMarkReset () throws IOException
    {
        String reference;
        Source source;
        StringBuffer buffer;
        int c;

        reference = "Now is the time for all good men to come to the aid of the party";
        source = new InputStreamSource (new Stream (new ByteArrayInputStream (reference.getBytes (DEFAULT_CHARSET))), null);
        assertTrue ("not markable", source.markSupported ());
        buffer = new StringBuffer (reference.length ());
        for (int i = 0; i < 25; i++)
            buffer.append ((char)source.read ());
        source.mark (88);
        for (int i = 0; i < 25; i++)
            source.read ();
        source.reset ();
        while (-1 != (c = source.read ()))
            buffer.append ((char)c);
        assertTrue ("string incorrect", reference.equals (buffer.toString ()));
        source.close ();
    }
View Full Code Here

    {
        String part1;
        String part2;
        String part3;
        String reference;
        Source source;
        StringBuffer buffer;
        int c;

        part1 = "Now is the time ";
        part2 = "for all good men ";
        part3 = "to come to the aid of the party";
        reference = part1 + part2 + part3;
        source = new InputStreamSource (new Stream (new ByteArrayInputStream (reference.getBytes (DEFAULT_CHARSET))), null);
        buffer = new StringBuffer (reference.length ());
        for (int i = 0; i < part1.length (); i++)
            buffer.append ((char)source.read ());
        source.skip (part2.length ());
        while (-1 != (c = source.read ()))
            buffer.append ((char)c);
        assertTrue ("string incorrect", (part1 + part3).equals (buffer.toString ()));
        source.close ();
    }
View Full Code Here

     * Test multi-byte read with a InputStreamSource.
     */
    public void testInputStreamSourceMultByte () throws IOException
    {
        String reference;
        Source source;
        char[] buffer;

        reference = "Now is the time for all good men to come to the aid of the party";
        source = new InputStreamSource (new Stream (new ByteArrayInputStream (reference.getBytes (DEFAULT_CHARSET))), null);
        buffer = new char[reference.length ()];
        source.read (buffer, 0, buffer.length);
        assertTrue ("string incorrect", reference.equals (new String (buffer)));
        assertTrue ("extra character", -1 == source.read ());
        source.close ();
    }
View Full Code Here

    {
        String part1;
        String part2;
        String part3;
        String reference;
        Source source;
        char[] buffer;
        int length;

        part1 = "Now is the time ";
        part2 = "for all good men ";
        part3 = "to come to the aid of the party";
        reference = part1 + part2 + part3;
        source = new InputStreamSource (new Stream (new ByteArrayInputStream (reference.getBytes (DEFAULT_CHARSET))), null);
        buffer = new char[reference.length ()];
        for (int i = 0; i < part1.length (); i++)
            buffer[i] = (char)source.read ();
        length = source.read (buffer, part1.length (), part2.length ());
        assertTrue ("incorrect length", part2.length () == length);
        length += part1.length ();
        for (int i = 0; i < part3.length (); i++)
            buffer[i + length] = (char)source.read ();
        assertTrue ("string incorrect", reference.equals (new String (buffer)));
        assertTrue ("extra character", -1 == source.read ());
        source.close ();
    }
View Full Code Here

TOP

Related Classes of org.htmlparser.lexer.Source

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.