org.apache.calcite.avatica.util.ByteString.getBytes()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(140)

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

ByteString.getBytes介绍

[英]Returns a copy of the byte array.
[中]返回字节数组的副本。

代码示例

代码示例来源:origin: org.apache.calcite/calcite-avatica

@Override public byte[] getBytes() {
 Object obj = getObject();
 try {
  final ByteString o = (ByteString) obj;
  return o == null ? null : o.getBytes();
 } catch (Exception ex) {
  return obj == null ? null : (byte[]) obj;
 }
}

代码示例来源:origin: org.apache.calcite/calcite-core

public String load(@Nonnull Pair<ByteString, Charset> key) {
  final Charset charset = key.right;
  final CharsetDecoder decoder = charset.newDecoder();
  final byte[] bytes = key.left.getBytes();
  final ByteBuffer buffer = ByteBuffer.wrap(bytes);
  try {
   return decoder.decode(buffer).toString();
  } catch (CharacterCodingException ex) {
   throw RESOURCE.charsetEncoding(
     //CHECKSTYLE: IGNORE 1
     new String(bytes, Charset.defaultCharset()),
     charset.name()).ex();
  }
 }
});

代码示例来源:origin: org.apache.calcite/calcite-core

/** Returns a byte-string padded with zero bytes to make it at least a given
  * length, */
 private static ByteString padRight(ByteString s, int length) {
  if (s.length() >= length) {
   return s;
  }
  return new ByteString(Arrays.copyOf(s.getBytes(), length));
 }
}

代码示例来源:origin: Qihoo360/Quicksql

/** Returns a byte-string padded with zero bytes to make it at least a given
  * length, */
 private static ByteString padRight(ByteString s, int length) {
  if (s.length() >= length) {
   return s;
  }
  return new ByteString(Arrays.copyOf(s.getBytes(), length));
 }
}

代码示例来源:origin: org.apache.calcite.avatica/avatica-core

@Override public byte[] getBytes() throws SQLException {
 Object obj = getObject();
 if (null == obj) {
  return null;
 }
 if (obj instanceof ByteString) {
  return ((ByteString) obj).getBytes();
 } else if (obj instanceof String) {
  // Need to unwind the base64 for JSON
  return ByteString.parseBase64((String) obj);
 } else if (obj instanceof byte[]) {
  // Protobuf would have a byte array
  return (byte[]) obj;
 } else {
  throw new RuntimeException("Cannot handle " + obj.getClass() + " as bytes");
 }
}

代码示例来源:origin: apache/calcite-avatica

@Override public byte[] getBytes() throws SQLException {
 Object obj = getObject();
 if (null == obj) {
  return null;
 }
 if (obj instanceof ByteString) {
  return ((ByteString) obj).getBytes();
 } else if (obj instanceof String) {
  // Need to unwind the base64 for JSON
  return ByteString.parseBase64((String) obj);
 } else if (obj instanceof byte[]) {
  // Protobuf would have a byte array
  return (byte[]) obj;
 } else {
  throw new RuntimeException("Cannot handle " + obj.getClass() + " as bytes");
 }
}

代码示例来源:origin: org.apache.calcite/calcite-core

/**
 * Validate if value can be decoded by given charset.
 *
 * @param value nls string in byte array
 * @param charset charset
 * @throws RuntimeException If the given value cannot be represented in the
 *     given charset
 */
public static void validateCharset(ByteString value, Charset charset) {
 if (charset == StandardCharsets.UTF_8) {
  final byte[] bytes = value.getBytes();
  if (!Utf8.isWellFormed(bytes)) {
   //CHECKSTYLE: IGNORE 1
   final String string = new String(bytes, charset);
   throw RESOURCE.charsetEncoding(string, charset.name()).ex();
  }
 }
}

代码示例来源:origin: org.apache.calcite/calcite-avatica

private static Object serialToJdbc(ColumnMetaData.Rep type, Object value,
  Calendar calendar) {
 switch (type) {
 case BYTE_STRING:
  return ByteString.ofBase64((String) value).getBytes();
 case JAVA_UTIL_DATE:
  return new java.util.Date(adjust((Number) value, calendar));
 case JAVA_SQL_DATE:
  return new java.sql.Date(
    adjust(((Number) value).longValue() * DateTimeUtils.MILLIS_PER_DAY,
      calendar));
 case JAVA_SQL_TIME:
  return new java.sql.Time(adjust((Number) value, calendar));
 case JAVA_SQL_TIMESTAMP:
  return new java.sql.Timestamp(adjust((Number) value, calendar));
 default:
  return serialToLocal(type, value);
 }
}

代码示例来源:origin: apache/samza

