more testing of UTF8Writer
diff --git a/src/main/java/com/fasterxml/jackson/core/util/VersionUtil.java b/src/main/java/com/fasterxml/jackson/core/util/VersionUtil.java
index 3896001..5bdc1b4 100644
--- a/src/main/java/com/fasterxml/jackson/core/util/VersionUtil.java
+++ b/src/main/java/com/fasterxml/jackson/core/util/VersionUtil.java
@@ -27,33 +27,17 @@
{
private final static Pattern V_SEP = Pattern.compile("[-_./;:]");
- private final Version _v;
-
/*
/**********************************************************
/* Instance life-cycle
/**********************************************************
*/
-
- protected VersionUtil()
- {
- Version v = null;
- try {
- /* Class we pass only matters for resource-loading: can't use this Class
- * (as it's just being loaded at this point), nor anything that depends on it.
- */
- v = VersionUtil.versionFor(getClass());
- } catch (Exception e) { // not good to dump to stderr; but that's all we have at this low level
- System.err.println("ERROR: Failed to load Version information from "+getClass());
- }
- if (v == null) {
- v = Version.unknownVersion();
- }
- _v = v;
- }
- public Version version() { return _v; }
-
+ protected VersionUtil() { }
+
+ @Deprecated // since 2.9
+ public Version version() { return Version.unknownVersion(); }
+
/*
/**********************************************************
/* Static load methods
diff --git a/src/test/java/com/fasterxml/jackson/core/io/UTF8WriterTest.java b/src/test/java/com/fasterxml/jackson/core/io/UTF8WriterTest.java
index 32d1c39..ddefff6 100644
--- a/src/test/java/com/fasterxml/jackson/core/io/UTF8WriterTest.java
+++ b/src/test/java/com/fasterxml/jackson/core/io/UTF8WriterTest.java
@@ -2,6 +2,8 @@
import java.io.*;
+import org.junit.Assert;
+
import com.fasterxml.jackson.core.io.IOContext;
import com.fasterxml.jackson.core.io.UTF8Writer;
import com.fasterxml.jackson.core.util.BufferRecycler;
@@ -51,6 +53,7 @@
char[] ch = str.toCharArray();
w.write(ch, 0, ch.length);
+ w.flush(); // trigger different code path for close
w.close();
byte[] data = out.toByteArray();
@@ -68,9 +71,11 @@
UTF8Writer w = new UTF8Writer(ctxt, out);
w.write('X');
+ char[] ch = { 'Y' };
+ w.write(ch);
w.close();
- assertEquals(1, out.size());
+ assertEquals(2, out.size());
// and this ought to be fine...
w.flush();
@@ -78,4 +83,80 @@
w.close();
w.flush();
}
+
+ public void testSurrogatesOk() throws Exception
+ {
+ BufferRecycler rec = new BufferRecycler();
+ IOContext ctxt = new IOContext(rec, null, false);
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ UTF8Writer w = new UTF8Writer(ctxt, out);
+
+ // First, valid case, char by char
+ w.write(0xD83D);
+ w.write(0xDE03);
+ w.close();
+ assertEquals(4, out.size());
+ final byte[] EXP_SURROGATES = new byte[] { (byte) 0xF0, (byte) 0x9F,
+ (byte) 0x98, (byte) 0x83 };
+ Assert.assertArrayEquals(EXP_SURROGATES, out.toByteArray());
+
+ // and then as String
+ ctxt = new IOContext(rec, null, false);
+ out = new ByteArrayOutputStream();
+ w = new UTF8Writer(ctxt, out);
+ w.write("\uD83D\uDE03");
+ w.close();
+ assertEquals(4, out.size());
+ Assert.assertArrayEquals(EXP_SURROGATES, out.toByteArray());
+ }
+
+ @SuppressWarnings("resource")
+ public void testSurrogatesFail() throws Exception
+ {
+ BufferRecycler rec = new BufferRecycler();
+ IOContext ctxt;
+ ByteArrayOutputStream out;
+ UTF8Writer w;
+
+ ctxt = new IOContext(rec, null, false);
+ out = new ByteArrayOutputStream();
+ w = new UTF8Writer(ctxt, out);
+ try {
+ w.write(0xDE03);
+ fail("should not pass");
+ } catch (IOException e) {
+ verifyException(e, "Unmatched second part");
+ }
+
+ ctxt = new IOContext(rec, null, false);
+ out = new ByteArrayOutputStream();
+ w = new UTF8Writer(ctxt, out);
+ w.write(0xD83D);
+ try {
+ w.write('a');
+ fail("should not pass");
+ } catch (IOException e) {
+ verifyException(e, "Broken surrogate pair");
+ }
+
+ ctxt = new IOContext(rec, null, false);
+ out = new ByteArrayOutputStream();
+ w = new UTF8Writer(ctxt, out);
+ try {
+ w.write("\uDE03");
+ fail("should not pass");
+ } catch (IOException e) {
+ verifyException(e, "Unmatched second part");
+ }
+
+ ctxt = new IOContext(rec, null, false);
+ out = new ByteArrayOutputStream();
+ w = new UTF8Writer(ctxt, out);
+ try {
+ w.write("\uD83Da");
+ fail("should not pass");
+ } catch (IOException e) {
+ verifyException(e, "Broken surrogate pair");
+ }
+ }
}