/** * Encodes array of bytes using base64 encoding and returns the result as a string. * * @param buffer Array of bytes to be encoded. * @return Resulting encoded string. */ public static String encodeAsString(final byte[] buffer) { final byte[] result = encode(buffer); try { return new String(result, "ASCII"); } catch (final UnsupportedEncodingException ex) { // should never happen return new String(result); } }
/** * Encodes array of bytes using base64 encoding and returns the result as a string. * * @param buffer Array of bytes to be encoded. * @return Resulting encoded string. */ public static String encodeAsString(final byte[] buffer) { final byte[] result = encode(buffer); try { return new String(result, "ASCII"); } catch (final UnsupportedEncodingException ex) { // should never happen return new String(result); } }
/** * Encodes array of bytes using base64 encoding and returns the result as a string. * * @param buffer Array of bytes to be encoded. * @return Resulting encoded string. */ public static String encodeAsString(final byte[] buffer) { final byte[] result = encode(buffer); try { return new String(result, "ASCII"); } catch (final UnsupportedEncodingException ex) { // should never happen return new String(result); } }
/** * Encodes array of bytes using base64 encoding and returns the result as a string. * * @param buffer Array of bytes to be encoded. * @return Resulting encoded string. */ public static String encodeAsString(final byte[] buffer) { final byte[] result = encode(buffer); try { return new String(result, "ASCII"); } catch (final UnsupportedEncodingException ex) { // should never happen return new String(result); } }
/** * Encodes array of bytes using base64 encoding and returns the result as a string. * * @param buffer Array of bytes to be encoded. * @return Resulting encoded string. */ public static String encodeAsString(final byte[] buffer) { final byte[] result = encode(buffer); try { return new String(result, "ASCII"); } catch (final UnsupportedEncodingException ex) { // should never happen return new String(result); } }
/** * Encodes array of bytes using base64 encoding and returns the result as a string. * * @param buffer Array of bytes to be encoded. * @return Resulting encoded string. */ public static String encodeAsString(final byte[] buffer) { final byte[] result = encode(buffer); try { return new String(result, "ASCII"); } catch (final UnsupportedEncodingException ex) { // should never happen return new String(result); } }
/** * Encodes array of bytes using base64 encoding and returns the result as a string. * * @param buffer Array of bytes to be encoded. * @return Resulting encoded string. */ public static String encodeAsString(final byte[] buffer) { final byte[] result = encode(buffer); try { return new String(result, "ASCII"); } catch (final UnsupportedEncodingException ex) { // should never happen return new String(result); } }
@Override public boolean isValid(Object testedPropertyValue, Object validatorPropertyValue) { if (testedPropertyValue == validatorPropertyValue) { return true; } String testedStringValue = ""; // If the property to be tested is a byte array, convert it to a string and convert it to Base64 if (testedPropertyValue instanceof byte[]) { byte[] encodedTestedProperty = Base64.encode((byte[]) testedPropertyValue); testedStringValue = new String(encodedTestedProperty); } else { testedStringValue = testedPropertyValue.toString(); } String validationRegex = validatorPropertyValue.toString(); if (testedStringValue.equals(validationRegex)) { return true; } final Pattern pattern; try { pattern = Pattern.compile(validationRegex); } catch (PatternSyntaxException e) { logWithTimestamp(" Validation string is not a valid regex. " + e.getMessage()); return false; } Matcher matcher = pattern.matcher(testedStringValue); boolean match = matcher.matches(); return match; }