当前位置: 首页>>代码示例>>Java>>正文


Java ByteBufferUtil.readWithShortLength方法代码示例

本文整理汇总了Java中org.apache.cassandra.utils.ByteBufferUtil.readWithShortLength方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBufferUtil.readWithShortLength方法的具体用法?Java ByteBufferUtil.readWithShortLength怎么用?Java ByteBufferUtil.readWithShortLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.cassandra.utils.ByteBufferUtil的用法示例。


在下文中一共展示了ByteBufferUtil.readWithShortLength方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deserialize

import org.apache.cassandra.utils.ByteBufferUtil; //导入方法依赖的package包/类
public static PagingState deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion)
{
    if (bytes == null)
        return null;

    try (DataInputBuffer in = new DataInputBuffer(bytes, true))
    {
        ByteBuffer pk;
        RowMark mark;
        int remaining, remainingInPartition;
        if (protocolVersion.isSmallerOrEqualTo(ProtocolVersion.V3))
        {
            pk = ByteBufferUtil.readWithShortLength(in);
            mark = new RowMark(ByteBufferUtil.readWithShortLength(in), protocolVersion);
            remaining = in.readInt();
            // Note that while 'in.available()' is theoretically an estimate of how many bytes are available
            // without blocking, we know that since we're reading a ByteBuffer it will be exactly how many
            // bytes remain to be read. And the reason we want to condition this is for backward compatility
            // as we used to not set this.
            remainingInPartition = in.available() > 0 ? in.readInt() : Integer.MAX_VALUE;
        }
        else
        {
            pk = ByteBufferUtil.readWithVIntLength(in);
            mark = new RowMark(ByteBufferUtil.readWithVIntLength(in), protocolVersion);
            remaining = (int)in.readUnsignedVInt();
            remainingInPartition = (int)in.readUnsignedVInt();
        }
        return new PagingState(pk.hasRemaining() ? pk : null,
                               mark.mark.hasRemaining() ? mark : null,
                               remaining,
                               remainingInPartition);
    }
    catch (IOException e)
    {
        throw new ProtocolException("Invalid value for the paging state");
    }
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:39,代码来源:PagingState.java

示例2: deserialize

import org.apache.cassandra.utils.ByteBufferUtil; //导入方法依赖的package包/类
public PartitionPosition deserialize(DataInput in, IPartitioner p, int version) throws IOException
{
    Kind kind = Kind.fromOrdinal(in.readByte());
    if (kind == Kind.ROW_KEY)
    {
        ByteBuffer k = ByteBufferUtil.readWithShortLength(in);
        return p.decorateKey(k);
    }
    else
    {
        Token t = Token.serializer.deserialize(in, p, version);
        return kind == Kind.MIN_BOUND ? t.minKeyBound() : t.maxKeyBound();
    }
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:15,代码来源:PartitionPosition.java

示例3: deserialize

import org.apache.cassandra.utils.ByteBufferUtil; //导入方法依赖的package包/类
public ColumnSubselection deserialize(DataInputPlus in, int version, CFMetaData metadata) throws IOException
{
    ByteBuffer name = ByteBufferUtil.readWithShortLength(in);
    ColumnDefinition column = metadata.getColumnDefinition(name);
    if (column == null)
    {
        // If we don't find the definition, it could be we have data for a dropped column, and we shouldn't
        // fail deserialization because of that. So we grab a "fake" ColumnDefinition that ensure proper
        // deserialization. The column will be ignore later on anyway.
        column = metadata.getDroppedColumnDefinition(name);
        if (column == null)
            throw new RuntimeException("Unknown column " + UTF8Type.instance.getString(name) + " during deserialization");
    }

    Kind kind = Kind.values()[in.readUnsignedByte()];
    switch (kind)
    {
        case SLICE:
            CellPath from = column.cellPathSerializer().deserialize(in);
            CellPath to = column.cellPathSerializer().deserialize(in);
            return new Slice(column, from, to);
        case ELEMENT:
            CellPath elt = column.cellPathSerializer().deserialize(in);
            return new Element(column, elt);
    }
    throw new AssertionError();
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:28,代码来源:ColumnSubselection.java

示例4: firstKeyBeyond

import org.apache.cassandra.utils.ByteBufferUtil; //导入方法依赖的package包/类
/**
 * Finds and returns the first key beyond a given token in this SSTable or null if no such key exists.
 */
public DecoratedKey firstKeyBeyond(PartitionPosition token)
{
    if (token.compareTo(first) < 0)
        return first;

    long sampledPosition = getIndexScanPosition(token);

    if (ifile == null)
        return null;

    String path = null;
    try (FileDataInput in = ifile.createReader(sampledPosition))
    {
        path = in.getPath();
        while (!in.isEOF())
        {
            ByteBuffer indexKey = ByteBufferUtil.readWithShortLength(in);
            DecoratedKey indexDecoratedKey = decorateKey(indexKey);
            if (indexDecoratedKey.compareTo(token) > 0)
                return indexDecoratedKey;

            RowIndexEntry.Serializer.skip(in, descriptor.version);
        }
    }
    catch (IOException e)
    {
        markSuspect();
        throw new CorruptSSTableException(e, path);
    }

    return null;
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:36,代码来源:SSTableReader.java

示例5: buildSummary

import org.apache.cassandra.utils.ByteBufferUtil; //导入方法依赖的package包/类
/**
 * Build index summary(and optionally bloom filter) by reading through Index.db file.
 *
 * @param recreateBloomFilter true if recreate bloom filter
 * @param summaryLoaded true if index summary is already loaded and not need to build again
 * @throws IOException
 */
private void buildSummary(boolean recreateBloomFilter, boolean summaryLoaded, int samplingLevel) throws IOException
{
     if (!components.contains(Component.PRIMARY_INDEX))
         return;

    // we read the positions in a BRAF so we don't have to worry about an entry spanning a mmap boundary.
    try (RandomAccessReader primaryIndex = RandomAccessReader.open(descriptor.filenameFor(Component.PRIMARY_INDEX),
                                                                   descriptor.getConfiguration()))
    {
        long indexSize = primaryIndex.length();
        long histogramCount = sstableMetadata.estimatedPartitionSize.count();
        long estimatedKeys = histogramCount > 0 && !sstableMetadata.estimatedPartitionSize.isOverflowed()
                ? histogramCount
                : estimateRowsFromIndex(primaryIndex); // statistics is supposed to be optional

        if (recreateBloomFilter)
            bf = FilterFactory.getFilter(estimatedKeys, metadata.params.bloomFilterFpChance, true, descriptor.version.hasOldBfHashOrder());

        try (IndexSummaryBuilder summaryBuilder = summaryLoaded ? null : new IndexSummaryBuilder(estimatedKeys, metadata.params.minIndexInterval, samplingLevel))
        {
            long indexPosition;

            while ((indexPosition = primaryIndex.getFilePointer()) != indexSize)
            {
                ByteBuffer key = ByteBufferUtil.readWithShortLength(primaryIndex);
                RowIndexEntry.Serializer.skip(primaryIndex, descriptor.version);
                DecoratedKey decoratedKey = decorateKey(key);
                if (first == null)
                    first = decoratedKey;
                last = decoratedKey;

                if (recreateBloomFilter)
                    bf.add(decoratedKey);

                // if summary was already read from disk we don't want to re-populate it using primary index
                if (!summaryLoaded)
                {
                    summaryBuilder.maybeAddEntry(decoratedKey, indexPosition);
                }
            }

            if (!summaryLoaded)
                indexSummary = summaryBuilder.build(getPartitioner());
        }
    }

    first = getMinimalKey(first);
    last = getMinimalKey(last);
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:57,代码来源:SSTableReader.java


注:本文中的org.apache.cassandra.utils.ByteBufferUtil.readWithShortLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。