本文整理了Java中com.datastax.driver.core.utils.Bytes.getArray()
方法的一些代码示例,展示了Bytes.getArray()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Bytes.getArray()
方法的具体详情如下:
包路径:com.datastax.driver.core.utils.Bytes
类名称:Bytes
方法名:getArray
[英]Extract the content of the provided ByteBuffer as a byte array.
This method work with any type of ByteBuffer (direct and non-direct ones), but when the ByteBuffer is backed by an array, this method will try to avoid copy when possible. As a consequence, changes to the returned byte array may or may not reflect into the initial ByteBuffer.
[中]将ByteBuffer提供的内容提取为字节数组。
此方法适用于任何类型的ByteBuffer(直接和非直接),但当ByteBuffer由数组支持时,此方法将尽可能避免复制。因此,对返回字节数组的更改可能会也可能不会反映到初始ByteBuffer中。
代码示例来源:origin: kaaproject/kaa
/**
* This method convert ByteBuffer object to byte array.
*
* @return the byte array or null
*/
public static byte[] getBytes(ByteBuffer byteBuffer) {
byte[] array = null;
if (byteBuffer != null) {
array = Bytes.getArray(byteBuffer);
}
return array;
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Returns the "raw" paging state of the query.
*
* <p>Contrary to {@link #getPagingState()}, there will be no validation when this is later
* reinjected into a statement.
*
* @return the paging state or null if there is no next page.
* @see Statement#setPagingStateUnsafe(byte[])
*/
public byte[] getPagingStateUnsafe() {
if (this.pagingState == null) return null;
return Bytes.getArray(this.pagingState);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/** @return A new ByteBuffer from the input Buffer with any trailing 0-bytes stripped off. */
private static ByteBuffer stripTrailingZeroBytes(ByteBuffer b) {
byte result[] = Bytes.getArray(b);
int zeroIndex = result.length;
for (int i = result.length - 1; i > 0; i--) {
if (result[i] == 0) {
zeroIndex = i;
} else {
break;
}
}
return ByteBuffer.wrap(result, 0, zeroIndex);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Override
public BigInteger deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) {
return bytes == null || bytes.remaining() == 0 ? null : new BigInteger(Bytes.getArray(bytes));
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
private BigInteger toBigInteger(ByteBuffer bb, int significantBytes) {
byte[] bytes = Bytes.getArray(bb);
byte[] target;
if (significantBytes != bytes.length) {
target = new byte[significantBytes];
System.arraycopy(bytes, 0, target, 0, bytes.length);
} else target = bytes;
return new BigInteger(1, target);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* {@inheritDoc}
*
* <p>Implementation note: this method treats {@code null}s and empty buffers differently: the
* formers are mapped to {@code null}s while the latters are mapped to empty strings.
*/
@Override
public String deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) {
if (bytes == null) return null;
if (bytes.remaining() == 0) return "";
return new String(Bytes.getArray(bytes), charset);
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Override
public int compareTo(Token other) {
assert other instanceof OPPToken;
return UnsignedBytes.lexicographicalComparator()
.compare(Bytes.getArray(value), Bytes.getArray(((OPPToken) other).value));
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
PagingState(
ByteBuffer pagingState,
Statement statement,
ProtocolVersion protocolVersion,
CodecRegistry codecRegistry) {
this.pagingState = Bytes.getArray(pagingState);
this.hash = hash(statement, protocolVersion, codecRegistry);
this.protocolVersion = protocolVersion;
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Override
public InetAddress deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) {
if (bytes == null || bytes.remaining() == 0) return null;
try {
return InetAddress.getByAddress(Bytes.getArray(bytes));
} catch (UnknownHostException e) {
throw new InvalidTypeException(
"Invalid bytes for inet value, got " + bytes.remaining() + " bytes");
}
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Override
public Duration deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion)
throws InvalidTypeException {
if (bytes == null || bytes.remaining() == 0) {
return null;
} else {
DataInput in = ByteStreams.newDataInput(Bytes.getArray(bytes));
try {
int months = (int) VIntCoding.readVInt(in);
int days = (int) VIntCoding.readVInt(in);
long nanoseconds = VIntCoding.readVInt(in);
return Duration.newInstance(months, days, nanoseconds);
} catch (IOException e) {
// cannot happen
throw new AssertionError();
}
}
}
代码示例来源:origin: org.caffinitas.mapper/caffinitas-mapper-core
@Override
public String deserialize(ByteBuffer bytes) {
return new String(Bytes.getArray(bytes), charset);
}
}
代码示例来源:origin: com.yugabyte/cassandra-driver-core
private BigInteger toBigInteger(ByteBuffer bb, int significantBytes) {
byte[] bytes = Bytes.getArray(bb);
byte[] target;
if (significantBytes != bytes.length) {
target = new byte[significantBytes];
System.arraycopy(bytes, 0, target, 0, bytes.length);
} else
target = bytes;
return new BigInteger(1, target);
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver
private BigInteger toBigInteger(ByteBuffer bb, int significantBytes) {
byte[] bytes = Bytes.getArray(bb);
byte[] target;
if (significantBytes != bytes.length) {
target = new byte[significantBytes];
System.arraycopy(bytes, 0, target, 0, bytes.length);
} else
target = bytes;
return new BigInteger(1, target);
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver
@Override
public BigInteger deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) {
return bytes == null || bytes.remaining() == 0 ? null : new BigInteger(Bytes.getArray(bytes));
}
}
代码示例来源:origin: com.facebook.presto.cassandra/cassandra-driver
@Override
public int compareTo(Token other) {
assert other instanceof OPPToken;
return UnsignedBytes.lexicographicalComparator().compare(
Bytes.getArray(value),
Bytes.getArray(((OPPToken) other).value));
}
代码示例来源:origin: com.stratio.cassandra/cassandra-driver-core
@Override
public InetAddress deserialize(ByteBuffer bytes) {
try {
return InetAddress.getByAddress(Bytes.getArray(bytes));
} catch (UnknownHostException e) {
throw new InvalidTypeException("Invalid bytes for inet value, got " + bytes.remaining() + " bytes");
}
}
}
代码示例来源:origin: com.yugabyte/cassandra-driver-core
@Override
public InetAddress deserialize(ByteBuffer bytes, ProtocolVersion protocolVersion) {
if (bytes == null || bytes.remaining() == 0)
return null;
try {
return InetAddress.getByAddress(Bytes.getArray(bytes));
} catch (UnknownHostException e) {
throw new InvalidTypeException("Invalid bytes for inet value, got " + bytes.remaining() + " bytes");
}
}
}
代码示例来源:origin: io.zipkin/zipkin-cassandra-core
private String debugInsertTraceIdByAnnotation(ByteBuffer annotationKey, long timestamp, long traceId, int ttl) {
return insertTraceIdByAnnotation.getQueryString()
.replace(":annotation", new String(Bytes.getArray(annotationKey)))
.replace(":ts", new Date(timestamp / 1000).toString())
.replace(":trace_id", String.valueOf(traceId))
.replace(":ttl_", String.valueOf(ttl));
}
代码示例来源:origin: cumulusrdf/cumulusrdf
/**
* Deserializes the object from the given ByteBuffer.
*
* @param serialized The serialized object.
* @return The deserialized object.
*/
public T deserialize(final ByteBuffer serialized) {
return deserializeInternal(Bytes.getArray(serialized));
}
代码示例来源:origin: io.zipkin/zipkin-cassandra-core
private String debugSelectTraceIdsByAnnotations(ByteBuffer annotationKey, long startTs, long endTs, int limit) {
return selectTraceIdsByAnnotations.getQueryString()
.replace(":annotation", new String(Bytes.getArray(annotationKey)))
.replace(":start_ts", new Date(startTs / 1000).toString())
.replace(":end_ts", new Date(endTs / 1000).toString())
.replace(":limit_", String.valueOf(limit));
}
内容来源于网络,如有侵权,请联系作者删除!