class Utils {

    public static String decodeIfText(ByteBuffer buffer, String contentType)
            throws CharacterCodingException {
        if (contentType == null) {
            return null;
        }

        String body = null;
        if (isContentTypeText(contentType)) {
            CharsetDecoder decoder = decodersPerThread.get().reset();
            body = decoder.decode(buffer).toString();
        } else if (contentType.contains(Operation.MEDIA_TYPE_APPLICATION_X_WWW_FORM_ENCODED)) {
            CharsetDecoder decoder = decodersPerThread.get().reset();
            body = decoder.decode(buffer).toString();
            try {
                body = URLDecoder.decode(body, Utils.CHARSET);
            } catch (UnsupportedEncodingException e) {
                throw new RuntimeException(e);
            }
        }

        return body;
    }

    private  Utils();

}