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

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

Introduction

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

Prototype

public static String bytesToHex(ByteBuffer bytes) 

Source Link

Usage

From source file:com.datastax.demo.portfolio.controller.PortfolioMgrHandler.java

License:Apache License

private static String buildStocksQuery(ByteBuffer ticker) throws Exception {

    return String.format("select FIRST 1000 ''..'' FROM Stocks WHERE key = '%s'",
            ByteBufferUtil.bytesToHex(ticker));
}

From source file:com.datastax.driver.core.querybuilder.Utils.java

License:Apache License

private static boolean appendValueIfLiteral(Object value, StringBuilder sb) {
    if (value instanceof Number || value instanceof UUID || value instanceof Boolean) {
        sb.append(value);//from  w w  w  .  j a v  a2 s .  c  o  m
        return true;
    } else if (value instanceof InetAddress) {
        sb.append("'").append(((InetAddress) value).getHostAddress()).append("'");
        return true;
    } else if (value instanceof Date) {
        sb.append(((Date) value).getTime());
        return true;
    } else if (value instanceof ByteBuffer) {
        sb.append("0x");
        sb.append(ByteBufferUtil.bytesToHex((ByteBuffer) value));
        return true;
    } else if (value == QueryBuilder.BIND_MARKER) {
        sb.append("?");
        return true;
    } else if (value instanceof FCall) {
        FCall fcall = (FCall) value;
        sb.append(fcall.name).append("(");
        for (int i = 0; i < fcall.parameters.length; i++) {
            if (i > 0)
                sb.append(",");
            appendValue(fcall.parameters[i], sb);
        }
        sb.append(")");
        return true;
    } else if (value instanceof CName) {
        appendName(((CName) value).name, sb);
        return true;
    } else if (value == null) {
        sb.append("null");
        return true;
    } else {
        return false;
    }
}

From source file:com.github.adejanovski.cassandra.jdbc.CassandraRowId.java

License:Apache License

public String toString() {
    return ByteBufferUtil.bytesToHex(bytes);
}

From source file:com.netflix.astyanax.core.querybuilder.Utils.java

License:Apache License

private static boolean appendValueIfLiteral(Object value, StringBuilder sb) {
    if (value instanceof Integer || value instanceof Long || value instanceof Float || value instanceof Double
            || value instanceof UUID || value instanceof Boolean) {
        sb.append(value);/*from  w ww  .j ava 2s  .  c om*/
        return true;
    } else if (value instanceof InetAddress) {
        sb.append(((InetAddress) value).getHostAddress());
        return true;
    } else if (value instanceof Date) {
        sb.append(((Date) value).getTime());
        return true;
    } else if (value instanceof ByteBuffer) {
        sb.append("0x");
        sb.append(ByteBufferUtil.bytesToHex((ByteBuffer) value));
        return true;
    } else if (value == QueryBuilder.BIND_MARKER) {
        sb.append("?");
        return true;
    } else {
        return false;
    }
}

From source file:com.protectwise.cassandra.util.PrintHelper.java

License:Apache License

public static void print(OnDiskAtom i, ColumnFamilyStore cfs, StringWriter w) {

    for (ColumnDefinition def : cfs.metadata.clusteringColumns()) {
        w.write(bufToString(def.name.bytes));
        w.write(':');
        w.write(def.type.getSerializer().deserialize(i.name().get(def.position())).toString());
        w.write(',');
    }//  ww  w.  j av  a 2  s  . com

    if (i instanceof Cell) {
        ColumnDefinition col = cfs.metadata.getColumnDefinition(((Cell) i).name());
        if (col != null) {
            w.write(bufToString(col.name.bytes));
            w.write(':');
            w.write(col.type.getSerializer().deserialize(((Cell) i).value()).toString());
        } else {
            w.write(bufToString(i.name().toByteBuffer()));
            w.write("?:0x");
            w.write(ByteBufferUtil.bytesToHex(((Cell) i).value()));
        }

    } else {
        w.write(i.getClass().getSimpleName());
    }

}

