1
package com.fasterxml.jackson.core.io;
5
import com.fasterxml.jackson.core.io.IOContext;
6
import com.fasterxml.jackson.core.io.UTF8Writer;
7
import com.fasterxml.jackson.core.util.BufferRecycler;
9
public class TestUTF8Writer
10
extends com.fasterxml.jackson.test.BaseTest
12
public void testSimple() throws Exception
14
BufferRecycler rec = new BufferRecycler();
15
IOContext ctxt = new IOContext(rec, null, false);
16
ByteArrayOutputStream out = new ByteArrayOutputStream();
17
UTF8Writer w = new UTF8Writer(ctxt, out);
19
String str = "AB\u00A0\u1AE9\uFFFC";
20
char[] ch = str.toCharArray();
22
// Let's write 3 times, using different methods
29
w.write(str, 0, str.length());
32
// and thus should have 3 times contents
33
byte[] data = out.toByteArray();
34
assertEquals(3*10, data.length);
35
String act = out.toString("UTF-8");
36
assertEquals(15, act.length());
38
assertEquals(3 * str.length(), act.length());
39
assertEquals(str+str+str, act);
42
public void testFlushAfterClose() throws Exception
44
BufferRecycler rec = new BufferRecycler();
45
IOContext ctxt = new IOContext(rec, null, false);
46
ByteArrayOutputStream out = new ByteArrayOutputStream();
47
UTF8Writer w = new UTF8Writer(ctxt, out);
52
assertEquals(1, out.size());
54
// and this ought to be fine...
56
// as well as some more...