本文整理了Java中com.google.common.base.Utf8.isWellFormed()
方法的一些代码示例,展示了Utf8.isWellFormed()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utf8.isWellFormed()
方法的具体详情如下:
包路径:com.google.common.base.Utf8
类名称:Utf8
方法名:isWellFormed
[英]Returns true if bytes is a well-formed UTF-8 byte sequence according to Unicode 6.0. Note that this is a stronger criterion than simply whether the bytes can be decoded. For example, some versions of the JDK decoder will accept "non-shortest form" byte sequences, but encoding never reproduces these. Such byte sequences are not considered well-formed.
This method returns true if and only if Arrays.equals(bytes, new does, but is more efficient in both time and space.
[中]如果字节是符合Unicode 6.0的格式良好的UTF-8字节序列,则返回true。请注意,这是一个比是否可以解码字节更严格的标准。例如,一些版本的JDK解码器将接受“非最短形式”字节序列,但编码永远不会复制这些字节序列。这样的字节序列被认为格式不好。
当且仅当数组为true时,此方法返回true。equals(字节,new有,但在时间和空间上都更有效。
代码示例来源:origin: google/guava
/**
* Returns {@code true} if {@code bytes} is a <i>well-formed</i> UTF-8 byte sequence according to
* Unicode 6.0. Note that this is a stronger criterion than simply whether the bytes can be
* decoded. For example, some versions of the JDK decoder will accept "non-shortest form" byte
* sequences, but encoding never reproduces these. Such byte sequences are <i>not</i> considered
* well-formed.
*
* <p>This method returns {@code true} if and only if {@code Arrays.equals(bytes, new
* String(bytes, UTF_8).getBytes(UTF_8))} does, but is more efficient in both time and space.
*/
public static boolean isWellFormed(byte[] bytes) {
return isWellFormed(bytes, 0, bytes.length);
}
代码示例来源:origin: google/j2objc
/**
* Returns {@code true} if {@code bytes} is a <i>well-formed</i> UTF-8 byte sequence according to
* Unicode 6.0. Note that this is a stronger criterion than simply whether the bytes can be
* decoded. For example, some versions of the JDK decoder will accept "non-shortest form" byte
* sequences, but encoding never reproduces these. Such byte sequences are <i>not</i> considered
* well-formed.
*
* <p>This method returns {@code true} if and only if {@code Arrays.equals(bytes, new
* String(bytes, UTF_8).getBytes(UTF_8))} does, but is more efficient in both time and space.
*/
public static boolean isWellFormed(byte[] bytes) {
return isWellFormed(bytes, 0, bytes.length);
}
代码示例来源:origin: wildfly/wildfly
/**
* Returns {@code true} if {@code bytes} is a <i>well-formed</i> UTF-8 byte sequence according to
* Unicode 6.0. Note that this is a stronger criterion than simply whether the bytes can be
* decoded. For example, some versions of the JDK decoder will accept "non-shortest form" byte
* sequences, but encoding never reproduces these. Such byte sequences are <i>not</i> considered
* well-formed.
*
* <p>This method returns {@code true} if and only if {@code Arrays.equals(bytes, new
* String(bytes, UTF_8).getBytes(UTF_8))} does, but is more efficient in both time and space.
*/
public static boolean isWellFormed(byte[] bytes) {
return isWellFormed(bytes, 0, bytes.length);
}
代码示例来源:origin: google/guava
private static void assertWellFormed(int... bytes) {
assertTrue(Utf8.isWellFormed(toByteArray(bytes)));
}
代码示例来源:origin: google/guava
private static void assertNotWellFormed(int... bytes) {
assertFalse(Utf8.isWellFormed(toByteArray(bytes)));
}
代码示例来源:origin: google/guava
tmpByteChar = tmpByteChar >> 8;
boolean isRoundTrippable = Utf8.isWellFormed(bytes);
assertEquals(isRoundTrippable, Utf8.isWellFormed(bytes, 0, numBytes));
String s = new String(bytes, Charsets.UTF_8);
byte[] bytesReencoded = s.getBytes(Charsets.UTF_8);
代码示例来源:origin: lenskit/lenskit
/**
* Create a new Text instance from bytes.
* @param bytes The bytes (must be valid UTF-8). The array of bytes is copied.
*/
public Text(byte[] bytes) {
Preconditions.checkArgument(Utf8.isWellFormed(bytes), "input bytes must be UTF-8");
data = Arrays.copyOf(bytes, bytes.length);
}
代码示例来源:origin: org.jboss.eap/wildfly-client-all
/**
* Returns {@code true} if {@code bytes} is a <i>well-formed</i> UTF-8 byte sequence according to
* Unicode 6.0. Note that this is a stronger criterion than simply whether the bytes can be
* decoded. For example, some versions of the JDK decoder will accept "non-shortest form" byte
* sequences, but encoding never reproduces these. Such byte sequences are <i>not</i> considered
* well-formed.
*
* <p>This method returns {@code true} if and only if {@code Arrays.equals(bytes, new
* String(bytes, UTF_8).getBytes(UTF_8))} does, but is more efficient in both time and space.
*/
public static boolean isWellFormed(byte[] bytes) {
return isWellFormed(bytes, 0, bytes.length);
}
代码示例来源:origin: org.kill-bill.billing/killbill-platform-osgi-bundles-logger
/**
* Returns {@code true} if {@code bytes} is a <i>well-formed</i> UTF-8 byte sequence according to
* Unicode 6.0. Note that this is a stronger criterion than simply whether the bytes can be
* decoded. For example, some versions of the JDK decoder will accept "non-shortest form" byte
* sequences, but encoding never reproduces these. Such byte sequences are <i>not</i> considered
* well-formed.
*
* <p>This method returns {@code true} if and only if {@code Arrays.equals(bytes, new
* String(bytes, UTF_8).getBytes(UTF_8))} does, but is more efficient in both time and space.
*/
public static boolean isWellFormed(byte[] bytes) {
return isWellFormed(bytes, 0, bytes.length);
}
代码示例来源:origin: com.google.guava/guava-jdk5
/**
* Returns {@code true} if {@code bytes} is a <i>well-formed</i> UTF-8 byte sequence according to
* Unicode 6.0. Note that this is a stronger criterion than simply whether the bytes can be
* decoded. For example, some versions of the JDK decoder will accept "non-shortest form" byte
* sequences, but encoding never reproduces these. Such byte sequences are <i>not</i> considered
* well-formed.
*
* <p>This method returns {@code true} if and only if {@code Arrays.equals(bytes, new
* String(bytes, UTF_8).getBytes(UTF_8))} does, but is more efficient in both time and space.
*/
public static boolean isWellFormed(byte[] bytes) {
return isWellFormed(bytes, 0, bytes.length);
}
代码示例来源:origin: Nextdoor/bender
/**
* Returns {@code true} if {@code bytes} is a <i>well-formed</i> UTF-8 byte sequence according to
* Unicode 6.0. Note that this is a stronger criterion than simply whether the bytes can be
* decoded. For example, some versions of the JDK decoder will accept "non-shortest form" byte
* sequences, but encoding never reproduces these. Such byte sequences are <i>not</i> considered
* well-formed.
*
* <p>This method returns {@code true} if and only if {@code Arrays.equals(bytes, new
* String(bytes, UTF_8).getBytes(UTF_8))} does, but is more efficient in both time and space.
*/
public static boolean isWellFormed(byte[] bytes) {
return isWellFormed(bytes, 0, bytes.length);
}
代码示例来源:origin: com.diffplug.guava/guava-core
/**
* Returns {@code true} if {@code bytes} is a <i>well-formed</i> UTF-8 byte sequence according to
* Unicode 6.0. Note that this is a stronger criterion than simply whether the bytes can be
* decoded. For example, some versions of the JDK decoder will accept "non-shortest form" byte
* sequences, but encoding never reproduces these. Such byte sequences are <i>not</i> considered
* well-formed.
*
* <p>This method returns {@code true} if and only if {@code Arrays.equals(bytes, new
* String(bytes, UTF_8).getBytes(UTF_8))} does, but is more efficient in both time and space.
*/
@CheckReturnValue
public static boolean isWellFormed(byte[] bytes) {
return isWellFormed(bytes, 0, bytes.length);
}
代码示例来源:origin: org.lenskit/lenskit-core
/**
* Create a new Text instance from bytes.
* @param bytes The bytes (must be valid UTF-8). The array of bytes is copied.
*/
public Text(byte[] bytes) {
Preconditions.checkArgument(Utf8.isWellFormed(bytes), "input bytes must be UTF-8");
data = Arrays.copyOf(bytes, bytes.length);
}
代码示例来源: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: dCache/nfs4j
/**
* Validate path and convert into UTB8 {@link String}.
*
* @param bytes to convert
* @return string
* @throws ChimeraNFSException if provided {@code bytes} are not a UTF8
* encoded.
*/
public static String convertPath(byte[] bytes) throws ChimeraNFSException {
if (!Utf8.isWellFormed(bytes)) {
throw new InvalException("invalid utf8 name");
}
String name = new String(bytes, UTF8);
if (name.length() == 0) {
throw new InvalException("bad path name");
}
if (name.indexOf('\0') != -1) {
throw new BadNameException("name with null");
}
return name;
}
}
代码示例来源:origin: com.google.guava/guava-tests
private static void assertWellFormed(int... bytes) {
assertTrue(Utf8.isWellFormed(toByteArray(bytes)));
}
代码示例来源:origin: com.google.guava/guava-tests
private static void assertNotWellFormed(int... bytes) {
assertFalse(Utf8.isWellFormed(toByteArray(bytes)));
}
代码示例来源:origin: com.google.guava/guava-tests
tmpByteChar = tmpByteChar >> 8;
boolean isRoundTrippable = Utf8.isWellFormed(bytes);
assertEquals(isRoundTrippable, Utf8.isWellFormed(bytes, 0, numBytes));
String s = new String(bytes, Charsets.UTF_8);
byte[] bytesReencoded = s.getBytes(Charsets.UTF_8);
内容来源于网络,如有侵权,请联系作者删除!