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.app.framework.utilities.map.BaseNCodec.java

/**
 * Decodes a String containing characters in the Base-N alphabet.
 *
 * @param pArray A String containing Base-N character data
 * @return a byte array containing binary data
 *///from w w w  .  j a v a2  s.  com
public byte[] decode(final String pArray) {
    return decode(StringUtils.getBytesUtf8(pArray));
}

From source file:mvm.rya.indexing.KeyParts.java

/**
* 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/* w w w  .  j av  a2 s  .c  o m*/
* @param keyText
*/
public static void appendUniqueness(Statement statement, Text keyText) {
    keyText.append(HASH_PREFIX, 0, 1); // delimiter
    Value statementValue = new Value(StringUtils.getBytesUtf8(StatementSerializer.writeStatement(statement)));
    byte[] hashOfValue = Md5Hash.md5Binary(statementValue);
    keyText.append(hashOfValue, 0, hashOfValue.length);
}

From source file:dashboard.ImportCDN.java

public static int postCDNEventToMixpanel(String ip, String eventName, String eventTime, String method,
        String fileName, String fName, String userAgent, String statusCode) throws IOException {

    try {//from   w w  w .  j a va2  s  . c om
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = sdf.parse(eventTime);
        long timeInSecSinceEpoch = date.getTime();
        if (timeInSecSinceEpoch > 0)
            timeInSecSinceEpoch = timeInSecSinceEpoch / 1000;

        JSONObject obj1 = new JSONObject();
        obj1.put("distinct_id", ip);
        obj1.put("ip", ip);
        obj1.put("File path", fileName);
        obj1.put("File name", fName);
        obj1.put("User agent", userAgent);
        obj1.put("Status code", statusCode);
        obj1.put("Method", method);
        obj1.put("time", timeInSecSinceEpoch);
        obj1.put("token", TOKEN);

        JSONObject obj2 = new JSONObject();
        obj2.put("event", eventName);
        obj2.put("properties", obj1);

        String s2 = obj2.toString();
        String encodedJSON = Base64.encodeBase64String(StringUtils.getBytesUtf8(s2));

        return postRequest("http://api.mixpanel.com/import", "data", encodedJSON, "api_key", API_KEY);
    } catch (Exception e) {
        //throw new RuntimeException("Can't POST to Mixpanel.", e);
        //e.printStackTrace();
        System.out.println("Exception in postCDNEventToMixpanel");
        return 0;
    }
}

From source file:com.smartitengineering.cms.spi.impl.content.search.ContentHelper.java

@Override
protected Content convertFromT2F(MultivalueMap<String, Object> toBean) {
    try {//from w  w w .  ja va2  s  .  c  o m
        byte[] contentId = StringUtils.getBytesUtf8(toBean.getFirst(SolrFieldNames.ID).toString());
        ContentId id = contentLoader.getFromByteArray(contentId);
        return SmartContentAPI.getInstance().getContentLoader().loadContent(id);
    } catch (Exception ex) {
        logger.error("Error converting to content, returning null!", ex);
    }
    return null;
}

From source file:kr.debop4j.core.tools.StringTool.java

/**
 * Get utf 8 bytes./*from   w  ww  . ja  va 2 s  . c om*/
 *
 * @param str ?
 * @return the byte [ ]
 */
public static byte[] getUtf8Bytes(final String str) {
    return StringUtils.getBytesUtf8(str);
}

From source file:com.metamx.milano.proto.MilanoTool.java

private MilanoTool(String base64) {
    if (base64 == null) {
        throw new IllegalStateException("Received null base64 data");
    }//  w  ww.  j ava 2s .  co  m
    this.base64 = base64;
    try {
        this.typeMetadata = MilanoTypeMetadata.TypeMetadata
                .parseFrom(Base64.decodeBase64(StringUtils.getBytesUtf8(this.base64)));
    } catch (InvalidProtocolBufferException e) {
        throw Throwables.propagate(e);
    }

    initializeDescriptors();
    log.debug("Created with Base64 String");
}

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

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

        {//  ww  w .  j a  v  a 2s  . co  m
        }
    });
    EventConsumer consumer = injector.getInstance(EventConsumer.class);
    consumer.consume(MSG_TYPE, "CONTENT_TYPE\nCREATE\n" + Base64
            .encodeBase64URLSafeString(StringUtils.getBytesUtf8("random string\nfor test\nof content type")));
    mockery.assertIsSatisfied();
}

From source file:com.netflix.astyanax.AbstractColumnListMutation.java

@Override
public ColumnListMutation<C> putCompressedColumn(C columnName, String value, Integer ttl) {
    Preconditions.checkNotNull(value, "Can't insert null value");

    if (value == null) {
        putEmptyColumn(columnName, ttl);
        return this;
    }//from w  ww. ja v  a 2s.  com

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    GZIPOutputStream gzip;
    try {
        gzip = new GZIPOutputStream(out);
        gzip.write(StringUtils.getBytesUtf8(value));
        gzip.close();
        return this.putColumn(columnName, ByteBuffer.wrap(out.toByteArray()), ttl);
    } catch (IOException e) {
        throw new RuntimeException("Error compressing column " + columnName, e);
    }
}

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

/**
 * Calculates the SHA-1 digest and returns the value as a <code>byte[]</code>.
 *
 * @param data/*from  w  w  w  .j  a v a 2s.co  m*/
 *            Data to digest; converted to bytes using {@link StringUtils#getBytesUtf8(String)}
 * @return SHA-1 digest
 */
public static byte[] sha1(final String data) {
    return sha1(StringUtils.getBytesUtf8(data));
}

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

/**
 * Index a new interval//  ww  w .  j av  a2 s. c  om
 * TODO: integrate into KeyParts (or eliminate)
 * @param writer
 * @param cv
 * @param interval
 * @throws MutationsRejectedException
 */
public void addInterval(BatchWriter writer, TemporalInterval interval, Statement statement)
        throws MutationsRejectedException {

    Value statementValue = new Value(StringUtils.getBytesUtf8(StatementSerializer.writeStatement(statement)));
    Text cf = new Text(StatementSerializer.writeContext(statement));
    Text cqBegin = new Text(KeyParts.CQ_BEGIN);
    Text cqEnd = new Text(KeyParts.CQ_END);

    // Start Begin index
    Text keyText = new Text(interval.getAsKeyBeginning());
    KeyParts.appendUniqueness(statement, keyText);
    Mutation m = new Mutation(keyText);
    m.put(cf, cqBegin, statementValue);
    // System.out.println("mutations add begin row=" + m.getRow() + " value=" + value.toString());
    writer.addMutation(m);

    // now the end index:
    keyText = new Text(interval.getAsKeyEnd());
    KeyParts.appendUniqueness(statement, keyText);
    m = new Mutation(keyText);
    m.put(cf, cqEnd, new Value(statementValue));
    // System.out.println("mutations add end row=" + m.getRow() + " value=" + value.toString());
    writer.addMutation(m);
}