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

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