FileDocCategorySizeDatePackage
ReaderInputStreamTest.javaAPI DocApache Ant 1.703333Wed Dec 13 06:16:18 GMT 2006org.apache.tools.ant.util

ReaderInputStreamTest

public class ReaderInputStreamTest extends TestCase
Test for ReaderInputStream

Fields Summary
Constructors Summary
public ReaderInputStreamTest(String s)

        super(s);
    
Methods Summary
private voidcompareBytes(java.lang.String s, java.lang.String encoding)

        byte[] expected = s.getBytes(encoding);
        
        ReaderInputStream r = new ReaderInputStream(
            new StringReader(s), encoding);
        for (int i = 0; i < expected.length; ++i) {
            int expect = expected[i] & 0xFF;
            int read = r.read();
            if (expect != read) {
                fail("Mismatch in ReaderInputStream at index " + i
                     + " expecting " + expect + " got " + read + " for string "
                     + s + " with encoding " + encoding);
            }
        }
        if (r.read() != -1) {
            fail("Mismatch in ReaderInputStream - EOF not seen for string "
                 + s + " with encoding " + encoding);
        }
    
public voidtestPreample()

        byte[] bytes = "".getBytes("utf-16");
        System.out.println("Preample len is " + bytes.length);
    
public voidtestReadZero()

        ReaderInputStream r = new ReaderInputStream(
            new StringReader("abc"));
        byte[] bytes = new byte[30];
        // First read in zero bytes
        r.read(bytes, 0, 0);
        // Now read in the string
        int readin = r.read(bytes, 0, 10);
        // Make sure that the counts are the same
        assertEquals("abc".getBytes().length, readin);
    
public voidtestSimple()

        compareBytes("abc", "utf-8");
    
public voidtestSimple16()

        compareBytes("a", "utf-16");
    
public voidtestSimpleAbc16()

        // THIS WILL FAIL.
        //compareBytes("abc", "utf-16");
        byte[] bytes = new byte[40];
        int pos = 0;
        ReaderInputStream r = new ReaderInputStream(
            new StringReader("abc"), "utf-16");
        for (int i = 0; true; ++i) {
            int res = r.read();
            if (res == -1) {
                break;
            }
            bytes[pos++] = (byte) res;
        }
        bytes = "abc".getBytes("utf-16");
        //        String n = new String(bytes, 0, pos, "utf-16");
        String n = new String(bytes, 0, bytes.length, "utf-16");
        System.out.println(n);