public static String decode(byte[] data, int pos, int len) { return Utf8.toString(data, pos, len); } public static byte[] encode(String str) {
/** * 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)); }
/** * 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); }
public void decodeBody(ByteBuffer buffer) { errorCode = buffer.getInt(); errmsgLen = buffer.getInt(); byte[] tmp = new byte[errmsgLen]; buffer.get(tmp); message = Utf8.toString(tmp); }
public Language guessLanguage(byte[] buf, int offset, int length) { return guessLanguage(Utf8.toString(buf, offset, length)); }
private Language guessLanguage(byte[] buf, int offset, int length) { return guessLanguage(Utf8.toString(buf, offset, length)); }
@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; }
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; } } } }
protected String getUtf8(Deserializer buf) { int len = buf.getInt(null); byte[] arr = buf.getBytes(null, len); return Utf8.toString(arr); }
/** 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); }
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); } }
@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; } } }
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()); }
/** * 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)); }
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)); } }
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(); }
/** * Will convert the utf8 sequence to a Java string * @return The converted Java String */ @Override public String toString() { return Utf8.toString(getBytes(), getByteOffset(), getByteLength()); }
buf.get(stringArray); value.setUnChecked(Utf8.toString(stringArray));
buf.get(stringArray); value.setUnChecked(Utf8.toString(stringArray));