### Question:
B2Utf8Util { public static void writeJsonString(CharSequence value, OutputStream out) throws IOException { out.write('"'); final int strLen = value.length(); for (int i=0; i < strLen; i++) { final char c = value.charAt(i); if (c < 32) { out.write('\\'); out.write('u'); out.write('0'); out.write('0'); out.write(B2StringUtil.LOWER_HEX_DIGITS[c / 16]); out.write(B2StringUtil.LOWER_HEX_DIGITS[c % 16]); } else if (c == '"') { out.write('\\'); out.write('"'); } else if (c == '\\') { out.write('\\'); out.write('\\'); } else { i = doCommonWrite(value, i, c, out); } } out.write('"'); }  static void write(String str,
                             OutputStream out); static void writeJsonString(CharSequence value,
                                       OutputStream out);  }### Answer:
@Test public void testWriteJsonString() throws IOException { int numTested = 0; int numBaddish = 0; for (int codePoint = 0; codePoint <= MAX_CODE_POINT; codePoint++) { try { final String codePointStr = stringForCodePoint(codePoint); if (codePoint < 32) { final String expected = '"' + String.format("\\u%04x", codePoint) + '"'; checkByteArrays(B2StringUtil.getUtf8Bytes(expected), convertForJsonString(codePointStr)); } else if (codePoint == '"') { final byte[] expected = { '"', '\\', '"', '"'}; checkByteArrays(expected, convertForJsonString(codePointStr)); } else if (codePoint == '\\') { final byte[] expected = { '"', '\\', '\\', '"'}; checkByteArrays(expected, convertForJsonString(codePointStr)); } else if (codePoint >= 0xD800 && codePoint <= 0xDFFF) { checkBadSurrogateLikeCodePointForJsonString(codePointStr); numBaddish++; } else { checkValidCodePointForJsonString(codePointStr); } numTested++; } catch (Throwable t) { throw new RuntimeException("trouble for codePoint " + codePointNum(codePoint) + ": " + t, t); } } System.err.println("testWriteJsonString: tested " + numTested + " code points, including " + numBaddish + " bad-ish ones."); }