/** * 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; }
public static String decode(byte[] data, int pos, int len) { return Utf8.toString(data, pos, len); } public static byte[] encode(String str) {
static Charset charset(String contentType) { if (contentType != null) { Matcher matcher = charsetPattern.matcher(contentType); if (matcher.find()) { try { return Charset.forName(matcher.group(1)); } catch (UnsupportedCharsetException uce) { return Utf8.getCharset(); } } } return Utf8.getCharset(); }
/** * 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)); }
buf.get(stringArray); value.setUnChecked(Utf8.toString(stringArray)); stringPositions = calculateStringPositions(stringArray);
/** * Count the number of bytes needed to represent a given sequence of 16-bit * char values as a UTF-8 encoded array. This method is written to be cheap * to invoke. * * Note: It is strongly assumed to character sequence is valid. */ public static int byteCount(CharSequence str) { return byteCount(str, 0, str.length()); }
buf.get(stringArray); value.setUnChecked(Utf8.toString(stringArray)); stringPositions = calculateStringPositions(stringArray);
public int getSerializedSize() { int size = 0; if (docId != null) { size += Utf8.byteCount(docId.toString()) + 1; } size += GlobalId.LENGTH; size += 8; size += 1; return size; }
/** 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) {
@Override public Detection detect(String input, Hint hint) { return new Detection(guessLanguage(input), Utf8.getCharset().name(), false); }
public LowercaseIdentifier(String s) { this(Utf8.toBytes(s)); } public LowercaseIdentifier(AbstractUtf8Array utf8) {
/** * 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); }
@Override public Detection detect(String input, Hint hint) { return new Detection(guessLanguage(input), Utf8.getCharset().name(), false); }
public Identifier(String s) { this(Utf8.toBytes(s)); } public Identifier(AbstractUtf8Array utf8) {
public void decodeBody(ByteBuffer buffer) { errorCode = buffer.getInt(); errmsgLen = buffer.getInt(); byte[] tmp = new byte[errmsgLen]; buffer.get(tmp); message = Utf8.toString(tmp); }
if (!path.exists()) return; if (fullPathNames) { digest.update(path.getPath().getBytes(Utf8.getCharset())); } else { digest.update(path.getName().getBytes(Utf8.getCharset()));
public static byte[] encode(String str) { return Utf8.toBytes(str); } }
private Language guessLanguage(byte[] buf, int offset, int length) { return guessLanguage(Utf8.toString(buf, offset, length)); }
return Utf8.getCharset().name(); } else if (!hasHighs) { return "US-ASCII";