class JavaStringToEscapedJsonString implements UnaryOperator<String> {

    @Override
    public String apply(final String javaString) {
        requireNonNull(javaString, "The Java String to be converted must not be null");
        final StringBuilder stringBuilder = new StringBuilder(javaString.length() + 2);
        stringBuilder.append(QUOTE);
        stringBuilder.append(javaString);
        int i = 1; // offset of starting " char
        for (final char c : javaString.toCharArray()) {
            @Nullable final String replacement = jsonCharEscaper.apply((int) c);
            if (null != replacement) {
                stringBuilder.replace(i, i + 1, replacement);
                i += replacement.length();
            } else {
                i++;
            }
        }
        stringBuilder.append(QUOTE);
        return stringBuilder.toString();
    }

    private  JavaStringToEscapedJsonString(final Function<Integer, String> theJsonCharEscaper);

}