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

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

Introduction

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

Prototype

public static String bytesToHex(byte... bytes) 

Source Link

Usage

From source file:andromache.config.CassandraConfigHelper.java

License:Apache License

private static String thriftToString(TBase object) {
    assert object != null;
    // this is so awful it's kind of cool!
    TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());
    try {//ww w .  java  2s  .  co  m
        return Hex.bytesToHex(serializer.serialize(object));
    } catch (TException e) {
        throw new RuntimeException(e);
    }
}

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

License:Apache License

/** convert CfDef to string */
protected static String cfdefToString(CfDef cfDef) throws IOException {
    assert cfDef != null;
    // this is so awful it's kind of cool!
    TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());
    try {/*from   w ww.ja v  a  2  s . c om*/
        return Hex.bytesToHex(serializer.serialize(cfDef));
    } catch (TException e) {
        throw new IOException(e);
    }
}

From source file:com.spotify.hdfs2cass.crunch.cql.CQLRecord.java

License:Open Source License

@Override
public String toString() {
    StringBuilder valuesAsStrings = new StringBuilder();
    valuesAsStrings.append("[");
    for (ByteBuffer value : values) {
        valuesAsStrings.append(Hex.bytesToHex(value.array()));
        valuesAsStrings.append(",");
    }/*w w  w .ja  v a 2s.c  o  m*/
    valuesAsStrings.deleteCharAt(valuesAsStrings.length() - 1);
    valuesAsStrings.append("]");
    return String.format("CQLRecord(key=%s, values=%s", valuesAsStrings);
}

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

License:Apache License

/** {@inheritDoc} */
@Override//from  w w w .j ava  2  s  . co 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.util.ByteBufferUtils.java

License:Apache License

public static String toHex(byte[] bytes) {
    return Hex.bytesToHex(bytes);
}

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

License:Apache License

/** {@inheritDoc} */
@Override//from   www. j  a va  2 s . c  o m
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.util.ByteBufferUtils.java

License:Apache License

public static String toHex(byte bytes) {
    return Hex.bytesToHex(bytes);
}

From source file:io.puntanegra.fhir.index.util.ByteBufferUtils.java

License:Apache License

/**
 * Returns the hexadecimal {@code String} representation of the specified {@code byte} array.
 *
 * @param bytes the {@code byte} array//from  w ww  .j  a  v a2 s .c  o  m
 * @return The hexadecimal {@code String} representation of {@code bytes}
 */
public static String toHex(byte[] bytes) {
    return Hex.bytesToHex(bytes);
}

From source file:io.puntanegra.fhir.index.util.ByteBufferUtils.java

License:Apache License

/**
 * Returns the hexadecimal {@code String} representation of the specified {@code byte}.
 *
 * @param b the {@code byte}/*from www .java 2 s. co  m*/
 * @return the hexadecimal {@code String} representation of {@code b}
 */
public static String toHex(byte b) {
    return Hex.bytesToHex(b);
}

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

License:Apache License

/**
 * Serialize a set of ColumnDefs for indexed columns, so that
 * it can be written to Job configuration
 *
 * @param columns column metadata/*from  w  ww  . j  a v a 2s  . com*/
 * @return serialized form
 */
public static String serializeIndexedColumns(Set<ColumnDef> columns) {
    TSerializer serializer = new TSerializer(new TBinaryProtocol.Factory());
    try {
        List<String> hexStrings = new ArrayList<String>();
        for (ColumnDef column : columns) {
            String encoded = Hex.bytesToHex(serializer.serialize(column));
            logger.info("Encoded column def: " + encoded);
            hexStrings.add(encoded);
        }
        return Joiner.on(AbstractCassandraSerDe.DELIMITER).join(hexStrings);
    } catch (TException e) {
        throw new RuntimeException(e);
    }
}