/** * Encode the input data producing a URL safe base 64 encoded byte array. * * @return a byte array containing the URL safe base 64 encoded data. */ public static byte[] encode( byte[] data) { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); try { encoder.encode(data, 0, data.length, bOut); } catch (Exception e) { throw new EncoderException("exception encoding URL safe base64 data: " + e.getMessage(), e); } return bOut.toByteArray(); }
/** * encode the input data producing a Hex encoded byte array. * * @return a byte array containing the Hex encoded data. */ public static byte[] encode( byte[] data, int off, int length) { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); try { encoder.encode(data, off, length, bOut); } catch (Exception e) { throw new EncoderException("exception encoding Hex string: " + e.getMessage(), e); } return bOut.toByteArray(); }
/** * encode the input data producing a base 64 encoded byte array. * * @return a byte array containing the base 64 encoded data. */ public static byte[] encode( byte[] data, int off, int length) { int len = (length + 2) / 3 * 4; ByteArrayOutputStream bOut = new ByteArrayOutputStream(len); try { encoder.encode(data, off, length, bOut); } catch (Exception e) { throw new EncoderException("exception encoding base64 string: " + e.getMessage(), e); } return bOut.toByteArray(); }