Java Code Examples for org.apache.commons.codec.binary.StringUtils#getBytesUtf8()

The following examples show how to use org.apache.commons.codec.binary.StringUtils#getBytesUtf8() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StringEncodeUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenSomeUnencodedString_whenApacheCommonsCodecEncode_thenCompareEquals() {
    String rawString = "Entwickeln Sie mit Vergnügen";
    byte[] bytes = StringUtils.getBytesUtf8(rawString);

    String utf8EncodedString = StringUtils.newStringUtf8(bytes);

    assertEquals(rawString, utf8EncodedString);
}
 
Example 2
Source File: AtlasNotificationBaseMessage.java    From atlas with Apache License 2.0 4 votes vote down vote up
public static byte[] getBytesUtf8(String str) {
    return StringUtils.getBytesUtf8(str);
}
 
Example 3
Source File: KeyParts.java    From rya with Apache License 2.0 4 votes vote down vote up
private static void appendPredicate(final Statement statement, final Text keyText) {
       final Value statementValue = new Value(StringUtils.getBytesUtf8(StatementSerializer.writePredicate(statement)));
       final byte[] hashOfValue = uniqueFromValueForKey(statementValue);
       appendBytes(HASH_PREFIX, keyText); // prefix the hash with a zero byte.
       appendBytes(hashOfValue, keyText);
}
 
Example 4
Source File: KeyParts.java    From rya with Apache License 2.0 4 votes vote down vote up
private static void appendSubjectPredicate(final Statement statement, final Text keyText) {
       final Value statementValue = new Value(StringUtils.getBytesUtf8(StatementSerializer.writeSubjectPredicate(statement)));
       final byte[] hashOfValue = uniqueFromValueForKey(statementValue);
       appendBytes(HASH_PREFIX, keyText); // prefix the hash with a zero byte.
       appendBytes(hashOfValue, keyText);
}
 
Example 5
Source File: TemporalInstantRfc3339.java    From rya with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] getAsKeyBytes() {
    return StringUtils.getBytesUtf8(getAsKeyString());
}
 
Example 6
Source File: IFunctionsTest.java    From ews-java-api with MIT License 4 votes vote down vote up
@Test
public void testBase64Encoder() {
  final byte[] value = StringUtils.getBytesUtf8("123");
  final IFunctions.Base64Encoder f = IFunctions.Base64Encoder.INSTANCE;
  Assert.assertEquals(Base64.encodeBase64String(value), f.func(value));
}
 
Example 7
Source File: KeyParts.java    From rya with Apache License 2.0 3 votes vote down vote up
/**
 * Get a collision unlikely hash string and append to the key,
 * so that if two keys have the same value, then they will be the same,
 * if two different values that occur at the same time there keys are different.
 * If the application uses a very large number of statements at the exact same time,
 * the md5 value might be upgraded to for example sha-1 to avoid collisions.
 * @param statement
 * @param keyText
 */
public static void appendUniqueness(final Statement statement, final Text keyText) {
    keyText.append(HASH_PREFIX, 0, 1);   // delimiter
    final Value statementValue = new Value(StringUtils.getBytesUtf8(StatementSerializer.writeStatement(statement)));
    final byte[] hashOfValue = Md5Hash.md5Binary(statementValue);
    keyText.append(hashOfValue, 0, hashOfValue.length);
}
 
Example 8
Source File: HmacUtils.java    From text_converter with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates an instance using the provided algorithm type.
 *
 * @param algorithm to use
 * @param  key the key to use
 * @throws IllegalArgumentException
 *             when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid.
 * @since 1.11
 */
public HmacUtils(final String algorithm, final String key) {
    this(algorithm, StringUtils.getBytesUtf8(key));
}
 
Example 9
Source File: HmacUtils.java    From text_converter with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates an instance using the provided algorithm type.
 *
 * @param algorithm to use
 * @param  key the key to use
 * @throws IllegalArgumentException
 *             when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid.
 * @since 1.11
 */
public HmacUtils(final HmacAlgorithms algorithm, final String key) {
    this(algorithm.getName(), StringUtils.getBytesUtf8(key));
}
 
Example 10
Source File: HmacUtils.java    From pivaa with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates an instance using the provided algorithm type.
 *
 * @param algorithm to use
 * @param  key the key to use
 * @throws IllegalArgumentException
 *             when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid.
 * @since 1.11
 */
public HmacUtils(final String algorithm, final String key) {
    this(algorithm, StringUtils.getBytesUtf8(key));
}
 
Example 11
Source File: HmacUtils.java    From pivaa with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Creates an instance using the provided algorithm type.
 *
 * @param algorithm to use
 * @param  key the key to use
 * @throws IllegalArgumentException
 *             when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid.
 * @since 1.11
 */
public HmacUtils(final HmacAlgorithms algorithm, final String key) {
    this(algorithm.getName(), StringUtils.getBytesUtf8(key));
}
 
Example 12
Source File: JsonUtil.java    From cm_ext with Apache License 2.0 2 votes vote down vote up
/**
 * Serializes 'data' into a UTF8 byte array.
 * @param data
 * @return
 */
public static byte[] valueAsBytes(Object data) {
  return StringUtils.getBytesUtf8(valueAsString(data));
}