Package org.jnode.util

Examples of org.jnode.util.ReaderInputStream


    @Test
    public void testLatin1Simple() throws Exception {
        final String LINE = "The quick brown fox jumped over the lazy dog";
        Reader r = new StringReader(LINE);
        ReaderInputStream ris = new ReaderInputStream(r, "latin1");
        byte[] buffer = new byte[100];
        Assert.assertEquals(LINE.length(), ris.read(buffer));
        for (int i = 0; i < LINE.length(); i++) {
            Assert.assertEquals((byte) LINE.charAt(i), buffer[i]);
        }
    }
View Full Code Here


        for (int i = 0; i < 256; i++) {
            bytes[i] = (byte) i;
        }
        final String LINE = new String(bytes, "latin1");
        Reader r = new StringReader(LINE);
        ReaderInputStream ris = new ReaderInputStream(r, "latin1");
        byte[] buffer = new byte[256];
        Assert.assertEquals(LINE.length(), ris.read(buffer));
        for (int i = 0; i < LINE.length(); i++) {
            Assert.assertEquals((byte) i, buffer[i]);
        }
    }
View Full Code Here

        for (int i = 0; i < 257; i++) {
            chars[i] = (char) i;
        }
        final String LINE = new String(chars);
        Reader r = new StringReader(LINE);
        ReaderInputStream ris = new ReaderInputStream(r, "latin1");
        byte[] buffer = new byte[257];
        Assert.assertEquals(256, ris.read(buffer));
        try {
            ris.read(buffer);
            Assert.fail("No exception raised");
        } catch (UnmappableCharacterException ex) {
            // expected
        }
    }
View Full Code Here

        for (int i = 0; i < 11; i++) {
            chars[i] = i == 5 ? '\u0101' : (char) ('A' + i);
        }
        final String LINE = new String(chars);
        Reader r = new StringReader(LINE);
        ReaderInputStream ris = new ReaderInputStream(r, "latin1");
        byte[] buffer = new byte[5];
        Assert.assertEquals(5, ris.read(buffer));
        try {
            ris.read();
            Assert.fail("No exception raised");
        } catch (UnmappableCharacterException ex) {
            // expected
        }
        Assert.assertEquals(5, ris.read(buffer));
    }
View Full Code Here

        for (int i = 0; i < 1024; i++) {
            chars[i] = (char) i;
        }
        final String LINE = new String(chars);
        Reader r = new StringReader(LINE);
        ReaderInputStream ris = new ReaderInputStream(r, "UTF-8");
        InputStreamReader isr = new InputStreamReader(ris);
        char[] buffer = new char[1024];
        isr.read(buffer);
        for (int i = 0; i < 1024; i++) {
            Assert.assertEquals(chars[i], buffer[i]);
View Full Code Here

    @Test
    public void testUnicode2() throws Exception {
        char[] chars = new char[] {'\ud800', '\udc00'};
        final String LINE = new String(chars);
        Reader r = new StringReader(LINE);
        ReaderInputStream ris = new ReaderInputStream(r, "UTF-8");
        InputStreamReader isr = new InputStreamReader(ris);
        Assert.assertEquals(chars[0], isr.read());
        Assert.assertEquals(chars[1], isr.read());
    }
View Full Code Here

    @Test
    public void testBadUnicode() throws Exception {
        char[] chars = new char[] {'\ud800'};
        final String LINE = new String(chars);
        Reader r = new StringReader(LINE);
        ReaderInputStream ris = new ReaderInputStream(r, "UTF-8");
        InputStreamReader isr = new InputStreamReader(ris);
        try {
            isr.read();
            Assert.fail("No exception raised");
        } catch (MalformedInputException ex) {
View Full Code Here

    public void testBadUnicode2() throws Exception {
        char[] chars = new char[] {'a', '\ud800'};
        final String LINE = new String(chars);
        try {
            Reader r = new StringReader(LINE.substring(1));
            ReaderInputStream ris = new ReaderInputStream(r, "UTF-8");
            InputStreamReader isr = new InputStreamReader(ris);
            isr.read();
            Assert.fail("No exception raised");
        } catch (MalformedInputException ex) {
            // expected
        }

        Reader r = new StringReader(LINE.substring(0, 1));
        ReaderInputStream ris = new ReaderInputStream(r, "UTF-8");
        InputStreamReader isr = new InputStreamReader(ris);
        Assert.assertEquals(chars[0], isr.read());
    }
View Full Code Here

    @Test
    public void testBadUnicode3() throws Exception {
        char[] chars = new char[] {'\udc00'};
        final String LINE = new String(chars);
        Reader r = new StringReader(LINE);
        ReaderInputStream ris = new ReaderInputStream(r, "UTF-8");
        InputStreamReader isr = new InputStreamReader(ris);
        try {
            isr.read();
            Assert.fail("No exception raised");
        } catch (MalformedInputException ex) {
View Full Code Here

    @Test
    public void testUnicode3() throws Exception {
        char[] chars = new char[] {'\ud800', '\udc00'};
        final String LINE = new String(chars);
        Reader r = new OneCharAtATimeReader(new StringReader(LINE));
        ReaderInputStream ris = new ReaderInputStream(r, "UTF-8");
        InputStreamReader isr = new InputStreamReader(ris);
        Assert.assertEquals(chars[0], isr.read());
        Assert.assertEquals(chars[1], isr.read());
    }
View Full Code Here

TOP

Related Classes of org.jnode.util.ReaderInputStream

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.