com.google.protobuf.ByteString.toString()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(536)

本文整理了Java中com.google.protobuf.ByteString.toString()方法的一些代码示例,展示了ByteString.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ByteString.toString()方法的具体详情如下:
包路径:com.google.protobuf.ByteString
类名称:ByteString
方法名:toString

ByteString.toString介绍

[英]Constructs a new String by decoding the bytes using the specified charset.
[中]

代码示例

代码示例来源:origin: com.google.protobuf/protobuf-java

/**
 * Constructs a new {@code String} by decoding the bytes as UTF-8.
 *
 * @return new string using UTF-8 encoding
 */
public final String toStringUtf8() {
 return toString(Internal.UTF_8);
}

代码示例来源:origin: osmandapp/Osmand

/**
 * Constructs a new {@code String} by decoding the bytes as UTF-8.
 *
 * @return new string using UTF-8 encoding
 */
public String toStringUtf8() {
 try {
  return toString("UTF-8");
 } catch (UnsupportedEncodingException e) {
  throw new RuntimeException("UTF-8 not supported?", e);
 }
}

代码示例来源:origin: com.google.protobuf/protobuf-java

/**
 * Constructs a new {@code String} by decoding the bytes using the
 * specified charset.
 *
 * @param charsetName encode using this charset
 * @return new string
 * @throws UnsupportedEncodingException if charset isn't recognized
 */
public final String toString(String charsetName)
  throws UnsupportedEncodingException {
 try {
  return toString(Charset.forName(charsetName));
 } catch (UnsupportedCharsetException e) {
  UnsupportedEncodingException exception = new UnsupportedEncodingException(charsetName);
  exception.initCause(e);
  throw exception;
 }
}

代码示例来源:origin: brianfrankcooper/YCSB