static public Object convertToAvroObject(Object relObj, Schema schema) {
 if (relObj == null) {
  return null;
 }
 switch(schema.getType()) {
  case RECORD:
   return convertToGenericRecord((SamzaSqlRelRecord) relObj, getNonNullUnionSchema(schema));
  case ARRAY:
   List<Object> avroList = ((List<Object>) relObj).stream()
     .map(o -> convertToAvroObject(o, getNonNullUnionSchema(schema).getElementType()))
     .collect(Collectors.toList());
   return avroList;
  case MAP:
   return ((Map<String, ?>) relObj).entrySet()
     .stream()
     .collect(Collectors.toMap(Map.Entry::getKey, e -> convertToAvroObject(e.getValue(),
       getNonNullUnionSchema(schema).getValueType())));
  case UNION:
   return convertToAvroObject(relObj, getNonNullUnionSchema(schema));
  case ENUM:
   return new GenericData.EnumSymbol(schema, (String) relObj);
  case FIXED:
   return new GenericData.Fixed(schema, ((ByteString) relObj).getBytes());
  case BYTES:
   return ByteBuffer.wrap(((ByteString) relObj).getBytes());
  default:
   return relObj;
 }
}

代码示例来源:origin: org.apache.samza/samza-sql

public Object convertToAvroObject(Object relObj, Schema schema) {
 if (relObj == null) {
  return null;
 }
 switch(schema.getType()) {
  case RECORD:
   return convertToGenericRecord((SamzaSqlRelRecord) relObj, getNonNullUnionSchema(schema));
  case ARRAY:
   List<Object> avroList = ((List<Object>) relObj).stream()
     .map(o -> convertToAvroObject(o, getNonNullUnionSchema(schema).getElementType()))
     .collect(Collectors.toList());
   return avroList;
  case MAP:
   return ((Map<String, ?>) relObj).entrySet()
     .stream()
     .collect(Collectors.toMap(Map.Entry::getKey, e -> convertToAvroObject(e.getValue(),
       getNonNullUnionSchema(schema).getValueType())));
  case UNION:
   return convertToAvroObject(relObj, getNonNullUnionSchema(schema));
  case ENUM:
   return new GenericData.EnumSymbol(schema, (String) relObj);
  case FIXED:
   return new GenericData.Fixed(schema, ((ByteString) relObj).getBytes());
  case BYTES:
   return ByteBuffer.wrap(((ByteString) relObj).getBytes());
  default:
   return relObj;
 }
}

代码示例来源:origin: Qihoo360/Quicksql

case BINARY:
 if (clazz == byte[].class) {
  return clazz.cast(((ByteString) value).getBytes());

代码示例来源:origin: org.apache.calcite.avatica/avatica-core

switch (type) {
case BYTE_STRING:
 return ByteString.ofBase64((String) value).getBytes();
case JAVA_UTIL_DATE:
 return new java.util.Date(adjust((Number) value, calendar));

代码示例来源:origin: apache/calcite-avatica

switch (type) {
case BYTE_STRING:
 return ByteString.ofBase64((String) value).getBytes();
case JAVA_UTIL_DATE:
 return new java.util.Date(adjust((Number) value, calendar));

代码示例来源:origin: org.apache.calcite/calcite-core

private void thereAndBack(byte[] bytes) {
 final ByteString byteString = new ByteString(bytes);
 final byte[] bytes2 = byteString.getBytes();
 assertThat(bytes, equalTo(bytes2));
 final String base64String = byteString.toBase64String();
 final ByteString byteString1 = ByteString.ofBase64(base64String);
 assertThat(byteString, equalTo(byteString1));
}

代码示例来源:origin: Qihoo360/Quicksql

private void thereAndBack(byte[] bytes) {
 final ByteString byteString = new ByteString(bytes);
 final byte[] bytes2 = byteString.getBytes();
 assertThat(bytes, equalTo(bytes2));
 final String base64String = byteString.toBase64String();
 final ByteString byteString1 = ByteString.ofBase64(base64String);
 assertThat(byteString, equalTo(byteString1));
}

代码示例来源:origin: apache/samza

Arrays.equals(((ByteString) message.getSamzaSqlRelRecord().getField("bytes_value").get()).getBytes(),
    testBytes.array()));
Assert.assertTrue(
  Arrays.equals(((ByteString) message.getSamzaSqlRelRecord().getField("fixed_value").get()).getBytes(),
    DEFAULT_TRACKING_ID_BYTES));

代码示例来源:origin: apache/calcite-avatica

assertThat(s.getBytes().length, is(8));
assertThat(Arrays.equals(s.getBytes(), bytes), is(true));
assertThat(s.getBytes()[3], is((byte) 92));
final byte[] copyBytes = s.getBytes();
copyBytes[3] = 11;
assertThat(s.getBytes()[3], is((byte) 92));
assertThat(s, is(s2));

代码示例来源:origin: org.apache.calcite.avatica/avatica-core

assertThat(s.getBytes().length, is(8));
assertThat(Arrays.equals(s.getBytes(), bytes), is(true));
assertThat(s.getBytes()[3], is((byte) 92));
final byte[] copyBytes = s.getBytes();
copyBytes[3] = 11;
assertThat(s.getBytes()[3], is((byte) 92));
assertThat(s, is(s2));

代码示例来源:origin: org.apache.calcite/calcite-core

thereAndBack(emptyByteString.getBytes());
thereAndBack(new byte[]{10, 0, 29, -80});

代码示例来源:origin: Qihoo360/Quicksql

thereAndBack(emptyByteString.getBytes());
thereAndBack(new byte[]{10, 0, 29, -80});

相关文章