@Override public String fromByteBuffer(final ByteBuffer buffer, final int numBytes) { return StringUtils.fromUtf8(buffer, numBytes); }
@Override public String fromBytes(byte[] bytes) { return StringUtils.fromUtf8(bytes); } };
public static String fromUtf8(final ByteBuffer buffer, final int numBytes) { final byte[] bytes = new byte[numBytes]; buffer.get(bytes); return StringUtils.fromUtf8(bytes); }
public static String fromUtf8(final ByteBuffer buffer) { return StringUtils.fromUtf8(buffer, buffer.remaining()); }
@Nullable public static String decodeUserSecret(String encodedUserSecret) { try { return StringUtils.fromUtf8(Base64.getDecoder().decode(encodedUserSecret)); } catch (IllegalArgumentException iae) { return null; } }
@Override public InventoryType deserializeInventory(byte[] bytes) { try { return jsonMapper.readValue(bytes, typeReference); } catch (IOException e) { log.error(e, "Could not parse json: %s", StringUtils.fromUtf8(bytes)); throw Throwables.propagate(e); } }
@Nullable private String charsetFix(String s) { if (s != null && !enc.canEncode(s)) { // Some whacky characters are in this string (e.g. \uD900). These are problematic because they are decodeable // by new String(...) but will not encode into the same character. This dance here will replace these // characters with something more sane. return StringUtils.fromUtf8(StringUtils.toUtf8(s)); } else { return s; } }
private static String readString(DataInput in) throws IOException { byte[] result = readBytes(in); return StringUtils.fromUtf8(result); }
@Override public Object apply(JsonNode node) { if (node == null || node.isMissingNode() || node.isNull()) { return null; } if (node.isIntegralNumber()) { if (node.canConvertToLong()) { return node.asLong(); } else { return node.asDouble(); } } if (node.isFloatingPointNumber()) { return node.asDouble(); } final String s = node.asText(); final CharsetEncoder enc = Charsets.UTF_8.newEncoder(); if (s != null && !enc.canEncode(s)) { // Some whacky characters are in this string (e.g. \uD900). These are problematic because they are decodeable // by new String(...) but will not encode into the same character. This dance here will replace these // characters with something more sane. return StringUtils.fromUtf8(StringUtils.toUtf8(s)); } else { return s; } } };
eventBytes.length, MAX_EVENT_SIZE, StringUtils.fromUtf8(ByteBuffer.wrap(eventBytes), 1024) ); return null;
returnCode.get(), reasonString.get(), StringUtils.fromUtf8(baos.toByteArray()) );
returnCode.get(), reasonString.get(), StringUtils.fromUtf8(baos.toByteArray()) );