Example usage for org.apache.commons.codec.binary StringUtils getBytesUtf8

List of usage examples for org.apache.commons.codec.binary StringUtils getBytesUtf8

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary StringUtils getBytesUtf8.

Prototype

public static byte[] getBytesUtf8(final String string) 

Source Link

Document

Encodes the given string into a sequence of bytes using the UTF-8 charset, storing the result into a new byte array.

Usage

From source file:com.smartitengineering.cms.spi.impl.events.EventConsumerTest.java

@Test
public void testSequenceConsumptionWithInvalidMessage() {
    mockery.checking(new Expectations() {

        {/*from   w w w.j av a 2 s .c o m*/
        }
    });
    EventConsumer consumer = injector.getInstance(EventConsumer.class);
    consumer.consume(MSG_TYPE, "SEQUENCE\nCREATE\n"
            + Base64.encodeBase64URLSafeString(StringUtils.getBytesUtf8("random string\nfor test")));
    mockery.assertIsSatisfied();
}

From source file:com.aoppp.gatewaysdk.internal.hw.DigestUtils2.java

/**
 * Calculates the SHA-256 digest and returns the value as a <code>byte[]</code>.
 * <p>//from  www .  java 2 s. c o  m
 * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
 * </p>
 *
 * @param data
 *            Data to digest; converted to bytes using {@link StringUtils#getBytesUtf8(String)}
 * @return SHA-256 digest
 * @since 1.4
 */
public static byte[] sha256(final String data) {
    return sha256(StringUtils.getBytesUtf8(data));
}

From source file:com.ibc.util.BaseNCodec.java

/**
 * Tests a given String to see if it contains only valid characters within the alphabet. 
 * The method treats whitespace and PAD as valid.
 *
 * @param basen String to test/*from w ww.ja va  2s  . c o  m*/
 * @return <code>true</code> if all characters in the String are valid characters in the alphabet or if
 *         the String is empty; <code>false</code>, otherwise
 * @see #isInAlphabet(byte[], boolean)
 */
public boolean isInAlphabet(String basen) {
    return isInAlphabet(StringUtils.getBytesUtf8(basen), true);
}

From source file:com.aoppp.gatewaysdk.internal.hw.DigestUtils2.java

/**
 * Calculates the SHA-384 digest and returns the value as a <code>byte[]</code>.
 * <p>//from w  w w .  j  ava2 s .co m
 * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
 * </p>
 *
 * @param data
 *            Data to digest; converted to bytes using {@link StringUtils#getBytesUtf8(String)}
 * @return SHA-384 digest
 * @since 1.4
 */
public static byte[] sha384(final String data) {
    return sha384(StringUtils.getBytesUtf8(data));
}

From source file:com.yenlo.identity.application.authenticator.custom.BaseNCodec.java

/**
 * Tests a given String to see if it contains only valid characters within the alphabet.
 * The method treats whitespace and PAD as valid.
 *
 * @param basen String to test//from w  w  w. j  av a 2  s  .  c o  m
 * @return <code>true</code> if all characters in the String are valid characters in the alphabet or if
 *         the String is empty; <code>false</code>, otherwise
 * @see #isInAlphabet(byte[], boolean)
 */
public boolean isInAlphabet(final String basen) {
    return isInAlphabet(StringUtils.getBytesUtf8(basen), true);
}

From source file:com.aoppp.gatewaysdk.internal.hw.DigestUtils2.java

