本文整理了Java中com.google.protobuf.ByteString.isValidUtf8()
方法的一些代码示例,展示了ByteString.isValidUtf8()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteString.isValidUtf8()
方法的具体详情如下:
包路径:com.google.protobuf.ByteString
类名称:ByteString
方法名:isValidUtf8
[英]Tells whether this ByteString represents a well-formed UTF-8 byte sequence, such that the original bytes can be converted to a String object and then round tripped back to bytes without loss.
More precisely, returns true whenever:
Arrays.equals(byteString.toByteArray(),
This method returns false for "overlong" byte sequences, as well as for 3-byte sequences that would map to a surrogate character, in accordance with the restricted definition of UTF-8 introduced in Unicode 3.1. Note that the UTF-8 decoder included in Oracle's JDK has been modified to also reject "overlong" byte sequences, but (as of 2011) still accepts 3-byte surrogate character byte sequences.
See the Unicode Standard,
Table 3-6. UTF-8 Bit Distribution,
Table 3-7. Well Formed UTF-8 Byte Sequences.
[中]说明此ByteString是否表示格式良好的UTF-8字节序列,以便可以将原始字节转换为字符串对象,然后在不丢失的情况下返回字节。
更准确地说,在以下情况下,返回true:
Arrays.equals(byteString.toByteArray(),
根据Unicode 3.1中引入的UTF-8受限定义,对于“超长”字节序列以及映射到代理字符的3字节序列,此方法返回false。请注意,Oracle JDK中包含的UTF-8解码器已修改为也拒绝“过长”字节序列,但(截至2011年)仍接受3字节代理字符字节序列。
参见Unicode标准,
表3-6UTF-8位分布,
表3-7格式良好的UTF-8字节序列。
代码示例来源:origin: bazelbuild/bazel
/**
* <code>optional string default_string = 5;</code>
*/
public java.lang.String getDefaultString() {
java.lang.Object ref = defaultString_;
if (ref instanceof java.lang.String) {
return (java.lang.String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
defaultString_ = s;
}
return s;
}
}
/**
代码示例来源:origin: bazelbuild/bazel
/**
* <code>optional string default_string = 5;</code>
*/
public java.lang.String getDefaultString() {
java.lang.Object ref = defaultString_;
if (!(ref instanceof java.lang.String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
java.lang.String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
defaultString_ = s;
}
return s;
} else {
return (java.lang.String) ref;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string key = 1;</code>
*/
public String getKey() {
Object ref = key_;
if (ref instanceof String) {
return (String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
key_ = s;
}
return s;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string value = 2;</code>
*/
public String getValue() {
Object ref = value_;
if (ref instanceof String) {
return (String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
value_ = s;
}
return s;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string value = 2;</code>
*/
public String getValue() {
Object ref = value_;
if (!(ref instanceof String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
value_ = s;
}
return s;
} else {
return (String) ref;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string key = 1;</code>
*/
public String getKey() {
Object ref = key_;
if (!(ref instanceof String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
key_ = s;
}
return s;
} else {
return (String) ref;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string gtid = 13;</code>
*
* <pre>
**当前事务的gitd*
* </pre>
*/
public String getGtid() {
Object ref = gtid_;
if (!(ref instanceof String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
gtid_ = s;
}
return s;
} else {
return (String) ref;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string ddlSchemaName = 14;</code>
*
* <pre>
** ddl/query的schemaName,会存在跨库ddl,需要保留执行ddl的当前schemaName *
* </pre>
*/
public String getDdlSchemaName() {
Object ref = ddlSchemaName_;
if (!(ref instanceof String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
ddlSchemaName_ = s;
}
return s;
} else {
return (String) ref;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string transactionId = 2;</code>
*
* <pre>
**事务号*
* </pre>
*/
public String getTransactionId() {
Object ref = transactionId_;
if (!(ref instanceof String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
transactionId_ = s;
}
return s;
} else {
return (String) ref;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string logfileName = 2;</code>
*
* <pre>
**binlog/redolog 文件名*
* </pre>
*/
public String getLogfileName() {
Object ref = logfileName_;
if (ref instanceof String) {
return (String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
logfileName_ = s;
}
return s;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string logfileName = 2;</code>
*
* <pre>
**binlog/redolog 文件名*
* </pre>
*/
public String getLogfileName() {
Object ref = logfileName_;
if (!(ref instanceof String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
logfileName_ = s;
}
return s;
} else {
return (String) ref;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string tableName = 9;</code>
*
* <pre>
**变更数据的tablename*
* </pre>
*/
public String getTableName() {
Object ref = tableName_;
if (!(ref instanceof String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
tableName_ = s;
}
return s;
} else {
return (String) ref;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string value = 8;</code>
*
* <pre>
** 字段值,timestamp,Datetime是一个时间格式的文本 *
* </pre>
*/
public String getValue() {
Object ref = value_;
if (!(ref instanceof String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
value_ = s;
}
return s;
} else {
return (String) ref;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string sql = 11;</code>
*
* <pre>
** ddl/query的sql语句 *
* </pre>
*/
public String getSql() {
Object ref = sql_;
if (!(ref instanceof String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
sql_ = s;
}
return s;
} else {
return (String) ref;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string serverenCode = 5;</code>
*
* <pre>
** 变更数据的编码 *
* </pre>
*/
public String getServerenCode() {
Object ref = serverenCode_;
if (!(ref instanceof String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
serverenCode_ = s;
}
return s;
} else {
return (String) ref;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string name = 3;</code>
*
* <pre>
**字段名称(忽略大小写),在mysql中是没有的*
* </pre>
*/
public String getName() {
Object ref = name_;
if (ref instanceof String) {
return (String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
name_ = s;
}
return s;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string mysqlType = 10;</code>
*
* <pre>
**字段mysql类型*
* </pre>
*/
public String getMysqlType() {
Object ref = mysqlType_;
if (ref instanceof String) {
return (String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
mysqlType_ = s;
}
return s;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string name = 3;</code>
*
* <pre>
**字段名称(忽略大小写),在mysql中是没有的*
* </pre>
*/
public String getName() {
Object ref = name_;
if (!(ref instanceof String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
name_ = s;
}
return s;
} else {
return (String) ref;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string mysqlType = 10;</code>
*
* <pre>
**字段mysql类型*
* </pre>
*/
public String getMysqlType() {
Object ref = mysqlType_;
if (!(ref instanceof String)) {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
mysqlType_ = s;
}
return s;
} else {
return (String) ref;
}
}
/**
代码示例来源:origin: alibaba/canal
/**
* <code>optional string sql = 11;</code>
*
* <pre>
** ddl/query的sql语句 *
* </pre>
*/
public String getSql() {
Object ref = sql_;
if (ref instanceof String) {
return (String) ref;
} else {
com.google.protobuf.ByteString bs =
(com.google.protobuf.ByteString) ref;
String s = bs.toStringUtf8();
if (bs.isValidUtf8()) {
sql_ = s;
}
return s;
}
}
/**
内容来源于网络,如有侵权,请联系作者删除!