/** * Decodes an Object using the base64 algorithm. This method is provided in order to satisfy the * requirements of the Decoder interface, and will throw a DecoderException if the supplied * object is not of type byte[]. * * @param pObject * Object to decode * @return An object (of type byte[]) containing the binary data which corresponds to the byte[] * supplied. * @throws IllegalArgumentException * if the parameter supplied is not of type byte[] */ public Object decode(Object pObject) { if (!(pObject instanceof byte[])) { throw new IllegalArgumentException( "Parameter supplied to Base64 decode is not a byte[]"); } return decode((byte[])pObject); }
/** * Decodes an Object using the base64 algorithm. This method is provided in order to satisfy the * requirements of the Decoder interface, and will throw a DecoderException if the supplied * object is not of type byte[]. * * @param pObject * Object to decode * @return An object (of type byte[]) containing the binary data which corresponds to the byte[] * supplied. * @throws IllegalArgumentException * if the parameter supplied is not of type byte[] */ public Object decode(Object pObject) { if (!(pObject instanceof byte[])) { throw new IllegalArgumentException( "Parameter supplied to Base64 decode is not a byte[]"); } return decode((byte[])pObject); }
/** * Decodes a String containing containing characters in the Base64 alphabet. * * @param pArray * A String containing Base64 character data * @return a byte array containing binary data * @since 1.4 */ public byte[] decode(final String pArray) { return decode(StringUtils.getBytesUtf8(pArray)); }
/** * Decodes a Base64 String into octets * * @param base64String * String containing Base64 data * @return Array containing decoded data. * @since 1.4 */ public static byte[] decodeBase64(final String base64String) { return new Base64().decode(base64String); }
/** * Decodes Base64 data into octets * * @param base64Data * Byte array containing Base64 data * @return Array containing decoded data. */ public static byte[] decodeBase64(final byte[] base64Data) { return new Base64().decode(base64Data); }
/** * Decodes a byte[] containing containing characters in the Base64 alphabet. * * @param pArray * A byte array containing Base64 character data * @return a byte array containing binary data */ public byte[] decode(final byte[] pArray) { reset(); if ((pArray == null) || (pArray.length == 0)) { return pArray; } long len = Math.max(1, (pArray.length * 3) / 4); byte[] buf = new byte[(int)len]; setInitialBuffer(buf, 0, buf.length); decode(pArray, 0, pArray.length); decode(pArray, 0, -1); // Notify decoder of EOF. // Would be nice to just return buf (like we sometimes do in the encode // logic), but we have no idea what the line-length was (could even be // variable). So we cannot determine ahead of time exactly how big an // array is necessary. Hence the need to construct a 2nd byte array to // hold the final result: byte[] result = new byte[pos]; readResults(result, 0, result.length); return result; }