io.airlift.slice.Slice.toByteBuffer()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(152)

本文整理了Java中io.airlift.slice.Slice.toByteBuffer()方法的一些代码示例,展示了Slice.toByteBuffer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Slice.toByteBuffer()方法的具体详情如下:
包路径:io.airlift.slice.Slice
类名称:Slice
方法名:toByteBuffer

Slice.toByteBuffer介绍

暂无

代码示例

代码示例来源:origin: prestodb/presto

  1. @Description("compute CRC-32")
  2. @ScalarFunction
  3. @SqlType(StandardTypes.BIGINT)
  4. public static long crc32(@SqlType(StandardTypes.VARBINARY) Slice slice)
  5. {
  6. CRC32 crc32 = new CRC32();
  7. crc32.update(slice.toByteBuffer());
  8. return crc32.getValue();
  9. }

代码示例来源:origin: prestodb/presto

  1. private static OGCGeometry geomFromBinary(Slice input)
  2. {
  3. requireNonNull(input, "input is null");
  4. OGCGeometry geometry;
  5. try {
  6. geometry = OGCGeometry.fromBinary(input.toByteBuffer().slice());
  7. }
  8. catch (IllegalArgumentException | IndexOutOfBoundsException e) {
  9. throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid WKB", e);
  10. }
  11. geometry.setSpatialReference(null);
  12. return geometry;
  13. }

代码示例来源:origin: prestodb/presto

  1. return ((Slice) nativeValue).toByteBuffer();

代码示例来源:origin: prestodb/presto

  1. private static OGCGeometry readSimpleGeometry(BasicSliceInput input, Slice inputSlice, GeometrySerializationType type, int length)
  2. {
  3. int currentPosition = toIntExact(input.position());
  4. ByteBuffer geometryBuffer = inputSlice.toByteBuffer(currentPosition, length).slice();
  5. input.setPosition(currentPosition + length);
  6. Geometry esriGeometry = OperatorImportFromESRIShape.local().execute(0, Unknown, geometryBuffer);
  7. return createFromEsriGeometry(esriGeometry, type.geometryType().isMultitype());
  8. }

代码示例来源:origin: prestodb/presto

  1. values.add(type.getSlice(block, position).toByteBuffer());

代码示例来源:origin: prestodb/presto

  1. row.addBinary(destChannel, type.getSlice(block, position).toByteBuffer());

代码示例来源:origin: airlift/slice

  1. public ByteBuffer toByteBuffer()
  2. {
  3. return toByteBuffer(0, size);
  4. }

代码示例来源:origin: io.airlift/slice

  1. public ByteBuffer toByteBuffer()
  2. {
  3. return toByteBuffer(0, size);
  4. }

代码示例来源:origin: io.airlift/slice

  1. /**
  2. * Decodes the a portion of this slice into a string with the specified
  3. * character set name.
  4. */
  5. public String toString(int index, int length, Charset charset)
  6. {
  7. if (length == 0) {
  8. return "";
  9. }
  10. if (base instanceof byte[]) {
  11. return new String((byte[]) base, (int) ((address - ARRAY_BYTE_BASE_OFFSET) + index), length, charset);
  12. }
  13. // direct memory can only be converted to a string using a ByteBuffer
  14. return decodeString(toByteBuffer(index, length), charset);
  15. }

代码示例来源:origin: prestosql/presto

  1. private static OGCGeometry geomFromBinary(Slice input)
  2. {
  3. requireNonNull(input, "input is null");
  4. OGCGeometry geometry;
  5. try {
  6. geometry = OGCGeometry.fromBinary(input.toByteBuffer().slice());
  7. }
  8. catch (IllegalArgumentException | IndexOutOfBoundsException e) {
  9. throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid WKB", e);
  10. }
  11. geometry.setSpatialReference(null);
  12. return geometry;
  13. }

代码示例来源:origin: io.prestosql/presto-main

  1. @Description("compute CRC-32")
  2. @ScalarFunction
  3. @SqlType(StandardTypes.BIGINT)
  4. public static long crc32(@SqlType(StandardTypes.VARBINARY) Slice slice)
  5. {
  6. CRC32 crc32 = new CRC32();
  7. crc32.update(slice.toByteBuffer());
  8. return crc32.getValue();
  9. }

代码示例来源:origin: com.facebook.presto/presto-geospatial

  1. private static OGCGeometry geomFromBinary(Slice input)
  2. {
  3. requireNonNull(input, "input is null");
  4. OGCGeometry geometry;
  5. try {
  6. geometry = OGCGeometry.fromBinary(input.toByteBuffer().slice());
  7. }
  8. catch (IllegalArgumentException | IndexOutOfBoundsException e) {
  9. throw new PrestoException(INVALID_FUNCTION_ARGUMENT, "Invalid WKB", e);
  10. }
  11. geometry.setSpatialReference(null);
  12. return geometry;
  13. }

