本文整理了Java中org.apache.calcite.avatica.util.ByteString.<init>()
方法的一些代码示例,展示了ByteString.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteString.<init>()
方法的具体详情如下:
包路径:org.apache.calcite.avatica.util.ByteString
类名称:ByteString
方法名:<init>
[英]Creates a ByteString.
[中]创建一个ByteString。
代码示例来源:origin: org.apache.calcite.avatica/avatica-core
/**
* Returns a ByteString that consists of a given range.
*
* @param start Start of range
* @param end Position after end of range
* @return Substring
*/
public ByteString substring(int start, int end) {
byte[] bytes = Arrays.copyOfRange(this.bytes, start, end);
return new ByteString(bytes, false);
}
代码示例来源:origin: apache/calcite-avatica
/**
* Returns a ByteString that consists of a given range.
*
* @param start Start of range
* @param end Position after end of range
* @return Substring
*/
public ByteString substring(int start, int end) {
byte[] bytes = Arrays.copyOfRange(this.bytes, start, end);
return new ByteString(bytes, false);
}
代码示例来源:origin: org.apache.calcite/calcite-avatica
/**
* Returns a ByteString that consists of a given range.
*
* @param start Start of range
* @param end Position after end of range
* @return Substring
*/
public ByteString substring(int start, int end) {
byte[] bytes = Arrays.copyOfRange(this.bytes, start, end);
return new ByteString(bytes, false);
}
代码示例来源:origin: org.apache.calcite/calcite-avatica
/**
* Creates a byte string from a Base64 string.
*
* @param string Base64 string
* @return Byte string
*/
public static ByteString ofBase64(String string) {
final byte[] bytes = parseBase64(string);
return new ByteString(bytes, false);
}
代码示例来源:origin: apache/calcite-avatica
/**
* Creates a byte string from a Base64 string.
*
* @param string Base64 string
* @return Byte string
*/
public static ByteString ofBase64(String string) {
final byte[] bytes = parseBase64(string);
return new ByteString(bytes, false);
}
代码示例来源:origin: org.apache.calcite.avatica/avatica-core
/**
* Creates a byte string from a Base64 string.
*
* @param string Base64 string
* @return Byte string
*/
public static ByteString ofBase64(String string) {
final byte[] bytes = parseBase64(string);
return new ByteString(bytes, false);
}
代码示例来源:origin: org.apache.calcite.avatica/avatica-core
/**
* Creates a byte string from a hexadecimal or binary string.
*
* <p>For example, <code>of("DEAD", 16)</code>
* returns the same as {@code ByteString(new byte[] {0xDE, 0xAD})}.
*
* @param string Array of bytes
* @param base Base (2 or 16)
* @return String
*/
public static ByteString of(String string, int base) {
final byte[] bytes = parse(string, base);
return new ByteString(bytes, false);
}
代码示例来源:origin: org.apache.calcite/calcite-avatica
/**
* Creates a byte string from a hexadecimal or binary string.
*
* <p>For example, <tt>of("DEAD", 16)</tt>
* returns the same as {@code ByteString(new byte[] {0xDE, 0xAD})}.
*
* @param string Array of bytes
* @param base Base (2 or 16)
* @return String
*/
public static ByteString of(String string, int base) {
final byte[] bytes = parse(string, base);
return new ByteString(bytes, false);
}
代码示例来源:origin: apache/calcite-avatica
/**
* Creates a byte string from a hexadecimal or binary string.
*
* <p>For example, <code>of("DEAD", 16)</code>
* returns the same as {@code ByteString(new byte[] {0xDE, 0xAD})}.
*
* @param string Array of bytes
* @param base Base (2 or 16)
* @return String
*/
public static ByteString of(String string, int base) {
final byte[] bytes = parse(string, base);
return new ByteString(bytes, false);
}
代码示例来源: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: Qihoo360/Quicksql
/** Helper for CAST(... AS BINARY(maxLength)). */
public static ByteString truncateOrPad(ByteString s, int maxLength) {
if (s == null) {
return null;
} else {
final int length = s.length();
if (length > maxLength) {
return s.substring(0, maxLength);
} else if (length < maxLength) {
return s.concat(new ByteString(new byte[maxLength - length]));
} else {
return s;
}
}
}
代码示例来源:origin: org.apache.calcite/calcite-core
/** Helper for CAST(... AS BINARY(maxLength)). */
public static ByteString truncateOrPad(ByteString s, int maxLength) {
if (s == null) {
return null;
} else {
final int length = s.length();
if (length > maxLength) {
return s.substring(0, maxLength);
} else if (length < maxLength) {
return s.concat(new ByteString(new byte[maxLength - length]));
} else {
return s;
}
}
}
代码示例来源:origin: org.apache.kylin/atopcalcite
/** Helper for CAST(... AS BINARY(maxLength)). */
public static ByteString truncateOrPad(ByteString s, int maxLength) {
if (s == null) {
return null;
} else {
final int length = s.length();
if (length > maxLength) {
return s.substring(0, maxLength);
} else if (length < maxLength) {
return s.concat(new ByteString(new byte[maxLength - length]));
} else {
return s;
}
}
}
代码示例来源:origin: org.apache.calcite.avatica/avatica-core
@Test public void testByteString() {
serializeAndEqualityCheck(
TypedValue.ofLocal(Rep.BYTE_STRING,
new ByteString("qwertyasdf".getBytes(UTF_8))));
}
代码示例来源:origin: org.apache.calcite/calcite-avatica
@Test
public void testByteString() {
serializeAndEqualityCheck(
TypedValue.ofLocal(Rep.BYTE_STRING,
new ByteString("qwertyasdf".getBytes(StandardCharsets.UTF_8))));
}
代码示例来源:origin: apache/calcite-avatica
@Test public void testByteString() {
serializeAndEqualityCheck(
TypedValue.ofLocal(Rep.BYTE_STRING,
new ByteString("qwertyasdf".getBytes(UTF_8))));
}
代码示例来源: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: org.apache.calcite.avatica/avatica-core
@Test public void testBase64() {
byte[] bytes = "qwertyasdf".getBytes(UTF_8);
// Plain bytes get put into protobuf for simplicitly
Common.TypedValue proto = Common.TypedValue.newBuilder().setBytesValue(
com.google.protobuf.ByteString.copyFrom(bytes))
.setType(Common.Rep.BYTE_STRING).build();
// But we should get back a b64-string to make sure TypedValue doesn't get confused.
Object deserializedObj = TypedValue.getSerialFromProto(proto);
assertThat(deserializedObj, is(instanceOf(String.class)));
assertEquals(new ByteString(bytes).toBase64String(), (String) deserializedObj);
// But we should get a non-b64 byte array as the JDBC representation
deserializedObj =
TypedValue.protoToJdbc(proto, DateTimeUtils.calendar());
assertThat(deserializedObj, is(instanceOf(byte[].class)));
assertArrayEquals(bytes, (byte[]) deserializedObj);
}
内容来源于网络,如有侵权,请联系作者删除!