本文整理了Java中io.airlift.slice.Slice.toByteBuffer()
方法的一些代码示例,展示了Slice.toByteBuffer()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Slice.toByteBuffer()
方法的具体详情如下:
包路径:io.airlift.slice.Slice
类名称:Slice
方法名:toByteBuffer
暂无
代码示例来源:origin: prestodb/presto
@Description("compute CRC-32")
@ScalarFunction
@SqlType(StandardTypes.BIGINT)
public static long crc32(@SqlType(StandardTypes.VARBINARY) Slice slice)
{
CRC32 crc32 = new CRC32();
crc32.update(slice.toByteBuffer());
return crc32.getValue();
}
代码示例来源:origin: prestodb/presto
private static OGCGeometry geomFromBinary(Slice input)
{
requireNonNull(input, "input is null");
OGCGeometry geometry;
try {
geometry = OGCGeometry.fromBinary(input.toByteBuffer().slice());
}
catch (IllegalArgumentException | IndexOutOfBoundsException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid WKB", e);
}
geometry.setSpatialReference(null);
return geometry;
}
代码示例来源:origin: prestodb/presto
return ((Slice) nativeValue).toByteBuffer();
代码示例来源:origin: prestodb/presto
private static OGCGeometry readSimpleGeometry(BasicSliceInput input, Slice inputSlice, GeometrySerializationType type, int length)
{
int currentPosition = toIntExact(input.position());
ByteBuffer geometryBuffer = inputSlice.toByteBuffer(currentPosition, length).slice();
input.setPosition(currentPosition + length);
Geometry esriGeometry = OperatorImportFromESRIShape.local().execute(0, Unknown, geometryBuffer);
return createFromEsriGeometry(esriGeometry, type.geometryType().isMultitype());
}
代码示例来源:origin: prestodb/presto
values.add(type.getSlice(block, position).toByteBuffer());
代码示例来源:origin: prestodb/presto
row.addBinary(destChannel, type.getSlice(block, position).toByteBuffer());
代码示例来源:origin: airlift/slice
public ByteBuffer toByteBuffer()
{
return toByteBuffer(0, size);
}
代码示例来源:origin: io.airlift/slice
public ByteBuffer toByteBuffer()
{
return toByteBuffer(0, size);
}
代码示例来源:origin: io.airlift/slice
/**
* Decodes the a portion of this slice into a string with the specified
* character set name.
*/
public String toString(int index, int length, Charset charset)
{
if (length == 0) {
return "";
}
if (base instanceof byte[]) {
return new String((byte[]) base, (int) ((address - ARRAY_BYTE_BASE_OFFSET) + index), length, charset);
}
// direct memory can only be converted to a string using a ByteBuffer
return decodeString(toByteBuffer(index, length), charset);
}
代码示例来源:origin: prestosql/presto
private static OGCGeometry geomFromBinary(Slice input)
{
requireNonNull(input, "input is null");
OGCGeometry geometry;
try {
geometry = OGCGeometry.fromBinary(input.toByteBuffer().slice());
}
catch (IllegalArgumentException | IndexOutOfBoundsException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid WKB", e);
}
geometry.setSpatialReference(null);
return geometry;
}
代码示例来源:origin: io.prestosql/presto-main
@Description("compute CRC-32")
@ScalarFunction
@SqlType(StandardTypes.BIGINT)
public static long crc32(@SqlType(StandardTypes.VARBINARY) Slice slice)
{
CRC32 crc32 = new CRC32();
crc32.update(slice.toByteBuffer());
return crc32.getValue();
}
代码示例来源:origin: com.facebook.presto/presto-geospatial
private static OGCGeometry geomFromBinary(Slice input)
{
requireNonNull(input, "input is null");
OGCGeometry geometry;
try {
geometry = OGCGeometry.fromBinary(input.toByteBuffer().slice());
}
catch (IllegalArgumentException | IndexOutOfBoundsException e) {
throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid WKB", e);
}
geometry.setSpatialReference(null);
return geometry;
}
代码示例来源:origin: prestosql/presto
@Description("compute CRC-32")
@ScalarFunction
@SqlType(StandardTypes.BIGINT)
public static long crc32(@SqlType(StandardTypes.VARBINARY) Slice slice)
{
CRC32 crc32 = new CRC32();
crc32.update(slice.toByteBuffer());
return crc32.getValue();
}
代码示例来源:origin: airlift/slice
private static void assertToByteBuffer(Slice slice, byte[] original)
{
for (int index = 0; index < original.length; index++) {
for (int length = 0; length < (original.length - index); length++) {
byte[] actual = getBytes(slice.toByteBuffer(index, length));
byte[] expected = Arrays.copyOfRange(original, index, index + length);
assertEquals(actual, expected);
}
}
}
代码示例来源:origin: MartinWeindel/presto-kudu
public static Object getJavaValue(Type type, Object nativeValue) {
if (type instanceof VarcharType) {
return ((Slice) nativeValue).toStringUtf8();
} else if (type == TimestampType.TIMESTAMP) {
return ((Long) nativeValue) * 1000;
} else if (type == BigintType.BIGINT) {
return nativeValue;
} else if (type == IntegerType.INTEGER) {
return ((Long) nativeValue).intValue();
} else if (type == SmallintType.SMALLINT) {
return ((Long) nativeValue).shortValue();
} else if (type == TinyintType.TINYINT) {
return ((Long) nativeValue).byteValue();
} else if (type == DoubleType.DOUBLE) {
return nativeValue;
} else if (type == RealType.REAL) {
// conversion can result in precision lost
return intBitsToFloat(((Long) nativeValue).intValue());
} else if (type == BooleanType.BOOLEAN) {
return nativeValue;
} else if (type instanceof VarbinaryType) {
return ((Slice) nativeValue).toByteBuffer();
} else if (type instanceof DecimalType) {
return nativeValue;
} else {
throw new IllegalStateException("Back conversion not implemented for " + type);
}
}
代码示例来源:origin: io.prestosql/presto-geospatial-toolkit
private static OGCGeometry readSimpleGeometry(BasicSliceInput input, Slice inputSlice, GeometrySerializationType type, int length)
{
int currentPosition = toIntExact(input.position());
ByteBuffer geometryBuffer = inputSlice.toByteBuffer(currentPosition, length).slice();
input.setPosition(currentPosition + length);
Geometry esriGeometry = OperatorImportFromESRIShape.local().execute(0, Unknown, geometryBuffer);
return createFromEsriGeometry(esriGeometry, type.geometryType().isMultitype());
}
代码示例来源:origin: com.facebook.presto/presto-geospatial-toolkit
private static OGCGeometry readSimpleGeometry(BasicSliceInput input, Slice inputSlice, GeometrySerializationType type, int length)
{
int currentPosition = toIntExact(input.position());
ByteBuffer geometryBuffer = inputSlice.toByteBuffer(currentPosition, length).slice();
input.setPosition(currentPosition + length);
Geometry esriGeometry = OperatorImportFromESRIShape.local().execute(0, Unknown, geometryBuffer);
return createFromEsriGeometry(esriGeometry, type.geometryType().isMultitype());
}
代码示例来源:origin: prestosql/presto
private static OGCGeometry readSimpleGeometry(BasicSliceInput input, Slice inputSlice, GeometrySerializationType type, int length)
{
int currentPosition = toIntExact(input.position());
ByteBuffer geometryBuffer = inputSlice.toByteBuffer(currentPosition, length).slice();
input.setPosition(currentPosition + length);
Geometry esriGeometry = OperatorImportFromESRIShape.local().execute(0, Unknown, geometryBuffer);
return createFromEsriGeometry(esriGeometry, type.geometryType().isMultitype());
}
代码示例来源:origin: airlift/slice
@Test
public void testToByteBuffer()
{
byte[] original = "hello world".getBytes(UTF_8);
Slice slice = allocate(original.length);
slice.setBytes(0, original);
assertEquals(slice.getBytes(), original);
assertEquals(getBytes(slice.toByteBuffer()), original);
assertToByteBuffer(slice, original);
}
代码示例来源:origin: com.facebook.presto/presto-cassandra
values.add(type.getSlice(block, position).toByteBuffer());
内容来源于网络,如有侵权,请联系作者删除!