From source file:com.protectwise.cassandra.util.PrintHelper.java

License:Apache License

public static String bufToString(ByteBuffer buf) {
    if (buf == null)
        return "null";
    try {/*  w  w w  . java 2s .c om*/
        return ByteBufferUtil.string(buf);
    } catch (CharacterCodingException e) {
        return "0x" + ByteBufferUtil.bytesToHex(buf);
    }
}

From source file:com.protectwise.cassandra.util.PrintHelper.java

License:Apache License

public static String printComposite(Composite name, ColumnFamilyStore cfs) {
    List<ColumnDefinition> clusters = cfs.metadata.clusteringColumns();

    StringWriter w = new StringWriter();

    w.append('[');
    for (int i = 0; i < name.size(); i++) {
        if (i > 0) {
            w.append(",");
        }//w w w .ja  va2 s  .c  o  m

        if (clusters.size() > i) {
            w.append("CK{" + bbToString(clusters.get(i).name.bytes) + "}=");
        }
        w.append("0x" + ByteBufferUtil.bytesToHex(name.get(i)));
    }
    w.append("]");

    return w.toString();
}

From source file:com.stratio.cassandra.index.RowIndexConfig.java

License:Apache License

/**
 * Builds a new {@link RowIndexConfig} for the column family defined by the specified metadata using the specified
 * index options.// w w  w. jav a 2s.  com
 *
 * @param metadata The metadata of the indexed column family.
 * @param options  The index options.
 */
