Refine search
/** * Encodes a string into its Base64 form using the specified charset. Unsafe characters are escaped. * * @param value * string to convert to Base64 form * @param charset * the charset for <code>value</code> * @return Base64 string * @throws EncoderException * thrown if a failure condition is encountered during the encoding process. */ public String encode(final String value, final String charset) throws EncoderException { if (value == null) { return null; } try { return this.encodeText(value, charset); } catch (final UnsupportedEncodingException e) { throw new EncoderException(e.getMessage(), e); } }
@Test public void testConstructorString() { final EncoderException e = new EncoderException(MSG); assertEquals(MSG, e.getMessage()); assertNull(e.getCause()); }
@Override public Object encode(final Object object) throws EncoderException { if (!(object instanceof String)) { throw new EncoderException("This method's parameter was expected to be of the type " + String.class.getName() + ". But actually it was of the type " + object.getClass().getName() + "."); } return encode((String) object); }
/** * Converts the passed in object to a string * @param pObject * @return String */ public String toString(Object pObject){ String encoded = null; try{ encoded= encoder.encode((String)pObject); }catch(EncoderException ex){ ex.printStackTrace(); throw new TranslationException(ex.getMessage()); } return encoded; }
@Override public Object encode(final Object source) throws EncoderException { if (!(source instanceof String)) { throw new EncoderException("BeiderMorseEncoder encode parameter is not of type String"); } return encode((String) source); }
/** * Encodes a string into its quoted-printable form using the specified charset. Unsafe characters are escaped. * * @param str * string to convert to quoted-printable form * @param charset * the charset for str * @return quoted-printable string * @throws EncoderException * thrown if a failure condition is encountered during the encoding process. */ public String encode(final String str, final String charset) throws EncoderException { if (str == null) { return null; } try { return encodeText(str, charset); } catch (final UnsupportedEncodingException e) { throw new EncoderException(e.getMessage(), e); } }
/** * Encode the value using DoubleMetaphone. It will only work if * <code>obj</code> is a <code>String</code> (like <code>Metaphone</code>). * * @param obj Object to encode (should be of type String) * @return An encoded Object (will be of type String) * @throws EncoderException encode parameter is not of type String */ @Override public Object encode(final Object obj) throws EncoderException { if (!(obj instanceof String)) { throw new EncoderException("DoubleMetaphone encode parameter is not of type String"); } return doubleMetaphone((String) obj); }
@Test public void testConstructor0() { final EncoderException e = new EncoderException(); assertNull(e.getMessage()); assertNull(e.getCause()); }
/** * Encodes a string into its Base64 form using the specified charset. Unsafe characters are escaped. * * @param value * string to convert to Base64 form * @param charset * the charset for pString * @return Base64 string * * @throws EncoderException * thrown if a failure condition is encountered during the encoding process. */ public String encode(final String value, final String charset) throws EncoderException { if (value == null) { return null; } try { return encodeText(value, charset); } catch (UnsupportedEncodingException e) { throw new EncoderException(e.getMessage()); } }
/** * Converts an array of raw binary data into an array of ASCII 0 and 1 chars. * * @param raw * the raw binary data to convert * @return 0 and 1 ASCII character chars one for each bit of the argument * @throws EncoderException * if the argument is not a byte[] * @see org.apache.commons.codec.Encoder#encode(Object) */ @Override public Object encode(final Object raw) throws EncoderException { if (!(raw instanceof byte[])) { throw new EncoderException("argument not a byte array"); } return toAsciiChars((byte[]) raw); }
@Test public void testConstructorStringThrowable() { final EncoderException e = new EncoderException(MSG, t); assertEquals(MSG, e.getMessage()); assertEquals(t, e.getCause()); }
/** * Encodes a string into its quoted-printable form using the specified charset. Unsafe characters are escaped. * * @param pString * string to convert to quoted-printable form * @param charset * the charset for pString * @return quoted-printable string * * @throws EncoderException * thrown if a failure condition is encountered during the encoding process. */ public String encode(final String pString, final String charset) throws EncoderException { if (pString == null) { return null; } try { return encodeText(pString, charset); } catch (UnsupportedEncodingException e) { throw new EncoderException(e.getMessage()); } }
/** * Encodes an Object using the Base-N algorithm. This method is provided in order to satisfy the requirements of * the Encoder interface, and will throw an EncoderException if the supplied object is not of type byte[]. * * @param obj * Object to encode * @return An object (of type byte[]) containing the Base-N encoded data which corresponds to the byte[] supplied. * @throws EncoderException * if the parameter supplied is not of type byte[] */ @Override public Object encode(final Object obj) throws EncoderException { if (!(obj instanceof byte[])) { throw new EncoderException("Parameter supplied to Base-N encode is not a byte[]"); } return encode((byte[]) obj); }
@Test public void testConstructorThrowable() { final EncoderException e = new EncoderException(t); assertEquals(t.getClass().getName(), e.getMessage()); assertEquals(t, e.getCause()); }
/** * Encodes a string into its URL safe form using the default string charset. Unsafe characters are escaped. * * @param str * string to convert to a URL safe form * @return URL safe string * @throws EncoderException * Thrown if URL encoding is unsuccessful * * @see #getDefaultCharset() */ @Override public String encode(final String str) throws EncoderException { if (str == null) { return null; } try { return encode(str, getDefaultCharset()); } catch (final UnsupportedEncodingException e) { throw new EncoderException(e.getMessage(), e); } }
/** * Encodes an Object using the caverphone algorithm. This method is provided in order to satisfy the requirements of * the Encoder interface, and will throw an EncoderException if the supplied object is not of type java.lang.String. * * @param obj * Object to encode * @return An object (or type java.lang.String) containing the caverphone code which corresponds to the String * supplied. * @throws EncoderException * if the parameter supplied is not of type java.lang.String */ @Override public Object encode(final Object obj) throws EncoderException { if (!(obj instanceof String)) { throw new EncoderException("Parameter supplied to Caverphone encode is not of type java.lang.String"); } return this.caverphone((String) obj); }
/** * Encodes a string into its URL safe form using the default string * charset. Unsafe characters are escaped. * * @param pString string to convert to a URL safe form * @return URL safe string * @throws EncoderException Thrown if URL encoding is unsuccessful * * @see #getDefaultCharset() */ public String encode(String pString) throws EncoderException { if (pString == null) { return null; } try { return encode(pString, getDefaultCharset()); } catch(UnsupportedEncodingException e) { throw new EncoderException(e.getMessage()); } }
/** * Encodes an Object using the caverphone algorithm. This method is provided in order to satisfy the requirements of * the Encoder interface, and will throw an EncoderException if the supplied object is not of type java.lang.String. * * @param source * Object to encode * @return An object (or type java.lang.String) containing the caverphone code which corresponds to the String * supplied. * @throws EncoderException * if the parameter supplied is not of type java.lang.String */ @Override public Object encode(final Object source) throws EncoderException { if (!(source instanceof String)) { throw new EncoderException("Parameter supplied to Caverphone encode is not of type java.lang.String"); } return this.encode((String) source); }
/** * Encodes a string into its quoted-printable form using the default string charset. Unsafe characters are escaped. * * <p> * This function implements a subset of quoted-printable encoding specification (rule #1 and rule #2) as defined in * RFC 1521 and is suitable for encoding binary data. * </p> * * @param pString * string to convert to quoted-printable form * @return quoted-printable string * * @throws EncoderException * Thrown if quoted-printable encoding is unsuccessful * * @see #getDefaultCharset() */ public String encode(String pString) throws EncoderException { if (pString == null) { return null; } try { return encode(pString, getDefaultCharset()); } catch (UnsupportedEncodingException e) { throw new EncoderException(e.getMessage()); } }
/** * Encodes an Object using the Match Rating Approach algorithm. Method is here to satisfy the requirements of the * Encoder interface Throws an EncoderException if input object is not of type java.lang.String. * * @param pObject * Object to encode * @return An object (or type java.lang.String) containing the Match Rating Approach code which corresponds to the * String supplied. * @throws EncoderException * if the parameter supplied is not of type java.lang.String */ @Override public final Object encode(final Object pObject) throws EncoderException { if (!(pObject instanceof String)) { throw new EncoderException( "Parameter supplied to Match Rating Approach encoder is not of type java.lang.String"); } return encode((String) pObject); }