@Override public boolean canDecode(CharSequence chars) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < chars.length(); i++) { char c = chars.charAt(i); if (separator.indexOf(c) < 0) { builder.append(c); } } return delegate.canDecode(builder); }
@Override public boolean canDecode(CharSequence chars) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < chars.length(); i++) { char c = chars.charAt(i); if (separator.indexOf(c) < 0) { builder.append(c); } } return delegate.canDecode(builder); }
@Override public boolean canDecode(CharSequence chars) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < chars.length(); i++) { char c = chars.charAt(i); if (separator.indexOf(c) < 0) { builder.append(c); } } return delegate.canDecode(builder); }
private static void testDecodes(BaseEncoding encoding, String encoded, String decoded) { assertTrue(encoding.canDecode(encoded)); assertThat(encoding.decode(encoded)).isEqualTo(decoded.getBytes(UTF_8)); }
private static void assertFailsToDecode( BaseEncoding encoding, String cannotDecode, @Nullable String expectedMessage) { assertFalse(encoding.canDecode(cannotDecode)); try { encoding.decode(cannotDecode); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { if (expectedMessage != null) { assertThat(expected).hasCauseThat().hasMessageThat().isEqualTo(expectedMessage); } } try { encoding.decodeChecked(cannotDecode); fail("Expected DecodingException"); } catch (DecodingException expected) { if (expectedMessage != null) { assertThat(expected).hasMessageThat().isEqualTo(expectedMessage); } } }
@Override public boolean canDecode(CharSequence chars) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < chars.length(); i++) { char c = chars.charAt(i); if (separator.indexOf(c) < 0) { builder.append(c); } } return delegate.canDecode(builder); }
@Override public boolean canDecode(CharSequence chars) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < chars.length(); i++) { char c = chars.charAt(i); if (separator.indexOf(c) < 0) { builder.append(c); } } return delegate.canDecode(builder); }
/** * Validate provided string that is expected to be in Base64 encoding. If the string is in Base64 * encoding, validate for expected length of decoded bytes. * @param base64candidate Base64 string candidate. * @param expectedLength Expected length od decoded bytes. * @return True in case the provided string are Base64 encoded data of expected byte length, * false otherwise. */ public static boolean isValidBase64OfLength(String base64candidate, int expectedLength) { final BaseEncoding base64 = BaseEncoding.base64(); if (base64candidate != null && base64.canDecode(base64candidate)) { byte[] bytes = base64.decode(base64candidate); return bytes.length == expectedLength; } else { return false; } }
/** * Validate provided string that is expected to be in Base64 encoding. If the string is in Base64 * encoding, validate for expected length of decoded bytes. * @param base64candidate Base64 string candidate. * @param expectedLength Expected length od decoded bytes. * @return True in case the provided string are Base64 encoded data of expected byte length, * false otherwise. */ public static boolean isValidBase64OfLength(String base64candidate, int expectedLength) { final BaseEncoding base64 = BaseEncoding.base64(); if (base64candidate != null && base64.canDecode(base64candidate)) { byte[] bytes = base64.decode(base64candidate); return bytes.length == expectedLength; } else { return false; } }
/** * Validate provided string that is expected to be in Base64 encoding. If the string is in Base64 * encoding, validate if expected length of decoded bytes is in range from-to. * @param base64candidate Base64 string candidate. * @param from Expected minimal length od decoded bytes. * @param to Expected maximal length od decoded bytes. * @return True in case the provided string are Base64 encoded data of expected byte length, * false otherwise. */ public static boolean isValidBase64OfLengthRange(String base64candidate, int from, int to) { final BaseEncoding base64 = BaseEncoding.base64(); if (base64candidate != null && base64.canDecode(base64candidate)) { byte[] bytes = base64.decode(base64candidate); return bytes.length >= from && bytes.length <= to; } else { return false; } }
/** * Validate provided string that is expected to be in Base64 encoding. If the string is in Base64 * encoding, validate if expected length of decoded bytes is in range from-to. * @param base64candidate Base64 string candidate. * @param from Expected minimal length od decoded bytes. * @param to Expected maximal length od decoded bytes. * @return True in case the provided string are Base64 encoded data of expected byte length, * false otherwise. */ public static boolean isValidBase64OfLengthRange(String base64candidate, int from, int to) { final BaseEncoding base64 = BaseEncoding.base64(); if (base64candidate != null && base64.canDecode(base64candidate)) { byte[] bytes = base64.decode(base64candidate); return bytes.length >= from && bytes.length <= to; } else { return false; } }
private static void testDecodes(BaseEncoding encoding, String encoded, String decoded) { assertTrue(encoding.canDecode(encoded)); assertThat(encoding.decode(encoded)).isEqualTo(decoded.getBytes(UTF_8)); }
private static void assertFailsToDecode( BaseEncoding encoding, String cannotDecode, @Nullable String expectedMessage) { assertFalse(encoding.canDecode(cannotDecode)); try { encoding.decode(cannotDecode); fail("Expected IllegalArgumentException"); } catch (IllegalArgumentException expected) { if (expectedMessage != null) { assertThat(expected.getCause()).hasMessage(expectedMessage); } } try { encoding.decodeChecked(cannotDecode); fail("Expected DecodingException"); } catch (DecodingException expected) { if (expectedMessage != null) { assertThat(expected).hasMessage(expectedMessage); } } }