本文整理了Java中com.yahoo.text.Utf8.toBytes()
方法的一些代码示例,展示了Utf8.toBytes()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utf8.toBytes()
方法的具体详情如下:
包路径:com.yahoo.text.Utf8
类名称:Utf8
方法名:toBytes
[英]Will try an optimistic approach to utf8 encoding. That is 4.6x faster that the brute encode for ascii, not accounting for reduced memory footprint and GC.
[中]将尝试一种乐观的utf8编码方法。这比野蛮的ascii编码快4.6倍,不考虑内存占用和GC的减少。
代码示例来源:origin: com.yahoo.vespa/vespajlib
/**
* This will construct a utf8 backing of the given string.
* @param str The string that will be utf8 encoded
*/
public Utf8String(String str) {
super(Utf8.toBytes(str));
s = str;
}
代码示例来源:origin: com.yahoo.vespa/container-search
/** Utility method for turning a string into utf-8 bytes */
protected static final byte[] getBytes(String string) {
return Utf8.toBytes(string);
}
public static void putString(String s, ByteBuffer buffer) {
代码示例来源:origin: com.yahoo.vespa/vespajlib
public static byte[] createUTF8CharArray(String input) {
if (input == null || input.length() < 1) {
return new byte[0];
}
return Utf8.toBytes(input);
}
代码示例来源:origin: com.yahoo.vespa/vespajlib
/**
* Writes a string directly as-is to the stream of this.
*
* @return this for convenience
*/
private JSONWriter write(String string) throws IOException {
if (string.length() == 0) return this;
stream.write(Utf8.toBytes(string));
return this;
}
代码示例来源:origin: com.yahoo.vespa/container-search
private void encodeSummaryClass(ByteBuffer buffer) {
if (summaryClass != null) {
byte[] tmp = Utf8.toBytes(summaryClass);
buffer.putInt(tmp.length);
buffer.put(tmp);
}
}
代码示例来源:origin: com.yahoo.vespa/document
private static long makeLocation(String s) {
long result = 0;
byte[] md5sum = MD5.md5.get().digest(Utf8.toBytes(s));
for (int i=0; i<8; ++i) {
result |= (md5sum[i] & 0xFFl) << (8*i);
}
return result;
}
代码示例来源:origin: com.yahoo.vespa/standalone-container
private static Path createApplicationDirectory(String servicesXml) throws IOException {
Path applicationDir = Files.createTempDirectory("application");
Path servicesXmlFile = applicationDir.resolve("services.xml");
String content = servicesXml;
if (!servicesXml.startsWith("<?xml")) {
content = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + servicesXml;
}
Files.write(servicesXmlFile, Utf8.toBytes(content));
return applicationDir;
}
代码示例来源:origin: com.yahoo.vespa/vespajlib
@Override
public GenericWriter write(float v) throws java.io.IOException {
buffer.append(Utf8.toBytes(String.valueOf(v)));
return this;
}
代码示例来源:origin: com.yahoo.vespa/linguistics
@Override
public final Detection detect(String input, Hint hint) {
byte[] buf = Utf8.toBytes(input);
return detect(buf, 0, buf.length, hint);
}
代码示例来源:origin: com.yahoo.vespa/vespajlib
@Override
public GenericWriter write(double v) throws java.io.IOException {
buffer.append(Utf8.toBytes(String.valueOf(v)));
return this;
}
@Override
代码示例来源:origin: com.yahoo.vespa/container-search
/**
* Encodes the location to the given buffer and returns the length.
* For internal use.
*/
public int encode(ByteBuffer buffer) {
byte[] loc = Utf8.toBytes(toString());
buffer.put(loc);
return loc.length;
}
代码示例来源:origin: com.yahoo.vespa/container-core
private void internalError() {
contentType = "text/plain";
data = Utf8.toBytes("Internal error while fetching status file.\n");
setStatus(com.yahoo.jdisc.http.HttpResponse.Status.NOT_FOUND);
}
代码示例来源:origin: com.yahoo.vespa/container-core
private void fileNotFound() {
contentType = "text/plain";
data = Utf8.toBytes(COULD_NOT_FIND_STATUS_FILE);
setStatus(com.yahoo.jdisc.http.HttpResponse.Status.NOT_FOUND);
}
代码示例来源:origin: com.yahoo.vespa/vespajlib
/**
* Hashes a string, by calling hash(byte[] key,int initval) with
* the utf-8 bytes of the string as key and 0 as initval.
* Note: This is copying the string content, change implementation to
* use efficiently on large strings.
*
* bratseth
*/
public static int hash(String key) {
return hash(Utf8.toBytes(key), 0);
}
代码示例来源:origin: com.yahoo.vespa/container-core
private void accessDenied() {
contentType = "text/plain";
data = Utf8.toBytes("Status file inaccessible.\n");
setStatus(com.yahoo.jdisc.http.HttpResponse.Status.NOT_FOUND);
}
代码示例来源:origin: com.yahoo.vespa/container-core
/**
* Behaves like a VIP status response file has been deleted.
*/
private void searchContainerOutOfService() {
contentType = "text/plain";
data = Utf8.toBytes(NO_SEARCH_BACKENDS);
setStatus(com.yahoo.jdisc.http.HttpResponse.Status.NOT_FOUND);
}
代码示例来源:origin: com.yahoo.vespa/vespajlib
/** Writes this string to the buffer as a 1_4 encoded length in bytes followed by the utf8 bytes */
public void putUtf8String(String value) {
byte[] stringBytes = Utf8.toBytes(value);
putInt1_4Bytes(stringBytes.length);
put(stringBytes);
}
代码示例来源:origin: com.yahoo.vespa/vespajlib
protected void putUtf8(Serializer buf, String val) {
byte[] raw = Utf8.toBytes(val);
buf.putInt(null, raw.length);
buf.put(null, raw);
}
}
代码示例来源:origin: com.yahoo.vespa/container-search
private byte[] getSummaryClassAsUtf8() {
if (query.getPresentation().getSummary() != null) {
return Utf8.toBytes(query.getPresentation().getSummary());
}
return new byte[0];
}
代码示例来源:origin: com.yahoo.vespa/document
public static void printStringXml(StringFieldValue s, XmlStream xml) {
String content = s.getString();
if (containsNonPrintableCharactersString(content)) {
byte[] bytecontent = Utf8.toBytes(content);
xml.addAttribute("binaryencoding", "base64");
xml.addContent(new Base64(0).encodeToString(bytecontent));
} else {
xml.addContent(content);
}
}
内容来源于网络,如有侵权,请联系作者删除!