/** * Decodes the HEX input data producing a output stream. * * @param data Input data to be decoded. * @return A byte array representing the decoded input data. */ public static byte[] decode(final String data) { try { final ByteArrayOutputStream out = new ByteArrayOutputStream(); decode(data, out); out.close(); return out.toByteArray(); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e.getMessage(), e); } }
/** * Encodes the input data producing a Hex output stream. * * @param data Input data to encode. * @return the number of bytes produced. */ public static String encode(final byte[] data) { try { final ByteArrayOutputStream out = new ByteArrayOutputStream(); encode(data, 0, data.length, out); out.close(); return new String(out.toByteArray()); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e.getMessage(), e); } }
/** * Decode binary data and return decoded value. * * @param descriptor {@link XMLFieldDescriptor} instance for the field whose value requires * decoding. * @param binaryData The binary data value to be decoded * @return Decode data. */ byte[] decodeBinaryData(final XMLFieldDescriptor descriptor, final String binaryData) { // -- Base64/HexBinary decoding byte[] decodedValue; if ((descriptor.isMultivalued() && HexDecoder.DATA_TYPE.equals(descriptor.getComponentType())) || HexDecoder.DATA_TYPE.equals(descriptor.getSchemaType())) { decodedValue = HexDecoder.decode(binaryData); } else { decodedValue = Base64Decoder.decode(binaryData); } return decodedValue; }
/** * Encode binary data. * * @param valueToEncode The binary data to encode. * @param componentType The XML schema component type. * @return Encoded binary data in {@link String} form. */ private Object encodeBinaryData(final Object valueToEncode, final String componentType) { String encodedValue; if (HexDecoder.DATA_TYPE.equals(componentType)) { encodedValue = HexDecoder.encode((byte[]) valueToEncode); } else { encodedValue = new String(Base64Encoder.encode((byte[]) valueToEncode)); } return encodedValue; }
value = HexDecoder.decode(attValue); } else { value = Base64Decoder.decode(attValue);
chars = new String(HexDecoder.encode((byte[]) obj)).toCharArray(); } else { chars = Base64Encoder.encode((byte[]) obj); if ((descriptor.isMultivalued() && HexDecoder.DATA_TYPE.equals(componentType)) || HexDecoder.DATA_TYPE.equals(schemaType)) { chars = new String(HexDecoder.encode((byte[]) object)).toCharArray(); } else { chars = Base64Encoder.encode((byte[]) object);