本文整理了Java中com.yahoo.text.Utf8.toString()
方法的一些代码示例,展示了Utf8.toString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utf8.toString()
方法的具体详情如下:
包路径:com.yahoo.text.Utf8
类名称:Utf8
方法名:toString
[英]Fetch a string from a ByteBuffer instance. ByteBuffer instances are stateful, so it is assumed to caller manipulates the instance's limit if the entire buffer is not a string.
[中]从ByteBuffer实例获取字符串。ByteBuffer实例是有状态的,因此如果整个缓冲区不是字符串,则假定调用者操纵实例的限制。
代码示例来源:origin: com.yahoo.vespa/vespajlib
public static String decode(byte[] data, int pos, int len) {
return Utf8.toString(data, pos, len);
}
public static byte[] encode(String str) {
代码示例来源:origin: com.yahoo.vespa/vespajlib
/**
* Utility method as toString(byte[]).
*
* @param data
* bytes to decode
* @param offset
* index of first byte to decode
* @param length
* number of bytes to decode
* @return String decoded from UTF-8
*/
public static String toString(byte[] data, int offset, int length) {
String s = toStringAscii(data, offset, length);
return s != null ? s : toString(ByteBuffer.wrap(data, offset, length));
}
代码示例来源:origin: com.yahoo.vespa/container-search
public Entry(byte[] k, byte[] v) {
key = Utf8.toString(k);
val = Utf8.toString(v);
}
};
代码示例来源:origin: com.yahoo.vespa/vespalog
/**
* return the current state as a string
* (directly fetched from the file via the mapping buffer)
**/
public String getOnOffString() {
byte[] levels = new byte[4 * VespaLevelControllerRepo.numLevels];
for (int i = 0; i < levels.length; i++) {
levels[i] = mapBuf.get(offset + i);
}
return Utf8.toString(levels);
}
代码示例来源:origin: com.yahoo.vespa/container-search
public void decodeBody(ByteBuffer buffer) {
errorCode = buffer.getInt();
errmsgLen = buffer.getInt();
byte[] tmp = new byte[errmsgLen];
buffer.get(tmp);
message = Utf8.toString(tmp);
}
代码示例来源:origin: com.yahoo.vespa/linguistics
public Language guessLanguage(byte[] buf, int offset, int length) {
return guessLanguage(Utf8.toString(buf, offset, length));
}
代码示例来源:origin: com.yahoo.vespa/linguistics
private Language guessLanguage(byte[] buf, int offset, int length) {
return guessLanguage(Utf8.toString(buf, offset, length));
}
代码示例来源:origin: com.yahoo.vespa/messagebus
@Override
public Routable decode(Version version, byte[] data) {
String str = Utf8.toString(data);
if (str.length() < 1) {
return null;
}
char c = str.charAt(0);
if (c == 'M') {
return new SimpleMessage(str.substring(1));
}
if (c == 'R') {
return new SimpleReply(str.substring(1));
}
return null;
}
代码示例来源:origin: com.yahoo.vespa/vespajlib
private String readKey() {
buf.reset();
switch (c) {
case '"': case '\'': return readString();
default:
for (;;) {
switch (c) {
case ':': case ' ': case '\t': case '\n': case '\r': case '\0': return Utf8.toString(buf.toByteArray());
default:
buf.write(c);
next();
break;
}
}
}
}
代码示例来源:origin: com.yahoo.vespa/vespajlib
protected String getUtf8(Deserializer buf) {
int len = buf.getInt(null);
byte[] arr = buf.getBytes(null, len);
return Utf8.toString(arr);
}
代码示例来源:origin: com.yahoo.vespa/vespajlib
/** Reads a string from the buffer as a 1_4 encoded length in bytes followed by the utf8 bytes */
public String getUtf8String() {
int stringLength = getInt1_4Bytes();
byte[] stringBytes = new byte[stringLength];
get(stringBytes);
return Utf8.toString(stringBytes);
}
代码示例来源:origin: com.yahoo.vespa/container-search
void decode(ByteBuffer buffer) {
int nameLen = buffer.getInt();
byte[] utf8name = new byte[nameLen];
buffer.get(utf8name);
this.setName(Utf8.toString(utf8name));
int n = buffer.getInt();
setEntries(new Entry[n]);
for (int j = 0; j < n; j++) {
int keyLen = buffer.getInt();
byte[] key = new byte[keyLen];
buffer.get(key);
int valLen = buffer.getInt();
byte[] value = new byte[valLen];
buffer.get(value);
getEntries()[j] = new Entry(key, value);
}
}
代码示例来源:origin: com.yahoo.vespa/vespajlib
@SuppressWarnings("fallthrough")
private void decodeNumber(Inserter inserter) {
buf.reset();
boolean likelyFloatingPoint=false;
for (;;) {
switch (c) {
case '.': case 'e': case 'E':
likelyFloatingPoint = true;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
case '+': case '-':
buf.write(c);
next();
break;
default:
if (likelyFloatingPoint) {
double num = Double.parseDouble(Utf8.toString(buf.toByteArray()));
inserter.insertDOUBLE(num);
} else {
long num = Long.parseLong(Utf8.toString(buf.toByteArray()));
inserter.insertLONG(num);
}
return;
}
}
}
代码示例来源:origin: com.yahoo.vespa/docproc
private void logProgress(Processing processing, DocumentProcessor.Progress progress, Call call) {
StringBuilder message = new StringBuilder();
boolean first = true;
message.append(call.getDocumentProcessorId()).append(" of class ")
.append(call.getDocumentProcessor().getClass().getSimpleName()).append(" returned ").append(progress)
.append(" for the documents: [");
for (DocumentOperation op : processing.getDocumentOperations()) {
if (first) {
first = false;
} else {
message.append(", ");
}
if (op instanceof DocumentPut) {
message.append(Utf8.toString(JsonWriter.toByteArray(((DocumentPut) op).getDocument())));
} else {
message.append(op.toString());
}
}
message.append("]");
log.log(LogLevel.SPAM, message.toString());
}
代码示例来源:origin: com.yahoo.vespa/documentapi
/**
* Reads a string from the given buffer that was previously written by {@link #encodeString(String,
* com.yahoo.vespa.objects.Serializer)}.
*
* @param in The byte buffer to read from.
* @return The decoded string.
*/
public static String decodeString(Deserializer in) {
int length = in.getInt(null);
if (length == 0) {
return "";
}
return Utf8.toString(in.getBytes(null, length));
}
代码示例来源:origin: com.yahoo.vespa/document
private void assignPositionFieldFromStringIfNonEmpty(Struct value, String elementText, boolean base64) {
String str = base64 ? Utf8.toString(new Base64().decode(elementText)) : elementText;
str = str.trim();
if (str.isEmpty()) {
return;
}
DataType valueType = value.getDataType();
if (valueType.equals(PositionDataType.INSTANCE)) {
value.assign(PositionDataType.fromString(str));
}
}
代码示例来源:origin: com.yahoo.vespa/vespajlib
public String getString(FieldBase field) {
int length = getInt(null);
byte[] stringArray = new byte[length-1];
buf.get(stringArray);
getByte(null);
return Utf8.toString(stringArray);
}
public int getInt1_4Bytes(FieldBase field) { return buf.getInt1_4Bytes(); }
代码示例来源:origin: com.yahoo.vespa/vespajlib
/**
* Will convert the utf8 sequence to a Java string
* @return The converted Java String
*/
@Override
public String toString() {
return Utf8.toString(getBytes(), getByteOffset(), getByteLength());
}
代码示例来源:origin: com.yahoo.vespa/document
buf.get(stringArray);
value.setUnChecked(Utf8.toString(stringArray));
代码示例来源:origin: com.yahoo.vespa/document
buf.get(stringArray);
value.setUnChecked(Utf8.toString(stringArray));
内容来源于网络,如有侵权,请联系作者删除!