/**
 * Calculates the SHA-512 digest and returns the value as a <code>byte[]</code>.
 * <p>/*from   w  w w . j a va2s . com*/
 * Throws a <code>RuntimeException</code> on JRE versions prior to 1.4.0.
 * </p>
 *
 * @param data
 *            Data to digest; converted to bytes using {@link StringUtils#getBytesUtf8(String)}
 * @return SHA-512 digest
 * @since 1.4
 */
public static byte[] sha512(final String data) {
    return sha512(StringUtils.getBytesUtf8(data));
}

From source file:com.smartitengineering.cms.api.impl.content.ContentLoaderImpl.java

public FieldValue getSimpleValueFor(String value, FieldValueType type) {
    final FieldValue result;
    switch (type) {
    case BOOLEAN:
        logger.debug("Getting as boolean");
        MutableBooleanFieldValue booleanFieldValue = createBooleanFieldValue();
        result = booleanFieldValue;/*from  w w w.j  av a2  s. c om*/
        booleanFieldValue.setValue(Boolean.parseBoolean(value));
        break;
    case CONTENT:
        logger.debug("Getting as content");
        MutableContentFieldValue contentFieldValue = createContentFieldValue();
        if (logger.isDebugEnabled()) {
            logger.debug("Content value: " + value);
        }
        try {
            DataInputStream inputStream = new DataInputStream(
                    new ByteArrayInputStream(StringUtils.getBytesUtf8(value)));
            ContentIdImpl idImpl = new ContentIdImpl();
            idImpl.readExternal(inputStream);
            contentFieldValue.setValue(idImpl);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
        result = contentFieldValue;
        break;
    case INTEGER:
        logger.debug("Getting as integer");
        MutableNumberFieldValue integerFieldValue = createIntegerFieldValue();
        integerFieldValue.setValue(NumberUtils.toInt(value, Integer.MIN_VALUE));
        result = integerFieldValue;
        break;
    case DOUBLE:
        logger.debug("Getting as double");
        MutableNumberFieldValue doubleFieldValue = createDoubleFieldValue();
        doubleFieldValue.setValue(NumberUtils.toDouble(value, Double.MIN_VALUE));
        result = doubleFieldValue;
        break;
    case LONG:
        logger.debug("Getting as long");
        MutableNumberFieldValue longFieldValue = createLongFieldValue();
        longFieldValue.setValue(NumberUtils.toLong(value, Long.MIN_VALUE));
        result = longFieldValue;
        break;
    case DATE_TIME:
        logger.debug("Getting as date time");
        MutableDateTimeFieldValue valueOf;
        try {
            valueOf = DateTimeFieldValueImpl.valueOf(value);
        } catch (Exception ex) {
            throw new RuntimeException(ex);
        }
        result = valueOf;
        break;
    case OTHER:
        logger.debug("Getting as other");
        MutableOtherFieldValue otherFieldValue = createOtherFieldValue();
        otherFieldValue.setValue(Base64.decodeBase64(value));
        result = otherFieldValue;
        break;
    case STRING:
    default:
        logger.debug("Getting as else or string");
        MutableStringFieldValue fieldValue = createStringFieldValue();
        fieldValue.setValue(value);
        result = fieldValue;
    }
    return result;
}

From source file:com.ibc.util.Base64.java

/**
 * Tests a given String to see if it contains only valid characters within the Base64 alphabet. Currently the
 * method treats whitespace as valid./*from w  ww  .j  a va 2 s.  co  m*/
 * 
 * @param base64
 *            String to test
 * @return <code>true</code> if all characters in the String are valid characters in the Base64 alphabet or if
 *         the String is empty; <code>false</code>, otherwise
 *  @since 1.5
 */
public static boolean isBase64(String base64) {
    return isBase64(StringUtils.getBytesUtf8(base64));
}

From source file:mvm.rya.indexing.accumulo.temporal.AccumuloTemporalIndexerTest.java

/**
 * Test method for {@link AccumuloTemporalIndexer#storeStatements(java.util.Collection)} .
 *
 * @throws TableExistsException//www  .j  a  v  a2s  .  c om
 * @throws TableNotFoundException
 * @throws AccumuloSecurityException
 * @throws AccumuloException
 * @throws IOException
 * @throws IllegalArgumentException
 * @throws NoSuchAlgorithmException
 */
@Test
public void testStoreStatements() throws AccumuloException, AccumuloSecurityException, TableNotFoundException,
        TableExistsException, IllegalArgumentException, IOException, NoSuchAlgorithmException {
    long valueHash = 0;
    Collection<Statement> statements = new ArrayList<Statement>(70);
    statements.addAll(Arrays.asList(seriesSpo));
    int rowsStoredExpected = statements.size() * 4; // instants store 4 each
    // hash the expected output:
    for (Statement statement : statements) {
        valueHash = hasher(valueHash, StringUtils.getBytesUtf8(StatementSerializer.writeStatement(statement)));
        valueHash = hasher(valueHash, StringUtils.getBytesUtf8(StatementSerializer.writeStatement(statement)));
        valueHash = hasher(valueHash, StringUtils.getBytesUtf8(StatementSerializer.writeStatement(statement)));
        valueHash = hasher(valueHash, StringUtils.getBytesUtf8(StatementSerializer.writeStatement(statement)));
    }
    statements.add(spo_B02_E30);
    rowsStoredExpected += 2; // intervals store two dates
    statements.add(spo_B30_E32);
    rowsStoredExpected += 2; // intervals store two dates
    valueHash = hasher(valueHash, StringUtils.getBytesUtf8(StatementSerializer.writeStatement(spo_B02_E30)));
    valueHash = hasher(valueHash, StringUtils.getBytesUtf8(StatementSerializer.writeStatement(spo_B02_E30)));
    valueHash = hasher(valueHash, StringUtils.getBytesUtf8(StatementSerializer.writeStatement(spo_B30_E32)));
    valueHash = hasher(valueHash, StringUtils.getBytesUtf8(StatementSerializer.writeStatement(spo_B30_E32)));
    // duplicates will overwrite old ones, no change in the output except timestamps
    statements.add(spo_B30_E32);
    statements.add(spo_B30_E32);

    List<RyaStatement> ryaStatements = Lists.newArrayList();
    for (Statement s : statements) {
        ryaStatements.add(convertStatement(s));
    }
    tIndexer.storeStatements(ryaStatements);

    Map<String, Long> statistics = new HashMap<String, Long>();
    int rowsStoredActual = printTables("junit testing: StoreStatements multiple statements", null, statistics);
    Assert.assertEquals("Number of rows stored.", rowsStoredExpected, rowsStoredActual); // 4 index entries per statement
    Assert.assertEquals("value hash.", valueHash, statistics.get(STAT_VALUEHASH).longValue());
}

From source file:com.smartitengineering.cms.api.impl.content.ContentLoaderImpl.java

@Override
public ContentId generateContentId(WorkspaceId workspaceId) {
    UUID uid = UUID.randomUUID();
    return createContentId(workspaceId, StringUtils.getBytesUtf8(uid.toString()));
}