/** * Converts base64Binary value into byte array. */ public static byte[] unmarshalBase64(String value) { byte[] valueBytes; try { valueBytes = value.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { valueBytes = value.getBytes(); } return Base64.decode(valueBytes, 0, valueBytes.length); }
/** * Encodes a byte array into Base64 notation. * Does not GZip-compress data. * * @param source The data to convert * @return the encode bytes * @since 1.4 */ public static String encodeBytes(byte[] source) { return encodeBytes(source, 0, source.length, NO_OPTIONS); } // end encodeBytes
/** * Encodes up to the first three bytes of array <var>threeBytes</var> * and returns a four-byte array in Base64 notation. * The actual number of significant bytes in your array is * given by <var>numSigBytes</var>. * The array <var>threeBytes</var> needs only be as big as * <var>numSigBytes</var>. * Code can reuse a byte array by passing a four-byte array as <var>b4</var>. * * @param b4 A reusable byte array to reduce array instantiation * @param threeBytes the array to convert * @param numSigBytes the number of significant bytes in your array * @return four byte array in Base64 notation. * @since 1.5.1 */ private static byte[] encode3to4(byte[] b4, byte[] threeBytes, int numSigBytes) { encode3to4(threeBytes, 0, numSigBytes, b4, 0); return b4; } // end encode3to4
/** * Serializes an object and returns the Base64-encoded * version of that serialized object. If the object * cannot be serialized or there is another error, * the method will return <tt>null</tt>. * The object is not GZip-compressed before being encoded. * * @param serializableObject The object to encode * @return The Base64-encoded object * @since 1.4 */ public static String encodeObject(java.io.Serializable serializableObject) { return encodeObject(serializableObject, NO_OPTIONS); } // end encodeObject
if (b4Posn > 3) outBuffPosn += decode4to3(b4, 0, outBuff, outBuffPosn); b4Posn = 0;
/** * Converts byte array into a base64Binary value. */ public static String marshalBase64(byte[] value) { return Base64.encodeBytes(value); }
private static ActivityHandle StringToHandle(String base64) { ActivityHandle activityHandle = null; try { byte[] bytes = Base64.decode(base64); final ByteArrayInputStream bais = new ByteArrayInputStream(bytes); //final JBossObjectInputStream jbois = new JBossObjectInputStream(bais); final ObjectInputStream ois = new ObjectInputStream(bais); activityHandle = (ActivityHandle) ois.readObject(); } catch (Exception e) { e.printStackTrace(); } return activityHandle; }
for (; d < len2; d += 3, e += 4) encode3to4(source, d + off, 3, outBuff, e); encode3to4(source, d + off, len - d, outBuff, e); e += 4;
/** * 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 * @return the text node * @since 1.4 */ public static String encodeBytes(byte[] source, int off, int len) { return encodeBytes(source, off, len, NO_OPTIONS); } // end encodeBytes
/** * Get the user name and password passed in the basic authentication header. * @param request the http servlet request * @return user name and password, or null if not found. If there is no password, * the result may contain only one element, or two elements and the second element is null or empty. */ static public String[] getBasicAuthUsernameAndPassword(HttpServletRequest request){ String authorization = request.getHeader("Authorization"); if (authorization != null && authorization.startsWith("Basic")) { try{ // Authorization: Basic base64credentials String base64Credentials = authorization.substring("Basic".length()).trim(); String credentials = new String(Base64.decode(base64Credentials), "UTF-8"); // credentials = username:password String[] values = StringUtils.split(credentials, ':'); return values; }catch(Exception e){ // ignore } } return null; }
/** * 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 * @return the encoded bytes * @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
byte[] objBytes = decode(encodedObject);
private static String getBasicAuthHeader(String username, String password) throws IOException { return "Basic " + new String(Base64.encodeBytes((username + ":" + password).getBytes("ISO-8859-1"), Base64.DONT_BREAK_LINES)); }
bytes = decode(bytes, 0, bytes.length);
@Override public String call() throws IOException { final HttpURLConnection conn = (HttpURLConnection) url.openConnection(); if (username != null) { final String userpassword = username + ":" + password; final String basicAuthorization = Base64.encodeBytes(userpassword.getBytes()); conn.setRequestProperty("Authorization", "Basic " + basicAuthorization); } conn.setDoInput(true); return processResponse(conn); } };
byte[] decodedPath = Base64.decode(encodedPath);
private static String handleToString(ActivityHandle ah) { String base64 = null; try { byte[] bytes = null; // need to marshall the handle, but this happens at most once per AS instance int bufferSize = 1024; final ByteArrayOutputStream baos = new ByteArrayOutputStream(bufferSize); //final JBossObjectOutputStream jboos = new JBossObjectOutputStream(baos); final ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(ah); bytes = baos.toByteArray(); base64 = Base64.encodeBytes(bytes); oos.close(); } catch (Exception e) { e.printStackTrace(); } return base64; }
raw = Base64.decode(bytes, 0, bytes.length);
buffer.append(password); String encoded = Base64.encodeBytes(buffer.toString().getBytes());
byte[] jbossBytes = org.jboss.util.Base64.decode(base64Str); if (print) { System.out.println("JBoss: " + toString(jbossBytes));