for (final Column column : family.getColumnsList()) {
 result.put(column.getQualifier().toString(UTF8_CHARSET), 
   new ByteArrayByteIterator(column.getCells(0).getValue().toByteArray()));
 if (debug) {
  System.out.println(
    "Result for field: " + column.getQualifier().toString(UTF8_CHARSET)
      + " is: " + column.getCells(0).getValue().toString(UTF8_CHARSET));

代码示例来源:origin: brianfrankcooper/YCSB

for (final Column column : family.getColumnsList()) {
 rowResult.put(column.getQualifier().toString(UTF8_CHARSET), 
   new ByteArrayByteIterator(column.getCells(0).getValue().toByteArray()));
 if (debug) {
  System.out.println(
    "Result for field: " + column.getQualifier().toString(UTF8_CHARSET)
      + " is: " + column.getCells(0).getValue().toString(UTF8_CHARSET));

代码示例来源:origin: yeriomin/play-store-api

/**
 * Constructs a new {@code String} by decoding the bytes as UTF-8.
 *
 * @return new string using UTF-8 encoding
 */
public final String toStringUtf8() {
 return toString(Internal.UTF_8);
}

代码示例来源:origin: com.google.protobuf/protobuf-lite

/**
 * Constructs a new {@code String} by decoding the bytes as UTF-8.
 *
 * @return new string using UTF-8 encoding
 */
public final String toStringUtf8() {
 return toString(Internal.UTF_8);
}

代码示例来源:origin: etcd-io/jetcd

public String toString(Charset charset) {
 return byteString.toString(charset);
}

代码示例来源:origin: io.etcd/jetcd-core

public String toString(Charset charset) {
 return byteString.toString(charset);
}

代码示例来源:origin: WeAreFairphone/FP2-Launcher

/**
 * Constructs a new {@code String} by decoding the bytes as UTF-8.
 *
 * @return new string using UTF-8 encoding
 */
public String toStringUtf8() {
 try {
  return toString("UTF-8");
 } catch (UnsupportedEncodingException e) {
  throw new RuntimeException("UTF-8 not supported?", e);
 }
}

代码示例来源:origin: skadistats/clarity

public static String convertByteString(ByteString s, String charsetName) {
  try {
    return s.toString(charsetName);
  } catch (UnsupportedEncodingException e) {
    Util.uncheckedThrow(e);
    return null;
  }
}

代码示例来源:origin: com.skadistats/clarity

public static String convertByteString(ByteString s, String charsetName) {
  try {
    return s.toString(charsetName);
  } catch (UnsupportedEncodingException e) {
    Util.uncheckedThrow(e);
    return null;
  }
}

代码示例来源:origin: com.google.protobuf/protobuf-lite

/**
 * Constructs a new {@code String} by decoding the bytes using the
 * specified charset.
 *
 * @param charsetName encode using this charset
 * @return new string
 * @throws UnsupportedEncodingException if charset isn't recognized
 */
public final String toString(String charsetName)
  throws UnsupportedEncodingException {
 try {
  return toString(Charset.forName(charsetName));
 } catch (UnsupportedCharsetException e) {
  UnsupportedEncodingException exception = new UnsupportedEncodingException(charsetName);
  exception.initCause(e);
  throw exception;
 }
}

代码示例来源:origin: org.openbase.bco/ontology.lib

/**
 * Method returns the state source(s) result(s) (contains state value(s)) of the input rfidState.
 *
 * @param rfidState The RFIDState.
 * @return state source(s) result(s) of the input state.
 */
private List<RdfNodeObject> rfidStateSources(final RFIDState rfidState) {
  final List<RdfNodeObject> stateSources = new ArrayList<>();
  final String rfidData = "\"" + rfidState.getData().toString()  + "\"^^xsd:string";
  stateSources.add(new RdfNodeObject(new ArrayList<String>() {{add(rfidData);}}, true));
  return stateSources;
}

代码示例来源:origin: pl.edu.icm.coansys/coansys-io-input

public static String translateToString(DocumentDTO docDTO) throws IOException {
  DocumentWrapper dw = translate(docDTO);
  return dw.toByteString().toString();
}

代码示例来源:origin: com.yoti/yoti-sdk-impl

private Object convertValueFromProto(AttrProto.Attribute attribute) throws ParseException, IOException {
  switch (attribute.getContentType()) {
    case STRING:
      return attribute.getValue().toString(DEFAULT_CHARSET);
    case DATE:
      return DateValue.parseFrom(attribute.getValue().toByteArray());
    case JPEG:
      return new JpegAttributeValue(attribute.getValue().toByteArray());
    case PNG:
      return new PngAttributeValue(attribute.getValue().toByteArray());
    case JSON:
      return JSON_MAPPER.readValue(attribute.getValue().toString(DEFAULT_CHARSET), Map.class);
    default:
      LOG.warn("Unknown type '{}' for attribute '{}'.  Attempting to parse it as a String", attribute.getContentType(), attribute.getName());
      return attribute.getValue().toString(DEFAULT_CHARSET);
  }
}

代码示例来源:origin: Longi94/JavaSteam

public FriendMsgCallback(CMsgClientFriendMsgIncoming.Builder msg) {
  sender = new SteamID(msg.getSteamidFrom());
  entryType = EChatEntryType.from(msg.getChatEntryType());
  fromLimitedAccount = msg.getFromLimitedAccount();
  if (msg.hasMessage()) {
    message = msg.getMessage().toString(Charset.forName("UTF-8"));
    message = message.replaceAll("\0+$", ""); // trim any extra null chars from the end
  }
}

代码示例来源:origin: Longi94/JavaSteam

public FriendMsgEchoCallback(CMsgClientFriendMsgIncoming.Builder msg) {
  sender = new SteamID(msg.getSteamidFrom());
  entryType = EChatEntryType.from(msg.getChatEntryType());
  fromLimitedAccount = msg.getFromLimitedAccount();
  if (msg.hasMessage()) {
    message = msg.getMessage().toString(Charset.forName("UTF-8"));
    message = message.replaceAll("\0+$", ""); // trim any extra null chars from the end
  }
}

代码示例来源:origin: stephenh/mirror

public static String toDebugString(Update u) {
 if (u == null) {
  return null;
 } else {
  ByteString truncated = ByteString.copyFromUtf8(StringUtils.abbreviate(u.getData().toString(Charsets.UTF_8), 50));
  return TextFormat.shortDebugString(Update.newBuilder(u).setData(truncated).build());
 }
}

代码示例来源:origin: Longi94/JavaSteam

@Test
public void sendChatMessage() throws UnsupportedEncodingException {
  SteamID testId = new SteamID(123456789L);
  handler.sendChatMessage(testId, EChatEntryType.ChatMsg, "testmessage");
  ClientMsgProtobuf<CMsgClientFriendMsg.Builder> msg = verifySend(EMsg.ClientFriendMsg);
  assertEquals(123456789L, msg.getBody().getSteamid());
  assertEquals("testmessage", msg.getBody().getMessage().toString("UTF-8"));
  assertEquals(EChatEntryType.ChatMsg.code(), msg.getBody().getChatEntryType());
}

相关文章