Java Code Examples for org.apache.cassandra.utils.ByteBufferUtil#bytesToHex()

The following examples show how to use org.apache.cassandra.utils.ByteBufferUtil#bytesToHex() . 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: CBUtil.java    From stratio-cassandra with Apache License 2.0 6 votes vote down vote up
private static String readString(ByteBuf cb, int length)
{
    if (length == 0)
        return "";

    ByteBuffer buffer = cb.nioBuffer(cb.readerIndex(), length);
    try
    {
        String str = decodeString(buffer);
        cb.readerIndex(cb.readerIndex() + length);
        return str;
    }
    catch (IllegalStateException | CharacterCodingException e)
    {
        throw new ProtocolException("Cannot decode string as UTF8: '" + ByteBufferUtil.bytesToHex(buffer) + "'; " + e);
    }
}
 
Example 2
Source File: DefaultChangeEncoder.java    From emodb with Apache License 2.0 5 votes vote down vote up
/** Returns the index of the colon that separates the encoding prefix from the body suffix. */
private int getSeparatorIndex(ByteBuffer buf) {
    int colon = BufferUtils.indexOf(buf, (byte) ':');
    if (colon == -1) {
        throw new IllegalStateException("Unknown encoding format: " + ByteBufferUtil.bytesToHex(buf));
    }
    return colon;
}
 
Example 3
Source File: AbstractTextSerializer.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public String deserialize(ByteBuffer bytes)
{
    try
    {
        return ByteBufferUtil.string(bytes, charset);
    }
    catch (CharacterCodingException e)
    {
        throw new MarshalException("Invalid " + charset + " bytes " + ByteBufferUtil.bytesToHex(bytes));
    }
}
 
Example 4
Source File: TableTransformer.java    From sstable-tools with Apache License 2.0 5 votes vote down vote up
public static String colValue(ResultSet results, List<ByteBuffer> row, int i) throws Exception {
    ByteBuffer v = row.get(i).duplicate();
    String ret = "null";
    if (v != null) {
        EnumSet<ResultSet.Flag> flags = (EnumSet<ResultSet.Flag>) CassandraUtils.readPrivate(results.metadata, "flags");
        if (flags.contains(ResultSet.Flag.NO_METADATA)) {
            ret = "0x" + ByteBufferUtil.bytesToHex(v);
        } else if (results.metadata.names.get(i).type.isCollection()) {
            ret = results.metadata.names.get(i).type.getSerializer().deserialize(v).toString();
        } else {
            ret = results.metadata.names.get(i).type.getString(v);
        }
    }
    return ret;
}
 
Example 5
Source File: OrderPreservingPartitioner.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public StringToken getToken(ByteBuffer key)
{
    String skey;
    try
    {
        skey = ByteBufferUtil.string(key);
    }
    catch (CharacterCodingException e)
    {
        skey = ByteBufferUtil.bytesToHex(key);
    }
    return new StringToken(skey);
}
 
Example 6
Source File: ColumnToCollectionType.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public void validateCollectionMember(ByteBuffer bytes, ByteBuffer collectionName) throws MarshalException
{
    CollectionType t = defined.get(collectionName);
    if (t == null)
        throw new MarshalException(ByteBufferUtil.bytesToHex(collectionName) + " is not defined as a collection");

    t.nameComparator().validate(bytes);
}
 
Example 7
Source File: ColumnToCollectionType.java    From stratio-cassandra with Apache License 2.0 5 votes vote down vote up
public int compareCollectionMembers(ByteBuffer o1, ByteBuffer o2, ByteBuffer collectionName)
{
    CollectionType t = defined.get(collectionName);
    if (t == null)
        throw new RuntimeException(ByteBufferUtil.bytesToHex(collectionName) + " is not defined as a collection");

    return t.nameComparator().compare(o1, o2);
}
 
Example 8
Source File: ByteBufferUtils.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public static String toHex(ByteBuffer byteBuffer) {
    return ByteBufferUtil.bytesToHex(byteBuffer);
}
 
Example 9
Source File: CqlOperation.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
private static String getUnQuotedCqlBlob(ByteBuffer term, boolean isCQL3)
{
    return isCQL3
            ? "0x" + ByteBufferUtil.bytesToHex(term)
            : ByteBufferUtil.bytesToHex(term);
}
 
Example 10
Source File: BytesSerializer.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public String toString(ByteBuffer value)
{
    return ByteBufferUtil.bytesToHex(value);
}
 
Example 11
Source File: DirectoriesTest.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
private static File cfDir(CFMetaData metadata)
{
    String cfId = ByteBufferUtil.bytesToHex(ByteBufferUtil.bytes(metadata.cfId));
    return new File(tempDataDir, metadata.ksName + File.separator + metadata.cfName + "-" + cfId);
}
 
Example 12
Source File: ColumnSlice.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@Override
public String toString()
{
    return "[" + ByteBufferUtil.bytesToHex(start.toByteBuffer()) + ", " + ByteBufferUtil.bytesToHex(finish.toByteBuffer()) + "]";
}
 
Example 13
Source File: CounterColumnType.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public String getString(ByteBuffer bytes)
{
    return ByteBufferUtil.bytesToHex(bytes);
}
 
Example 14
Source File: LocalByPartionerType.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
public String getString(ByteBuffer bytes)
{
    return ByteBufferUtil.bytesToHex(bytes);
}
 
Example 15
Source File: DecoratedKey.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@Override
public String toString()
{
    String keystring = getKey() == null ? "null" : ByteBufferUtil.bytesToHex(getKey());
    return "DecoratedKey(" + getToken() + ", " + keystring + ")";
}
 
Example 16
Source File: Constants.java    From stratio-cassandra with Apache License 2.0 4 votes vote down vote up
@Override
public String toString()
{
    return ByteBufferUtil.bytesToHex(bytes);
}
 
Example 17
Source File: CassandraRowId.java    From cassandra-jdbc-wrapper with Apache License 2.0 4 votes vote down vote up
public String toString()
{
    return ByteBufferUtil.bytesToHex(bytes);
}
 
Example 18
Source File: ScanRange.java    From emodb with Apache License 2.0 4 votes vote down vote up
@JsonProperty ("to")
public String getToHex() {
    return ByteBufferUtil.bytesToHex(_to);
}
 
Example 19
Source File: ScanRange.java    From emodb with Apache License 2.0 4 votes vote down vote up
@JsonProperty ("from")
public String getFromHex() {
    return ByteBufferUtil.bytesToHex(_from);
}
 
Example 20
Source File: CFMetaData.java    From stratio-cassandra with Apache License 2.0 2 votes vote down vote up
/**
 * generate a column family name for an index corresponding to the given column.
 * This is NOT the same as the index's name! This is only used in sstable filenames and is not exposed to users.
 *
 * @param info A definition of the column with index
 *
 * @return name of the index ColumnFamily
 */
public String indexColumnFamilyName(ColumnDefinition info)
{
    // TODO simplify this when info.index_name is guaranteed to be set
    return cfName + Directories.SECONDARY_INDEX_NAME_SEPARATOR + (info.getIndexName() == null ? ByteBufferUtil.bytesToHex(info.name.bytes) : info.getIndexName());
}