public RowIndexConfig(CFMetaData metadata, Map<String, String> options) {
    // Setup refresh seconds
    String refreshOption = options.get(REFRESH_SECONDS_OPTION);
    if (refreshOption != null) {
        try {
            refreshSeconds = Double.parseDouble(refreshOption);
        } catch (NumberFormatException e) {
            String msg = String.format("'%s' must be a strictly positive double", REFRESH_SECONDS_OPTION);
            throw new RuntimeException(msg);
        }
        if (refreshSeconds <= 0) {
            String msg = String.format("'%s' must be strictly positive", REFRESH_SECONDS_OPTION);
            throw new RuntimeException(msg);
        }
    } else {
        refreshSeconds = DEFAULT_REFRESH_SECONDS;
    }

    // Setup write buffer size
    String ramBufferSizeOption = options.get(RAM_BUFFER_MB_OPTION);
    if (ramBufferSizeOption != null) {
        try {
            ramBufferMB = Integer.parseInt(ramBufferSizeOption);
        } catch (NumberFormatException e) {
            String msg = String.format("'%s' must be a strictly positive integer", RAM_BUFFER_MB_OPTION);
            throw new RuntimeException(msg);
        }
        if (ramBufferMB <= 0) {
            String msg = String.format("'%s' must be strictly positive", RAM_BUFFER_MB_OPTION);
            throw new RuntimeException(msg);
        }
    } else {
        ramBufferMB = DEFAULT_RAM_BUFFER_MB;
    }

    // Setup max merge size
    String maxMergeSizeMBOption = options.get(MAX_MERGE_MB_OPTION);
    if (maxMergeSizeMBOption != null) {
        try {
            maxMergeMB = Integer.parseInt(maxMergeSizeMBOption);
        } catch (NumberFormatException e) {
            String msg = String.format("'%s' must be a strictly positive integer", MAX_MERGE_MB_OPTION);
            throw new RuntimeException(msg);
        }
        if (maxMergeMB <= 0) {
            String msg = String.format("'%s' must be strictly positive", MAX_MERGE_MB_OPTION);
            throw new RuntimeException(msg);
        }
    } else {
        maxMergeMB = DEFAULT_MAX_MERGE_MB;
    }

    // Setup max cached MB
    String maxCachedMBOption = options.get(MAX_CACHED_MB_OPTION);
    if (maxCachedMBOption != null) {
        try {
            maxCachedMB = Integer.parseInt(maxCachedMBOption);
        } catch (NumberFormatException e) {
            String msg = String.format("'%s'  must be a strictly positive integer", MAX_CACHED_MB_OPTION);
            throw new RuntimeException(msg);
        }
        if (maxCachedMB <= 0) {
            String msg = String.format("'%s'  must be strictly positive", MAX_CACHED_MB_OPTION);
            throw new RuntimeException(msg);
        }
    } else {
        maxCachedMB = DEFAULT_MAX_CACHED_MB;
    }

    // Setup queues in index pool
    String indexPoolNumQueuesOption = options.get(INDEXING_THREADS_OPTION);
    if (indexPoolNumQueuesOption != null) {
        try {
            indexingThreads = Integer.parseInt(indexPoolNumQueuesOption);
        } catch (NumberFormatException e) {
            String msg = String.format("'%s'  must be a positive integer", INDEXING_THREADS_OPTION);
            throw new RuntimeException(msg);
        }
    } else {
        indexingThreads = DEFAULT_INDEXING_THREADS;
    }

    // Setup queues in index pool
    String indexPoolQueuesSizeOption = options.get(INDEXING_QUEUES_SIZE_OPTION);
    if (indexPoolQueuesSizeOption != null) {
        try {
            indexingQueuesSize = Integer.parseInt(indexPoolQueuesSizeOption);
        } catch (NumberFormatException e) {
            String msg = String.format("'%s'  must be a strictly positive integer",
                    INDEXING_QUEUES_SIZE_OPTION);
            throw new RuntimeException(msg);
        }
        if (indexingQueuesSize <= 0) {
            String msg = String.format("'%s'  must be strictly positive", INDEXING_QUEUES_SIZE_OPTION);
            throw new RuntimeException(msg);
        }
    } else {
        indexingQueuesSize = DEFAULT_INDEXING_QUEUES_SIZE;
    }

    // Get columns mapping schema
    String schemaOption = options.get(SCHEMA_OPTION);
    if (schemaOption != null && !schemaOption.trim().isEmpty()) {
        try {
            schema = Schema.fromJson(schemaOption);
            schema.validate(metadata);
        } catch (Exception e) {
            String msg = String.format("'%s' is invalid : %s", SCHEMA_OPTION, e.getMessage());
            throw new RuntimeException(msg);
        }
    } else {
        String msg = String.format("'%s' required", SCHEMA_OPTION);
        throw new RuntimeException(msg);
    }

    // Get Lucene directory path
    String[] dataFileLocations = DatabaseDescriptor.getAllDataFileLocations();
    StringBuilder directoryPathBuilder = new StringBuilder();
    directoryPathBuilder.append(dataFileLocations[0]);
    directoryPathBuilder.append(File.separatorChar);
    directoryPathBuilder.append(metadata.ksName);
    directoryPathBuilder.append(File.separatorChar);
    directoryPathBuilder.append(metadata.cfName);
    directoryPathBuilder.append("-");
    directoryPathBuilder.append(ByteBufferUtil.bytesToHex(ByteBufferUtil.bytes(metadata.cfId)));
    directoryPathBuilder.append(File.separatorChar);
    directoryPathBuilder.append(INDEXES_DIR_NAME);
    path = directoryPathBuilder.toString();
}

From source file:com.stratio.cassandra.index.util.ByteBufferUtils.java

License:Apache License

public static String toHex(ByteBuffer byteBuffer) {
    return ByteBufferUtil.bytesToHex(byteBuffer);
}

From source file:com.stratio.cassandra.lucene.service.FullKeyMapper.java

License:Apache License

public String hash(DecoratedKey partitionKey, CellName cellName) {
    return ByteBufferUtil.bytesToHex(byteBuffer(partitionKey, cellName));
}