public static String objectToString(final Object fieldObject) { if (ObjectUtils.isNull(fieldObject)) { return NOT_PROVIDED; } if (fieldObject instanceof byte[]) { final byte[] objectBytes = (byte[]) fieldObject; final String toTest = StringUtils.newStringUtf8(objectBytes); if (!StringUtils.isUSAscii(toTest)) { return "Loaded file is binary - it's content is not displayable"; } else if (toTest.equals(StringUtils.FAILED)) { return StringUtils.FAILED; } try { return new String(objectBytes, StringUtils.UTF_8); } catch (UnsupportedEncodingException e) { return new String(objectBytes); } } else { final String valueAsStr = fieldObject.toString().trim(); return (!valueAsStr.equalsIgnoreCase("null") ? valueAsStr : ""); } }
public byte[] getResponseBodyAsBytes() { if (fileBytes.length == 0) { return StringUtils.getBytesUtf8(getBody()); } return fileBytes; }
@CoberturaIgnore public static String constructUserAgentName() { final Package pkg = StringUtils.class.getPackage(); final String implementationVersion = StringUtils.isSet(pkg.getImplementationVersion()) ? pkg.getImplementationVersion() : "x.x.xx"; return String.format("stubby4j/%s (HTTP stub client request)", implementationVersion); }
public static byte[] getBytesUtf8(final String string) { return string.getBytes(StringUtils.charsetUTF8()); }
public static String newStringUtf8(final byte[] bytes) { return new String(bytes, StringUtils.charsetUTF8()); }
public static int calculateStringLength(final String post) { if (StringUtils.isSet(post)) { return StringUtils.getBytesUtf8(post).length; } return 0; }
public static String encodeBase64(final String toEncode) { return BASE_64_ENCODER.encodeToString(StringUtils.getBytesUtf8(toEncode)); }
public static String replaceTokens( final byte[] stringBytes, final Map<String, String> tokensAndValues) { return replaceTokensInString(StringUtils.newStringUtf8(stringBytes), tokensAndValues); }
public boolean isRecordingRequired() { final String body = getBody(); return StringUtils.toLower(body).startsWith("http"); }
public String getBody() { return (StringUtils.isSet(body) ? body : ""); }
public boolean isBodyContainsTemplateTokens() { final boolean isFileTemplate = fileBytes.length != 0 && isTemplateFile(); return isFileTemplate || StringUtils.isTokenized(getBody()); }