001package com.restfb.json; 002 003import java.io.Writer; 004 005public class UnicodeJsonWriter extends JsonWriter { 006 007 UnicodeJsonWriter(Writer writer) { 008 super(writer); 009 } 010 011 @Override 012 protected char[] getReplacementChars(char ch) { 013 014 if (ch == '\\') { 015 return BS_CHARS; 016 } 017 if (ch == '"') { 018 return QUOT_CHARS; 019 } 020 if (ch == '\n') { 021 return LF_CHARS; 022 } 023 if (ch == '\r') { 024 return CR_CHARS; 025 } 026 if (ch == '\t') { 027 return TAB_CHARS; 028 } 029 if (ch < 0x20 || ch > 0x7f) { 030 return new char[] { '\\', 'u', HEX_DIGITS[ch >> 12 & 0x000f], HEX_DIGITS[ch >> 8 & 0x000f], 031 HEX_DIGITS[ch >> 4 & 0x000f], HEX_DIGITS[ch & 0x000f] }; 032 } else { 033 return NO_CHARS; 034 } 035 } 036}