Package org.auraframework.util

Examples of org.auraframework.util.Utf8InputStreamReader


    public void testLatinCharsOnly() throws Exception {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream(10);
        final String testChars = "abc123_+/`";
        baos.write(testChars.getBytes(Charsets.UTF_8));
        final Reader reader = new Utf8InputStreamReader(new ByteArrayInputStream(baos.toByteArray()));
        final char[] actual = new char[10];
        try {
            assertTrue(reader.ready());
            assertEquals(8, reader.read(actual, 0, 8));
            assertFalse(reader.ready());
            assertEquals(2, reader.read(actual, 8, 8));
            assertEquals(-1, reader.read(actual, 10, 8));
            assertEquals(-1, reader.read());
            assertEquals(-1, reader.read(actual));
            assertFalse(reader.ready());

            // Ensure that we match
            assertTrue(Arrays.equals(testChars.toCharArray(), actual));
        } finally {
            reader.close();
        }
    }
View Full Code Here


                        return 0;
                    }
                }
            };
        }
        final Reader reader = new Utf8InputStreamReader(in);
        final char[] actual = new char[testChars.length()];
        try {
            if (!oneByteAtATime) {
                assertTrue(reader.ready());
            }
            assertEquals(testChars.length(), reader.read(actual));
            assertEquals(-1, reader.read());
            assertEquals(-1, reader.read(actual, 10, 8));
            assertEquals(-1, reader.read(actual));
            assertFalse(reader.ready());

            // Ensure that we match
            assertTrue(Arrays.equals(testChars.toCharArray(), actual));
        } finally {
            reader.close();
        }
    }
View Full Code Here

        baos.write(0xbf);
        baos.write('h');
        baos.write(0xfe); // not valid UTF-8
        baos.write(0xff); // not valid UTF-8
        baos.write('i');
        final Reader reader = new Utf8InputStreamReader(new ByteArrayInputStream(baos.toByteArray()));
        try {
            assertTrue(reader.ready());
            assertEquals('h', reader.read());
            assertFalse(reader.ready());
            assertEquals('i', reader.read());
            assertEquals(-1, reader.read());
            assertFalse(reader.ready());
        } finally {
            reader.close();
        }
    }
View Full Code Here

        baos.write(0xF0);
        baos.write(0xA0);
        baos.write(0x02);
        baos.write(0x03);
        baos.write(0x04);
        final Reader reader = new Utf8InputStreamReader(new ByteArrayInputStream(baos.toByteArray()));
        try {
            assertEquals(0x04, reader.read());
            assertEquals(-1, reader.read());
        } finally {
            reader.close();
        }
    }
View Full Code Here

        baos.write(0xB2); // middle of a UTF-8 sequence
        baos.write(0xB2); // middle of a UTF-8 sequence
        baos.write(0xBF); // middle of a UTF-8 sequence
        baos.write(0xB2); // middle of a UTF-8 sequence
        baos.write('H'); // 1-byte UTF-8
        final Reader reader = new Utf8InputStreamReader(new ByteArrayInputStream(baos.toByteArray()));
        try {
            assertEquals('䷾', reader.read());
            assertEquals('H', reader.read());
            assertEquals(-1, reader.read());
        } finally {
            reader.close();
        }
    }
View Full Code Here

    public void testTooShortUTF8() throws Exception {
        final ByteArrayOutputStream baos = new ByteArrayOutputStream(3);
        baos.write(0xF0);
        baos.write(0xA0);
        final Reader reader = new Utf8InputStreamReader(new ByteArrayInputStream(baos.toByteArray()));
        try {
            assertEquals(-1, reader.read());
        } finally {
            reader.close();
        }
    }
View Full Code Here

        baos.write(0xBF);
        baos.write('H');
        baos.write(0xEF); // Little endian BOM in UTF-8
        baos.write(0xBF);
        baos.write(0xBE);
        final Reader reader = new Utf8InputStreamReader(new ByteArrayInputStream(baos.toByteArray()));
        try {
            assertEquals('H', reader.read());
            assertEquals(-1, reader.read());
        } finally {
            reader.close();
        }
    }
View Full Code Here

        baos.write(0xEE); // First char after the last low surrogate (okay to
                          // read)
        baos.write(0x80);
        baos.write(0x80);
        baos.write('H');
        final Reader reader = new Utf8InputStreamReader(new ByteArrayInputStream(baos.toByteArray()));
        try {
            assertEquals('퟿', reader.read());
            assertEquals('', reader.read());
            assertEquals('H', reader.read());
            assertEquals(-1, reader.read());
        } finally {
            reader.close();
        }
    }
View Full Code Here

        json.writeMapEnd();
        json.close();

        // Compare this against our expectations
        final DataInputStream in = new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));
        final Reader reader = new Utf8InputStreamReader(in);
        final char[] chars = new char[88];
        assertNextStringFromReader(reader, "{\"header\":[", chars);
        for (int i = 0; i < columns.length; i++) {
            assertNextStringFromReader(reader, "\"" + columns[i] + "\"", chars);
            if (i < columns.length - 1) {
                assertEquals(',', (char) reader.read());
            }
        }
        assertNextStringFromReader(reader, "],\"rows\":[[\"", chars);
        assertNextStringFromReader(reader, testChars, chars);
        assertNextStringFromReader(reader, "\",\"", chars);
        assertNextStringFromReader(reader, id1, chars);
        assertNextStringFromReader(reader, "\",`", chars);
        assertEquals(37, in.readLong());
        for (int i = 0; i < 37; i++) {
            assertEquals(i, in.read());
        }
        assertNextStringFromReader(reader, "`],[\"", chars);
        assertNextStringFromReader(reader, uuid, chars);
        assertNextStringFromReader(reader, "\",\"", chars);
        assertNextStringFromReader(reader, id2, chars);
        assertNextStringFromReader(reader, "\",`", chars);
        assertEquals(7, in.readLong());
        for (int i = 0; i < 7; i++) {
            assertEquals(255 - i, in.read());
        }
        assertNextStringFromReader(reader, "`]]}", chars);
        assertEquals(-1, reader.read());
        assertEquals(-1, in.read());
    }
View Full Code Here

        json.writeBinaryStreamEnd();
        json.close();

        // Check what was written
        final DataInputStream in = new DataInputStream(new ByteArrayInputStream(baos.toByteArray()));
        final Reader reader = new Utf8InputStreamReader(in);
        try {
            assertEquals('`', reader.read());
            assertEquals(0, in.readLong());
            assertEquals('`', reader.read());
            assertEquals(-1, reader.read());
        } finally {
            reader.close();
        }
    }
View Full Code Here

TOP

Related Classes of org.auraframework.util.Utf8InputStreamReader

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.