public static FormValidation validateBase64 ( String value , boolean allowWhitespace , boolean allowEmpty , String errorMessage ) { try { String v = value ; if ( ! allowWhitespace ) { if ( v . indexOf ( ' ' ) >= 0 || v . indexOf ( ' ' ) >= 0 ) return error ( errorMessage ) ; } v = v . trim ( ) ; if ( ! allowEmpty && v . length ( ) == 0 ) return error ( errorMessage ) ; Base64 . getDecoder ( ) . decode ( v . getBytes ( StandardCharsets . UTF_8 ) ) ; return ok ( ) ; } catch ( IllegalArgumentException e ) { return error ( errorMessage ) ; } }
Makes sure that the given string is a base64 encoded text .