/** * Converts the specified {@link String} to a <code><jk>byte</jk>[]</code>. */ @Override /* PojoSwap */ public byte[] unswap(BeanSession session, String s, ClassMeta<?> hint) throws Exception { return base64Decode(s); } }
@Test public void testBase64EncodeToString() throws Exception { String s = null; assertEquals(s, base64DecodeToString(base64EncodeToString(s))); s = ""; assertEquals(s, base64DecodeToString(base64EncodeToString(s))); s = "foobar"; assertEquals(s, base64DecodeToString(base64EncodeToString(s))); s = "\u0000\uffff"; assertEquals(s, base64DecodeToString(base64EncodeToString(s))); try { base64Decode("a"); fail(); } catch (IllegalArgumentException e) { assertEquals("Invalid BASE64 string length. Must be multiple of 4.", e.getLocalizedMessage()); // OK. } try { base64Decode("aaa"); fail(); } catch (IllegalArgumentException e) { // OK. } }
/** * Converts the specified {@link String} to a <code><jk>byte</jk>[]</code>. */ @Override /* PojoSwap */ public byte[] unswap(BeanSession session, String s, ClassMeta<?> hint) throws Exception { return base64Decode(s); } }
/** * Converts the specified {@link String} to a <code><jk>byte</jk>[]</code>. */ @Override /* PojoSwap */ public byte[] unswap(BeanSession session, String s, ClassMeta<?> hint) throws Exception { return base64Decode(s); } }
/** * Shortcut for calling <code>base64Decode(String)</code> and converting the result to a UTF-8 encoded string. * * @param in The BASE-64 encoded string to decode. * @return The decoded string. */ public static String base64DecodeToString(String in) { byte[] b = base64Decode(in); if (b == null) return null; return new String(b, IOUtils.UTF8); }
/** * Shortcut for calling <code>base64Decode(String)</code> and converting the result to a UTF-8 encoded string. * * @param in The BASE-64 encoded string to decode. * @return The decoded string. */ public static String base64DecodeToString(String in) { byte[] b = base64Decode(in); if (b == null) return null; return new String(b, IOUtils.UTF8); }
/** * Shortcut for calling <code>base64Decode(String)</code> and converting the result to a UTF-8 encoded string. * * @param in The BASE-64 encoded string to decode. * @return The decoded string. */ public static String base64DecodeToString(String in) { byte[] b = base64Decode(in); if (b == null) return null; return new String(b, IOUtils.UTF8); }
@Override /* ConfigEncoder */ public String decode(String fieldName, String in) { if (! isEncoded(in)) return in; in = in.substring(1, in.length()-1); byte[] b = base64Decode(in); for (int i = 0; i < b.length; i++) { int j = i % key.length(); b[i] = (byte)(b[i] ^ key.charAt(j)); } return new String(b, UTF8); }
@Override /* ConfigEncoder */ public String decode(String fieldName, String in) { if (! isEncoded(in)) return in; in = in.substring(1, in.length()-1); byte[] b = base64Decode(in); for (int i = 0; i < b.length; i++) { int j = i % key.length(); b[i] = (byte)(b[i] ^ key.charAt(j)); } return new String(b, UTF8); }
@Override /* ConfigEncoder */ public String decode(String fieldName, String in) { if (! isEncoded(in)) return in; in = in.substring(1, in.length()-1); byte[] b = base64Decode(in); for (int i = 0; i < b.length; i++) { int j = i % key.length(); b[i] = (byte)(b[i] ^ key.charAt(j)); } return new String(b, UTF8); }
private byte[] convertFromString(String in) { switch(binaryFormat) { case BASE64: return base64Decode(in); case HEX: return fromHex(in); case SPACED_HEX: return fromSpacedHex(in); default: return new byte[0]; } }
private byte[] convertFromString(String in) { switch(binaryFormat) { case BASE64: return base64Decode(in); case HEX: return fromHex(in); case SPACED_HEX: return fromSpacedHex(in); default: return new byte[0]; } }
private byte[] convertFromString(String in) { switch(binaryFormat) { case BASE64: return base64Decode(in); case HEX: return fromHex(in); case SPACED_HEX: return fromSpacedHex(in); default: return new byte[0]; } }
@SuppressWarnings({ "unchecked" }) private <T> T parse(String s, Parser parser, Type type, Type...args) throws ParseException { if (isEmpty(s)) return null; if (isSimpleType(type)) return (T)beanSession.convertToType(s, (Class<?>)type); if (type == byte[].class) { if (s.indexOf('\n') != -1) s = s.replaceAll("\n", ""); try { switch (binaryFormat) { case HEX: return (T)fromHex(s); case SPACED_HEX: return (T)fromSpacedHex(s); default: return (T)base64Decode(s); } } catch (Exception e) { throw new ParseException(e, "Value could not be converted to a byte array."); } } if (parser == null) parser = this.parser; if (parser instanceof JsonParser) { char s1 = firstNonWhitespaceChar(s); if (isArray(type) && s1 != '[') s = '[' + s + ']'; else if (s1 != '[' && s1 != '{' && ! "null".equals(s)) s = '\'' + s + '\''; } return parser.parse(s, type, args); }
@SuppressWarnings({ "unchecked" }) private <T> T parse(String s, Parser parser, Type type, Type...args) throws ParseException { if (isEmpty(s)) return null; if (isSimpleType(type)) return (T)beanSession.convertToType(s, (Class<?>)type); if (type == byte[].class) { if (s.indexOf('\n') != -1) s = s.replaceAll("\n", ""); try { switch (binaryFormat) { case HEX: return (T)fromHex(s); case SPACED_HEX: return (T)fromSpacedHex(s); default: return (T)base64Decode(s); } } catch (Exception e) { throw new ParseException(e, "Value could not be converted to a byte array."); } } if (parser == null) parser = this.parser; if (parser instanceof JsonParser) { char s1 = firstNonWhitespaceChar(s); if (isArray(type) && s1 != '[') s = '[' + s + ']'; else if (s1 != '[' && s1 != '{' && ! "null".equals(s)) s = '\'' + s + '\''; } return parser.parse(s, type, args); }
@SuppressWarnings({ "unchecked" }) private <T> T parse(String s, Parser parser, Type type, Type...args) throws ParseException { if (isEmpty(s)) return null; if (isSimpleType(type)) return (T)beanSession.convertToType(s, (Class<?>)type); if (type == byte[].class) { if (s.indexOf('\n') != -1) s = s.replaceAll("\n", ""); try { switch (binaryFormat) { case HEX: return (T)fromHex(s); case SPACED_HEX: return (T)fromSpacedHex(s); default: return (T)base64Decode(s); } } catch (Exception e) { throw new ParseException(e, "Value could not be converted to a byte array."); } } if (parser == null) parser = this.parser; if (parser instanceof JsonParser) { char s1 = firstNonWhitespaceChar(s); if (isArray(type) && s1 != '[') s = '[' + s + ']'; else if (s1 != '[' && s1 != '{' && ! "null".equals(s)) s = '\'' + s + '\''; } return parser.parse(s, type, args); }
if (type.isObject()) { if (f == BYTE) return (T)base64Decode(in); if (f == DATE || f == DATE_TIME) return (T)parseIsoCalendar(in); return toType(base64Decode(in), type); if (f == DATE || f == DATE_TIME) return toType(parseIsoCalendar(in), type);
if (type.isObject()) { if (f == BYTE) return (T)base64Decode(in); if (f == DATE || f == DATE_TIME) return (T)parseIsoCalendar(in); return toType(base64Decode(in), type); if (f == DATE || f == DATE_TIME) return toType(parseIsoCalendar(in), type);
if (type.isObject()) { if (f == BYTE) return (T)base64Decode(in); if (f == DATE || f == DATE_TIME) return (T)parseIsoCalendar(in); return toType(base64Decode(in), type); if (f == DATE || f == DATE_TIME) return toType(parseIsoCalendar(in), type);