Example usage for org.apache.cassandra.utils Hex hexToBytes

List of usage examples for org.apache.cassandra.utils Hex hexToBytes

Introduction

In this page you can find the example usage for org.apache.cassandra.utils Hex hexToBytes.

Prototype

public static byte[] hexToBytes(String str) 

Source Link

Usage

From source file:andromache.config.CassandraConfigHelper.java

License:Apache License

private static KeyRange keyRangeFromString(String st) {
    assert st != null;
    TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
    KeyRange keyRange = new KeyRange();
    try {//from w w w. j a  v a  2 s .  c om
        deserializer.deserialize(keyRange, Hex.hexToBytes(st));
    } catch (TException e) {
        throw new RuntimeException(e);
    }
    return keyRange;
}

From source file:andromache.config.CassandraConfigHelper.java

License:Apache License

private static SlicePredicate predicateFromString(String st) {
    assert st != null;
    TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
    SlicePredicate predicate = new SlicePredicate();
    try {/*from   w w w.  j a  va 2  s .c om*/
        deserializer.deserialize(predicate, Hex.hexToBytes(st));
    } catch (TException e) {
        throw new RuntimeException(e);
    }
    return predicate;
}

From source file:com.dse.pig.udfs.AbstractCassandraStorage.java

License:Apache License

/** convert string back to CfDef */
protected static CfDef cfdefFromString(String st) throws IOException {
    assert st != null;
    TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
    CfDef cfDef = new CfDef();
    try {/*  w  ww.  jav  a 2s  .  co  m*/
        deserializer.deserialize(cfDef, Hex.hexToBytes(st));
    } catch (TException e) {
        throw new IOException(e);
    }
    return cfDef;
}

From source file:com.stratio.cassandra.index.schema.ColumnMapperBlob.java

License:Apache License

/** {@inheritDoc} */
@Override//from   w w w.ja v a2 s.c  o m
public String indexValue(String name, Object value) {
    if (value == null) {
        return null;
    } else if (value instanceof ByteBuffer) {
        ByteBuffer bb = (ByteBuffer) value;
        return ByteBufferUtils.toHex(bb);
    } else if (value instanceof byte[]) {
        byte[] bytes = (byte[]) value;
        return ByteBufferUtils.toHex(bytes);
    } else if (value instanceof String) {
        String string = (String) value;
        string = string.replaceFirst("0x", "");
        byte[] bytes = Hex.hexToBytes(string);
        return Hex.bytesToHex(bytes);
    } else {
        throw new IllegalArgumentException(String.format("Value '%s' cannot be cast to byte array", value));
    }
}

From source file:com.stratio.cassandra.index.schema.ColumnMapperBlobTest.java

License:Apache License

@Test
public void testValueBytes() {
    ColumnMapperBlob mapper = new ColumnMapperBlob();
    byte[] bytes = Hex.hexToBytes("f1");
    String parsed = mapper.indexValue("test", bytes);
    Assert.assertEquals("f1", parsed);
}

From source file:com.stratio.cassandra.lucene.schema.mapping.BlobMapper.java

License:Apache License

/** {@inheritDoc} */
@Override/*w w  w  . j a v a2s . c  om*/
public String base(String name, Object value) {
    if (value == null) {
        return null;
    } else if (value instanceof ByteBuffer) {
        ByteBuffer bb = (ByteBuffer) value;
        return ByteBufferUtils.toHex(bb);
    } else if (value instanceof byte[]) {
        byte[] bytes = (byte[]) value;
        return ByteBufferUtils.toHex(bytes);
    } else if (value instanceof String) {
        String string = (String) value;
        string = string.replaceFirst("0x", "");
        byte[] bytes = Hex.hexToBytes(string);
        return Hex.bytesToHex(bytes);
    } else {
        return error("Field '%s' requires a byte array, but found '%s'", name, value);
    }
}

From source file:com.stratio.cassandra.lucene.schema.mapping.BlobMapperTest.java

License:Apache License

@Test
public void testValueBytes() {
    BlobMapper mapper = new BlobMapper("field", null, null);
    byte[] bytes = Hex.hexToBytes("f1");
    String parsed = mapper.base("test", bytes);
    assertEquals("f1", parsed);
}

From source file:org.apache.hadoop.hive.cassandra.CassandraPushdownPredicate.java

License:Apache License

/**
 * Serialize a set of ColumnDefs for indexed columns, read
 * from Job configuration/*w w w . ja  va  2  s .c  o m*/
 *
 * @param serialized column metadata
 * @return list of column metadata objects which may be empty, but not null
 */
public static Set<ColumnDef> deserializeIndexedColumns(String serialized) {
    Set<ColumnDef> columns = new HashSet<ColumnDef>();
    if (null == serialized) {
        return columns;
    }

    Iterable<String> strings = Splitter.on(AbstractCassandraSerDe.DELIMITER).omitEmptyStrings().trimResults()
            .split(serialized);
    TDeserializer deserializer = new TDeserializer(new TBinaryProtocol.Factory());
    for (String encoded : strings) {
        ColumnDef column = new ColumnDef();
        try {
            logger.info("Encoded column def: " + encoded);
            deserializer.deserialize(column, Hex.hexToBytes(encoded));
        } catch (TException e) {
            logger.warn("Error deserializing indexed column definition", e);
        }
        if (null == column.getName() || null == column.validation_class) {
            continue;
        }
        columns.add(column);
    }
    return columns;
}

From source file:org.apache.hadoop.hive.cassandra.ql.udf.UDFHexToBytes.java

License:Apache License

public BytesWritable evaluate(Text text) {
    return new BytesWritable(Hex.hexToBytes(new String(text.getBytes())));
}