代码示例来源:origin: prestosql/presto

  1. @Description("compute CRC-32")
  2. @ScalarFunction
  3. @SqlType(StandardTypes.BIGINT)
  4. public static long crc32(@SqlType(StandardTypes.VARBINARY) Slice slice)
  5. {
  6. CRC32 crc32 = new CRC32();
  7. crc32.update(slice.toByteBuffer());
  8. return crc32.getValue();
  9. }

代码示例来源:origin: airlift/slice

  1. private static void assertToByteBuffer(Slice slice, byte[] original)
  2. {
  3. for (int index = 0; index < original.length; index++) {
  4. for (int length = 0; length < (original.length - index); length++) {
  5. byte[] actual = getBytes(slice.toByteBuffer(index, length));
  6. byte[] expected = Arrays.copyOfRange(original, index, index + length);
  7. assertEquals(actual, expected);
  8. }
  9. }
  10. }

代码示例来源:origin: MartinWeindel/presto-kudu

  1. public static Object getJavaValue(Type type, Object nativeValue) {
  2. if (type instanceof VarcharType) {
  3. return ((Slice) nativeValue).toStringUtf8();
  4. } else if (type == TimestampType.TIMESTAMP) {
  5. return ((Long) nativeValue) * 1000;
  6. } else if (type == BigintType.BIGINT) {
  7. return nativeValue;
  8. } else if (type == IntegerType.INTEGER) {
  9. return ((Long) nativeValue).intValue();
  10. } else if (type == SmallintType.SMALLINT) {
  11. return ((Long) nativeValue).shortValue();
  12. } else if (type == TinyintType.TINYINT) {
  13. return ((Long) nativeValue).byteValue();
  14. } else if (type == DoubleType.DOUBLE) {
  15. return nativeValue;
  16. } else if (type == RealType.REAL) {
  17. // conversion can result in precision lost
  18. return intBitsToFloat(((Long) nativeValue).intValue());
  19. } else if (type == BooleanType.BOOLEAN) {
  20. return nativeValue;
  21. } else if (type instanceof VarbinaryType) {
  22. return ((Slice) nativeValue).toByteBuffer();
  23. } else if (type instanceof DecimalType) {
  24. return nativeValue;
  25. } else {
  26. throw new IllegalStateException("Back conversion not implemented for " + type);
  27. }
  28. }

代码示例来源:origin: io.prestosql/presto-geospatial-toolkit

  1. private static OGCGeometry readSimpleGeometry(BasicSliceInput input, Slice inputSlice, GeometrySerializationType type, int length)
  2. {
  3. int currentPosition = toIntExact(input.position());
  4. ByteBuffer geometryBuffer = inputSlice.toByteBuffer(currentPosition, length).slice();
  5. input.setPosition(currentPosition + length);
  6. Geometry esriGeometry = OperatorImportFromESRIShape.local().execute(0, Unknown, geometryBuffer);
  7. return createFromEsriGeometry(esriGeometry, type.geometryType().isMultitype());
  8. }

代码示例来源:origin: com.facebook.presto/presto-geospatial-toolkit

  1. private static OGCGeometry readSimpleGeometry(BasicSliceInput input, Slice inputSlice, GeometrySerializationType type, int length)
  2. {
  3. int currentPosition = toIntExact(input.position());
  4. ByteBuffer geometryBuffer = inputSlice.toByteBuffer(currentPosition, length).slice();
  5. input.setPosition(currentPosition + length);
  6. Geometry esriGeometry = OperatorImportFromESRIShape.local().execute(0, Unknown, geometryBuffer);
  7. return createFromEsriGeometry(esriGeometry, type.geometryType().isMultitype());
  8. }

代码示例来源:origin: prestosql/presto

  1. private static OGCGeometry readSimpleGeometry(BasicSliceInput input, Slice inputSlice, GeometrySerializationType type, int length)
  2. {
  3. int currentPosition = toIntExact(input.position());
  4. ByteBuffer geometryBuffer = inputSlice.toByteBuffer(currentPosition, length).slice();
  5. input.setPosition(currentPosition + length);
  6. Geometry esriGeometry = OperatorImportFromESRIShape.local().execute(0, Unknown, geometryBuffer);
  7. return createFromEsriGeometry(esriGeometry, type.geometryType().isMultitype());
  8. }

代码示例来源:origin: airlift/slice

  1. @Test
  2. public void testToByteBuffer()
  3. {
  4. byte[] original = "hello world".getBytes(UTF_8);
  5. Slice slice = allocate(original.length);
  6. slice.setBytes(0, original);
  7. assertEquals(slice.getBytes(), original);
  8. assertEquals(getBytes(slice.toByteBuffer()), original);
  9. assertToByteBuffer(slice, original);
  10. }

代码示例来源:origin: com.facebook.presto/presto-cassandra

  1. values.add(type.getSlice(block, position).toByteBuffer());

相关文章