/** * 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
/** * Decodes the first four bytes of array <var>fourBytes</var> and returns * an array up to three bytes long with the decoded values. * * @param fourBytes * the array with Base64 content * @return array with decoded values * @since 1.3 */ private static byte[] decode4to3(byte[] fourBytes) { byte[] outBuff1 = new byte[3]; int count = decode4to3(fourBytes, 0, outBuff1, 0); byte[] outBuff2 = new byte[count]; for (int i = 0; i < count; i++) outBuff2[i] = outBuff1[i]; return outBuff2; }
/** * Encodes the first three bytes of array <var>threeBytes</var> and returns * a four-byte array in Base64 notation. * * @param threeBytes * the array to convert * @return four byte array in Base64 notation. * @since 1.3 */ private static byte[] encode3to4(byte[] threeBytes) { return encode3to4(threeBytes, 3); } // end encodeToBytes
public Map execute(Map inputs) throws TaskExecutionException { Map results = new HashMap(); Object data = ((DataThing)inputs.get("base64")).getDataObject(); String base64; if (String.class.isAssignableFrom(data.getClass())) { base64 = (String) ((DataThing) inputs.get("base64")).getDataObject(); } else { throw new TaskExecutionException("Input data cannot be assigned to a String, so is not a base64 encoding. Its type is:"+data.getClass().getName()); } byte[] bytes = Base64.decode(base64); results.put("bytes", new DataThing(bytes)); return results; }
/** * 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
byte[] objBytes = decode(encodedObject);
/** * 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
bytes = decode(bytes, 0, bytes.length);
/** * 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>. * * @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.3 */ private static byte[] encode3to4(byte[] threeBytes, int numSigBytes) { byte[] dest = new byte[4]; encode3to4(threeBytes, 0, numSigBytes, dest, 0); return dest; }
b4[b4Posn++] = sbiCrop; if (b4Posn > 3) { outBuffPosn += decode4to3(b4, 0, outBuff, outBuffPosn); b4Posn = 0;
/** * 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
result.put(child.getName(), new DataThing(xmlText)); } else if (outputTypes[i].equals("'application/octet-stream'")) { // base64Binary byte[] data = Base64.decode(child.getText()); result.put(child.getName(), DataThingFactory.bake(data)); } else if (outputTypes[i].equals("l('text/plain')")) { // an inner element containing a list
/** * 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
public Map execute(Map inputs) throws TaskExecutionException { Map results = new HashMap(); byte[] bytes = (byte[]) ((DataThing) inputs.get("bytes")).getDataObject(); String base64 = Base64.encodeBytes(bytes); results.put("base64", new DataThing(base64)); return results; }
String encodedData = e.getChild("dataElementData", namespace) .getTextTrim(); byte[] decodedData = Base64.decode(encodedData); Object result; if (mimeMajorType.equals("text")) {
int lineLength = 0; for (; d < len2; d += 3, e += 4) { encode3to4(source, d + off, 3, outBuff, e); encode3to4(source, d + off, len - d, outBuff, e); e += 4;
realDataElement.setText(Base64.encodeBytes(theBytes)); dataElement.addContent(realDataElement); return dataElement;
private Element buildElementFromObject(String key, Object dataObject) throws JDOMException, IOException { Element dataElement = null; if (isXMLInput(key)) { dataElement = createDataElementForXMLInput(dataObject, key); } else { dataElement = new Element(key); setDataElementNamespace(key, dataElement); if (dataObject.toString().equals("nil")) { dataElement.setAttribute("nil", "true"); // changes nil value // to nil=true // attribute. } else { if (dataObject instanceof byte[]) { dataElement .setAttribute( "type", "xsd:base64Binary", org.jdom.Namespace .getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance")); dataObject = Base64.encodeBytes((byte[]) dataObject); } dataElement.setText(dataObject.toString()); } } return dataElement; }