Search in sources :

Example 1 with SimpleByteTranslator

use of com.adaptris.util.text.SimpleByteTranslator in project interlok by adaptris.

the class HexSequenceConfiguredReplacementSource method obtainValue.

public String obtainValue(AdaptrisMessage msg) throws ServiceException {
    String result = null;
    ByteTranslator hexToBytes = new HexStringByteTranslator();
    ByteTranslator bytesToString = new SimpleByteTranslator();
    if (!isEmpty(charset)) {
        bytesToString = new CharsetByteTranslator(charset);
    }
    try {
        result = bytesToString.translate(hexToBytes.translate(this.getValue()));
    } catch (Exception e) {
        throw new ServiceException(e);
    }
    return result;
}
Also used : ServiceException(com.adaptris.core.ServiceException) ByteTranslator(com.adaptris.util.text.ByteTranslator) HexStringByteTranslator(com.adaptris.util.text.HexStringByteTranslator) SimpleByteTranslator(com.adaptris.util.text.SimpleByteTranslator) CharsetByteTranslator(com.adaptris.util.text.CharsetByteTranslator) CharsetByteTranslator(com.adaptris.util.text.CharsetByteTranslator) HexStringByteTranslator(com.adaptris.util.text.HexStringByteTranslator) SimpleByteTranslator(com.adaptris.util.text.SimpleByteTranslator) ServiceException(com.adaptris.core.ServiceException)

Example 2 with SimpleByteTranslator

use of com.adaptris.util.text.SimpleByteTranslator in project interlok by adaptris.

the class ByteArrayMetadataTest method testWrapString.

@Test
public void testWrapString() throws Exception {
    AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
    msg.addMetadata(KEY, HELLO_WORLD);
    byte[] wrapped = new ByteArrayFromMetadata().withTranslator(new SimpleByteTranslator()).withKey(KEY).wrap(msg);
    assertTrue(MessageDigest.isEqual(BYTE_ARRAY, wrapped));
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SimpleByteTranslator(com.adaptris.util.text.SimpleByteTranslator) Test(org.junit.Test)

Aggregations

SimpleByteTranslator (com.adaptris.util.text.SimpleByteTranslator)2 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)1 ServiceException (com.adaptris.core.ServiceException)1 ByteTranslator (com.adaptris.util.text.ByteTranslator)1 CharsetByteTranslator (com.adaptris.util.text.CharsetByteTranslator)1 HexStringByteTranslator (com.adaptris.util.text.HexStringByteTranslator)1 Test (org.junit.Test)1