/** * Decodes a Base64 object into its original form. Escaped characters are converted back to their original * representation. * * @param value * Base64 object to convert into its original form * @return original object * @throws DecoderException * Thrown if the argument is not a <code>String</code>. Thrown if a failure condition is encountered * during the decode process. */ @Override public Object decode(final Object value) throws DecoderException { if (value == null) { return null; } else if (value instanceof String) { return decode((String) value); } else { throw new DecoderException("Objects of type " + value.getClass().getName() + " cannot be decoded using BCodec"); } }
/** * Decodes a Base64 object into its original form. Escaped characters are converted back to their original * representation. * * @param value * Base64 object to convert into its original form * * @return original object * * @throws DecoderException * A decoder exception is thrown if a failure condition is encountered during the decode process. */ public Object decode(Object value) throws DecoderException { if (value == null) { return null; } else if (value instanceof String) { return decode((String) value); } else { throw new DecoderException("Objects of type " + value.getClass().getName() + " cannot be decoded using BCodec"); } }
@Test public void testDecodeObjects() throws Exception { final BCodec bcodec = new BCodec(); final String decoded = "=?UTF-8?B?d2hhdCBub3Q=?="; final String plain = (String) bcodec.decode((Object) decoded); assertEquals("Basic B decoding test", "what not", plain); final Object result = bcodec.decode((Object) null); assertEquals("Decoding a null Object should return null", null, result); try { final Object dObj = new Double(3.0); bcodec.decode(dObj); fail("Trying to url encode a Double object should cause an exception."); } catch (final DecoderException ee) { // Exception expected, test segment passes. } } }
@Test public void testDecodeStringWithNull() throws Exception { final BCodec bcodec = new BCodec(); final String test = null; final String result = bcodec.decode(test); assertEquals("Result should be null", null, result); }
@Test public void testBasicEncodeDecode() throws Exception { final BCodec bcodec = new BCodec(); final String plain = "Hello there"; final String encoded = bcodec.encode(plain); assertEquals("Basic B encoding test", "=?UTF-8?B?SGVsbG8gdGhlcmU=?=", encoded); assertEquals("Basic B decoding test", plain, bcodec.decode(encoded)); }
@Test public void testEncodeDecodeNull() throws Exception { final BCodec bcodec = new BCodec(); assertNull("Null string B encoding test", bcodec.encode((String) null)); assertNull("Null string B decoding test", bcodec.decode((String) null)); }
@Test public void testUTF8RoundTrip() throws Exception { final String ru_msg = constructString(RUSSIAN_STUFF_UNICODE); final String ch_msg = constructString(SWISS_GERMAN_STUFF_UNICODE); final BCodec bcodec = new BCodec(CharEncoding.UTF_8); assertEquals("=?UTF-8?B?0JLRgdC10Lxf0L/RgNC40LLQtdGC?=", bcodec.encode(ru_msg)); assertEquals("=?UTF-8?B?R3LDvGV6aV96w6Rtw6Q=?=", bcodec.encode(ch_msg)); assertEquals(ru_msg, bcodec.decode(bcodec.encode(ru_msg))); assertEquals(ch_msg, bcodec.decode(bcodec.encode(ch_msg))); }
/** * Decodes a Base64 object into its original form. Escaped characters are converted back to their original * representation. * * @param value * Base64 object to convert into its original form * * @return original object * * @throws DecoderException * A decoder exception is thrown if a failure condition is encountered during the decode process. */ public Object decode(Object value) throws DecoderException { if (value == null) { return null; } else if (value instanceof String) { return decode((String) value); } else { throw new DecoderException("Objects of type " + value.getClass().getName() + " cannot be decoded using BCodec"); } }
/** * Decodes a Base64 object into its original form. Escaped characters are converted back to their original * representation. * * @param value * Base64 object to convert into its original form * @return original object * @throws DecoderException * Thrown if the argument is not a <code>String</code>. Thrown if a failure condition is encountered * during the decode process. */ @Override public Object decode(final Object value) throws DecoderException { if (value == null) { return null; } else if (value instanceof String) { return decode((String) value); } else { throw new DecoderException("Objects of type " + value.getClass().getName() + " cannot be decoded using BCodec"); } }
/** * Decodes a Base64 object into its original form. Escaped characters are converted back to their original * representation. * * @param value * Base64 object to convert into its original form * * @return original object * * @throws DecoderException * A decoder exception is thrown if a failure condition is encountered during the decode process. */ public Object decode(Object value) throws DecoderException { if (value == null) { return null; } else if (value instanceof String) { return decode((String) value); } else { throw new DecoderException("Objects of type " + value.getClass().getName() + " cannot be decoded using BCodec"); } }
/** * Decodes a Base64 object into its original form. Escaped characters are converted back to their original * representation. * * @param value * Base64 object to convert into its original form * @return original object * @throws DecoderException * Thrown if the argument is not a <code>String</code>. Thrown if a failure condition is encountered * during the decode process. */ @Override public Object decode(final Object value) throws DecoderException { if (value == null) { return null; } else if (value instanceof String) { return decode((String) value); } else { throw new DecoderException("Objects of type " + value.getClass().getName() + " cannot be decoded using BCodec"); } }
/** * Decodes a Base64 object into its original form. Escaped characters are converted back to their original * representation. * * @param value * Base64 object to convert into its original form * * @return original object * * @throws DecoderException * A decoder exception is thrown if a failure condition is encountered during the decode process. */ public Object decode(Object value) throws DecoderException { if (value == null) { return null; } else if (value instanceof String) { return decode((String) value); } else { throw new DecoderException("Objects of type " + value.getClass().getName() + " cannot be decoded using BCodec"); } }
/** * Decodes a Base64 object into its original form. Escaped characters are converted back to their original * representation. * * @param value * Base64 object to convert into its original form * * @return original object * * @throws DecoderException * A decoder exception is thrown if a failure condition is encountered during the decode process. */ public Object decode(Object value) throws DecoderException { if (value == null) { return null; } else if (value instanceof String) { return decode((String) value); } else { throw new DecoderException("Objects of type " + value.getClass().getName() + " cannot be decoded using BCodec"); } }
/** * Decodes a Base64 object into its original form. Escaped characters are converted back to their original * representation. * * @param value * Base64 object to convert into its original form * @return original object * @throws DecoderException * Thrown if the argument is not a <code>String</code>. Thrown if a failure condition is encountered * during the decode process. */ @Override public Object decode(final Object value) throws DecoderException { if (value == null) { return null; } else if (value instanceof String) { return decode((String) value); } else { throw new DecoderException("Objects of type " + value.getClass().getName() + " cannot be decoded using BCodec"); } }
/** * Decodes a Base64 object into its original form. Escaped characters are converted back to their original * representation. * * @param value * Base64 object to convert into its original form * @return original object * @throws DecoderException * Thrown if the argument is not a <code>String</code>. Thrown if a failure condition is encountered * during the decode process. */ @Override public Object decode(final Object value) throws DecoderException { if (value == null) { return null; } else if (value instanceof String) { return decode((String) value); } else { throw new DecoderException("Objects of type " + value.getClass().getName() + " cannot be decoded using BCodec"); } }
/** * Decodes a Base64 object into its original form. Escaped characters are converted back to their original * representation. * * @param value * Base64 object to convert into its original form * * @return original object * * @throws DecoderException * A decoder exception is thrown if a failure condition is encountered during the decode process. */ public Object decode(Object value) throws DecoderException { if (value == null) { return null; } else if (value instanceof String) { return decode((String) value); } else { throw new DecoderException("Objects of type " + value.getClass().getName() + " cannot be decoded using BCodec"); } }
/** * Decodes a Base64 object into its original form. Escaped characters are converted back to their original * representation. * * @param value * Base64 object to convert into its original form * @return original object * @throws DecoderException * Thrown if the argument is not a <code>String</code>. Thrown if a failure condition is encountered * during the decode process. */ @Override public Object decode(final Object value) throws DecoderException { if (value == null) { return null; } else if (value instanceof String) { return decode((String) value); } else { throw new DecoderException("Objects of type " + value.getClass().getName() + " cannot be decoded using BCodec"); } }
/** * Used to decode a string as specified by RFC 2047 * @param value The encoded string */ public static String decode(String value) { if (value == null) return null; try { // try BCodec first return (new BCodec()).decode(value); } catch (DecoderException de) { // try QCodec next try { return (new QCodec()).decode(value); } catch (Exception ex) { return value; } } catch (Exception e) { return value; } }
/** * Used to decode a string as specified by RFC 2047 * * @param value The encoded string */ public static String decode(String value) { if (value == null) return null; try { // try BCodec first return (new BCodec()).decode(value); } catch (DecoderException de) { // try QCodec next try { return (new QCodec()).decode(value); } catch (Exception ex) { return value; } } catch (Exception e) { return value; } }