/** * Encodes a byte array into Base64 notation. Does not GZip-compress data. * * @param source * The data to convert * @since 1.4 */ public static String encodeBytes(final byte[] source) { return encodeBytes(source, 0, source.length, NO_OPTIONS); } // end encodeBytes
/** * Encodes a byte array into Base64 notation. Does not GZip-compress data. * * @param source * The data to convert * @since 1.4 */ public static String encodeBytes(final byte[] source) { return encodeBytes(source, 0, source.length, NO_OPTIONS); } // end encodeBytes
/** * Encodes a byte array into Base64 notation. Does not GZip-compress data. * * @param source * The data to convert * @since 1.4 */ public static String encodeBytes(byte[] source) { return encodeBytes(source, 0, source.length, NO_OPTIONS); } // end encodeBytes
/** * Encodes a byte array into Base64 notation. Does not GZip-compress data. * * @param source * The data to convert * @param off * Offset in array where conversion should begin * @param len * Length of data to convert * @since 1.4 */ public static String encodeBytes(final byte[] source, final int off, final int len) { return encodeBytes(source, off, len, NO_OPTIONS); } // end encodeBytes
/** * Encodes a byte array into Base64 notation. Does not GZip-compress data. * * @param source * The data to convert * @param off * Offset in array where conversion should begin * @param len * Length of data to convert * @since 1.4 */ public static String encodeBytes(final byte[] source, final int off, final int len) { return encodeBytes(source, off, len, NO_OPTIONS); } // end encodeBytes
/** * Encodes a byte array into Base64 notation. Does not GZip-compress data. * * @param source * The data to convert * @param off * Offset in array where conversion should begin * @param len * Length of data to convert * @since 1.4 */ public static String encodeBytes(byte[] source, int off, int len) { return encodeBytes(source, off, len, NO_OPTIONS); } // end encodeBytes
/** * Encodes a byte array into Base64 notation. * <p> * Valid options: * * <pre> * GZIP: gzip-compresses object before encoding it. * DONT_BREAK_LINES: don't break lines at 76 characters * <i>Note: Technically, this makes your encoding non-compliant.</i> * </pre> * * <p> * Example: <code>encodeBytes( myData, Base64.GZIP )</code> or * <p> * Example: * <code>encodeBytes( myData, Base64.GZIP | Base64.DONT_BREAK_LINES )</code> * * * @param source * The data to convert * @param options * Specified options * @see Base64#GZIP * @see Base64#DONT_BREAK_LINES * @since 2.0 */ public static String encodeBytes(byte[] source, int options) { return encodeBytes(source, 0, source.length, options); } // end encodeBytes
/** * Encodes a byte array into Base64 notation. * <p> * Valid options: * * <pre> * GZIP: gzip-compresses object before encoding it. * DONT_BREAK_LINES: don't break lines at 76 characters * <i>Note: Technically, this makes your encoding non-compliant.</i> * </pre> * * <p> * Example: <code>encodeBytes( myData, Base64.GZIP )</code> or * <p> * Example: <code>encodeBytes( myData, Base64.GZIP | Base64.DONT_BREAK_LINES )</code> * * * @param source * The data to convert * @param options * Specified options * @see Base64#GZIP * @see Base64#DONT_BREAK_LINES * @since 2.0 */ public static String encodeBytes(final byte[] source, final int options) { return encodeBytes(source, 0, source.length, options); } // end encodeBytes
/** * Encodes a byte array into Base64 notation. * <p> * Valid options: * * <pre> * GZIP: gzip-compresses object before encoding it. * DONT_BREAK_LINES: don't break lines at 76 characters * <i>Note: Technically, this makes your encoding non-compliant.</i> * </pre> * * <p> * Example: <code>encodeBytes( myData, Base64.GZIP )</code> or * <p> * Example: <code>encodeBytes( myData, Base64.GZIP | Base64.DONT_BREAK_LINES )</code> * * * @param source * The data to convert * @param options * Specified options * @see Base64#GZIP * @see Base64#DONT_BREAK_LINES * @since 2.0 */ public static String encodeBytes(final byte[] source, final int options) { return encodeBytes(source, 0, source.length, options); } // end encodeBytes
public static String fragmentAndBase64Encode(final byte[] bytes) throws IOException { final StringBuilder encodedString = new StringBuilder(); final int bytesFragmentLength = BASE64_BYTES_FRAGMENT_LENGTH; int nbFragment = bytes.length / bytesFragmentLength; final int remainingBytes = bytes.length % bytesFragmentLength; if (remainingBytes > 0) { nbFragment++; } int bytesPosition = 0; for (int nbFragmentsProcessed = 0; nbFragmentsProcessed < nbFragment; nbFragmentsProcessed++) { ByteArrayOutputStream byteArrayOutputStream = null; if (nbFragmentsProcessed + 1 < nbFragment) { byteArrayOutputStream = new ByteArrayOutputStream(bytesFragmentLength); byteArrayOutputStream.write(bytes, bytesPosition, bytesFragmentLength); } else { byteArrayOutputStream = new ByteArrayOutputStream(remainingBytes); byteArrayOutputStream.write(bytes, bytesPosition, remainingBytes); } final String stringFragment = Base64.encodeBytes(byteArrayOutputStream.toByteArray()); if (bytesPosition != 0) { encodedString.append(BASE64_BYTES_FRAGMENT_SEPARATOR); } encodedString.append(stringFragment); byteArrayOutputStream.close(); bytesPosition += bytesFragmentLength; } return encodedString.toString(); }
public static String fragmentAndBase64Encode(final byte[] bytes) throws IOException { final StringBuilder encodedString = new StringBuilder(); final int bytesFragmentLength = BASE64_BYTES_FRAGMENT_LENGTH; int nbFragment = bytes.length / bytesFragmentLength; final int remainingBytes = bytes.length % bytesFragmentLength; if (remainingBytes > 0) { nbFragment++; } int bytesPosition = 0; for (int nbFragmentsProcessed = 0; nbFragmentsProcessed < nbFragment; nbFragmentsProcessed++) { ByteArrayOutputStream byteArrayOutputStream = null; if (nbFragmentsProcessed + 1 < nbFragment) { byteArrayOutputStream = new ByteArrayOutputStream(bytesFragmentLength); byteArrayOutputStream.write(bytes, bytesPosition, bytesFragmentLength); } else { byteArrayOutputStream = new ByteArrayOutputStream(remainingBytes); byteArrayOutputStream.write(bytes, bytesPosition, remainingBytes); } final String stringFragment = Base64.encodeBytes(byteArrayOutputStream.toByteArray()); if (bytesPosition != 0) { encodedString.append(BASE64_BYTES_FRAGMENT_SEPARATOR); } encodedString.append(stringFragment); byteArrayOutputStream.close(); bytesPosition += bytesFragmentLength; } return encodedString.toString(); }
if (userName != null && !userName.trim().equals("")) { final String passWord = optionsMap.get(APIAccessor.PASSWORD_HASH_OPTION); final String encodedUserAndPswd = Base64.encodeBytes((userName + ":" + passWord).getBytes()); request.getHeaders().add(AUTHORIZATION_PROPERTY, AUTHENTICATION_SCHEME + " " + encodedUserAndPswd);
if (userName != null && !userName.trim().equals("")) { final String passWord = optionsMap.get(APIAccessor.PASSWORD_HASH_OPTION); final String encodedUserAndPswd = Base64.encodeBytes((userName + ":" + passWord).getBytes()); request.getHeaders().add(AUTHORIZATION_PROPERTY, AUTHENTICATION_SCHEME + " " + encodedUserAndPswd);