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

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