Beispiel #1
0
  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 : "");
    }
  }
Beispiel #2
0
  public byte[] getResponseBodyAsBytes() {

    if (fileBytes.length == 0) {
      return StringUtils.getBytesUtf8(getBody());
    }
    return fileBytes;
  }
Beispiel #3
0
  @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);
  }
Beispiel #4
0
 public static byte[] getBytesUtf8(final String string) {
   return string.getBytes(StringUtils.charsetUTF8());
 }
Beispiel #5
0
 public static String newStringUtf8(final byte[] bytes) {
   return new String(bytes, StringUtils.charsetUTF8());
 }
Beispiel #6
0
 public static int calculateStringLength(final String post) {
   if (StringUtils.isSet(post)) {
     return StringUtils.getBytesUtf8(post).length;
   }
   return 0;
 }
Beispiel #7
0
 public static String encodeBase64(final String toEncode) {
   return BASE_64_ENCODER.encodeToString(StringUtils.getBytesUtf8(toEncode));
 }
Beispiel #8
0
 public static String replaceTokens(
     final byte[] stringBytes, final Map<String, String> tokensAndValues) {
   return replaceTokensInString(StringUtils.newStringUtf8(stringBytes), tokensAndValues);
 }
Beispiel #9
0
 public boolean isRecordingRequired() {
   final String body = getBody();
   return StringUtils.toLower(body).startsWith("http");
 }
Beispiel #10
0
 public String getBody() {
   return (StringUtils.isSet(body) ? body : "");
 }
Beispiel #11
0
 public boolean isBodyContainsTemplateTokens() {
   final boolean isFileTemplate = fileBytes.length != 0 && isTemplateFile();
   return isFileTemplate || StringUtils.isTokenized(getBody());
 }