本文整理汇总了Java中org.apache.cassandra.utils.ByteBufferUtil类的典型用法代码示例。如果您正苦于以下问题:Java ByteBufferUtil类的具体用法?Java ByteBufferUtil怎么用?Java ByteBufferUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ByteBufferUtil类属于org.apache.cassandra.utils包,在下文中一共展示了ByteBufferUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTimestamp
import org.apache.cassandra.utils.ByteBufferUtil; //导入依赖的package包/类
public long getTimestamp(long now, QueryOptions options) throws InvalidRequestException
{
if (timestamp == null)
return now;
ByteBuffer tval = timestamp.bindAndGet(options);
if (tval == null)
throw new InvalidRequestException("Invalid null value of timestamp");
if (tval == ByteBufferUtil.UNSET_BYTE_BUFFER)
return now;
try
{
LongType.instance.validate(tval);
}
catch (MarshalException e)
{
throw new InvalidRequestException("Invalid timestamp value: " + tval);
}
return LongType.instance.compose(tval);
}
示例2: bind
import org.apache.cassandra.utils.ByteBufferUtil; //导入依赖的package包/类
public Terminal bind(QueryOptions options) throws InvalidRequestException
{
SortedSet<ByteBuffer> buffers = new TreeSet<>(comparator);
for (Term t : elements)
{
ByteBuffer bytes = t.bindAndGet(options);
if (bytes == null)
throw new InvalidRequestException("null is not supported inside collections");
if (bytes == ByteBufferUtil.UNSET_BYTE_BUFFER)
return UNSET_VALUE;
buffers.add(bytes);
}
return new Value(buffers);
}
示例3: bindInternal
import org.apache.cassandra.utils.ByteBufferUtil; //导入依赖的package包/类
private ByteBuffer[] bindInternal(QueryOptions options) throws InvalidRequestException
{
if (values.size() > type.size())
{
throw new InvalidRequestException(String.format(
"UDT value contained too many fields (expected %s, got %s)", type.size(), values.size()));
}
ByteBuffer[] buffers = new ByteBuffer[values.size()];
for (int i = 0; i < type.size(); i++)
{
buffers[i] = values.get(i).bindAndGet(options);
// Since a frozen UDT value is always written in its entirety Cassandra can't preserve a pre-existing
// value by 'not setting' the new value. Reject the query.
if (!type.isMultiCell() && buffers[i] == ByteBufferUtil.UNSET_BYTE_BUFFER)
throw new InvalidRequestException(String.format("Invalid unset value for field '%s' of user defined type %s", type.fieldNameAsString(i), type.getNameAsString()));
}
return buffers;
}
示例4: deserialize
import org.apache.cassandra.utils.ByteBufferUtil; //导入依赖的package包/类
public Columns deserialize(DataInputPlus in, CFMetaData metadata) throws IOException
{
int length = (int)in.readUnsignedVInt();
BTree.Builder<ColumnDefinition> builder = BTree.builder(Comparator.naturalOrder());
builder.auto(false);
for (int i = 0; i < length; i++)
{
ByteBuffer name = ByteBufferUtil.readWithVIntLength(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");
}
builder.add(column);
}
return new Columns(builder.build());
}
示例5: readBoundValue
import org.apache.cassandra.utils.ByteBufferUtil; //导入依赖的package包/类
public static ByteBuffer readBoundValue(ByteBuf cb, ProtocolVersion protocolVersion)
{
int length = cb.readInt();
if (length < 0)
{
if (protocolVersion.isSmallerThan(ProtocolVersion.V4)) // backward compatibility for pre-version 4
return null;
if (length == -1)
return null;
else if (length == -2)
return ByteBufferUtil.UNSET_BYTE_BUFFER;
else
throw new ProtocolException("Invalid ByteBuf length " + length);
}
ByteBuf slice = cb.readSlice(length);
return ByteBuffer.wrap(readRawBytes(slice));
}
示例6: append
import org.apache.cassandra.utils.ByteBufferUtil; //导入依赖的package包/类
public void append(DecoratedKey key, RowIndexEntry indexEntry, long dataEnd, ByteBuffer indexInfo) throws IOException
{
bf.add(key);
long indexStart = indexFile.position();
try
{
ByteBufferUtil.writeWithShortLength(key.getKey(), indexFile);
rowIndexEntrySerializer.serialize(indexEntry, indexFile, indexInfo);
}
catch (IOException e)
{
throw new FSWriteError(e, indexFile.getPath());
}
long indexEnd = indexFile.position();
if (logger.isTraceEnabled())
logger.trace("wrote index entry: {} at {}", indexEntry, indexStart);
summary.maybeAddEntry(key, indexStart, indexEnd, dataEnd);
}
示例7: serialize
import org.apache.cassandra.utils.ByteBufferUtil; //导入依赖的package包/类
public ByteBuffer serialize(BigDecimal value)
{
if (value == null)
return ByteBufferUtil.EMPTY_BYTE_BUFFER;
BigInteger bi = value.unscaledValue();
int scale = value.scale();
byte[] bibytes = bi.toByteArray();
ByteBuffer bytes = ByteBuffer.allocate(4 + bibytes.length);
bytes.putInt(scale);
bytes.put(bibytes);
bytes.rewind();
return bytes;
}
示例8: addElementToAll
import org.apache.cassandra.utils.ByteBufferUtil; //导入依赖的package包/类
public MultiCBuilder addElementToAll(ByteBuffer value)
{
checkUpdateable();
if (elementsList.isEmpty())
elementsList.add(new ArrayList<ByteBuffer>());
if (value == null)
containsNull = true;
else if (value == ByteBufferUtil.UNSET_BYTE_BUFFER)
containsUnset = true;
for (int i = 0, m = elementsList.size(); i < m; i++)
elementsList.get(i).add(value);
size++;
return this;
}
示例9: fromJSONObject
import org.apache.cassandra.utils.ByteBufferUtil; //导入依赖的package包/类
@Override
public Term fromJSONObject(Object parsed) throws MarshalException
{
if (parsed instanceof Long)
return new Constants.Value(ByteBufferUtil.bytes((Long) parsed));
try
{
return new Constants.Value(TimestampType.instance.fromString((String) parsed));
}
catch (ClassCastException exc)
{
throw new MarshalException(String.format(
"Expected a long or a datestring representation of a date value, but got a %s: %s",
parsed.getClass().getSimpleName(), parsed));
}
}
示例10: stringifyCollectionsParameters
import org.apache.cassandra.utils.ByteBufferUtil; //导入依赖的package包/类
public static String stringifyCollectionsParameters(Map<ByteBuffer, ? extends CollectionType> collections)
{
StringBuilder sb = new StringBuilder();
sb.append('(');
boolean first = true;
for (Map.Entry<ByteBuffer, ? extends CollectionType> entry : collections.entrySet())
{
if (!first)
sb.append(',');
first = false;
sb.append(ByteBufferUtil.bytesToHex(entry.getKey())).append(":");
sb.append(entry.getValue());
}
sb.append(')');
return sb.toString();
}
示例11: prepare
import org.apache.cassandra.utils.ByteBufferUtil; //导入依赖的package包/类
public ColumnDefinition prepare(CFMetaData cfm)
{
if (!cfm.isStaticCompactTable())
return find(cfm);
AbstractType<?> thriftColumnNameType = cfm.thriftColumnNameType();
if (thriftColumnNameType instanceof UTF8Type)
return find(cfm);
// We have a Thrift-created table with a non-text comparator. Check if we have a match column, otherwise assume we should use
// thriftColumnNameType
ByteBuffer bufferName = ByteBufferUtil.bytes(text);
for (ColumnDefinition def : cfm.allColumns())
{
if (def.name.bytes.equals(bufferName))
return def;
}
return find(thriftColumnNameType.fromString(text), cfm);
}
示例12: fromString
import org.apache.cassandra.utils.ByteBufferUtil; //导入依赖的package包/类
public ByteBuffer fromString(String source) throws MarshalException
{
// Return an empty ByteBuffer for an empty string.
if (source.isEmpty())
return ByteBufferUtil.EMPTY_BYTE_BUFFER;
InetAddress address;
try
{
address = InetAddress.getByName(source);
}
catch (Exception e)
{
throw new MarshalException(String.format("Unable to make inet address from '%s'", source), e);
}
return decompose(address);
}
示例13: fromString
import org.apache.cassandra.utils.ByteBufferUtil; //导入依赖的package包/类
public ByteBuffer fromString(String source) throws MarshalException
{
// Return an empty ByteBuffer for an empty string.
if (source.isEmpty())
return ByteBufferUtil.EMPTY_BYTE_BUFFER;
int int32Type;
try
{
int32Type = Integer.parseInt(source);
}
catch (Exception e)
{
throw new MarshalException(String.format("Unable to make int from '%s'", source), e);
}
return decompose(int32Type);
}
示例14: getAndAppendComparator
import org.apache.cassandra.utils.ByteBufferUtil; //导入依赖的package包/类
protected AbstractType<?> getAndAppendComparator(int i, ByteBuffer bb, StringBuilder sb)
{
try
{
int header = ByteBufferUtil.readShortLength(bb);
if ((header & 0x8000) == 0)
{
String name = ByteBufferUtil.string(ByteBufferUtil.readBytes(bb, header));
sb.append(name).append("@");
return TypeParser.parse(name);
}
else
{
sb.append((char)(header & 0xFF)).append("@");
return aliases.get((byte)(header & 0xFF));
}
}
catch (CharacterCodingException e)
{
throw new RuntimeException(e);
}
}
示例15: fromString
import org.apache.cassandra.utils.ByteBufferUtil; //导入依赖的package包/类
public ByteBuffer fromString(String source) throws MarshalException
{
// Return an empty ByteBuffer for an empty string.
if (source.isEmpty())
return ByteBufferUtil.EMPTY_BYTE_BUFFER;
Double d;
try
{
d = Double.valueOf(source);
}
catch (NumberFormatException e1)
{
throw new MarshalException(String.format("Unable to make double from '%s'", source), e1);
}
return decompose(d);
}