Java Code Examples for com.google.protobuf.ByteString#toString()

The following examples show how to use com.google.protobuf.ByteString#toString() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SeriesKeyEncoding.java    From heroic with Apache License 2.0 6 votes vote down vote up
public SeriesKey decode(ByteString key, Transform<String, Series> transform) throws Exception {
    final String string = key.toString(Charsets.UTF_8);
    final List<String> parts = SPLITTER.splitToList(string);

    if (parts.size() != 3) {
        throw new IllegalArgumentException("Not a valid key: " + string);
    }

    final String category = parts.get(0);

    if (!this.category.equals(category)) {
        throw new IllegalArgumentException(
            "Key is in the wrong category (expected " + this.category + "): " + string);
    }

    final LocalDate date = LocalDate.parse(parts.get(1));
    final Series series = transform.transform(parts.get(2));
    return new SeriesKey(date, series);
}
 
Example 2
Source File: Util.java    From clarity with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static String convertByteString(ByteString s, String charsetName) {
    try {
        return s.toString(charsetName);
    } catch (UnsupportedEncodingException e) {
        Util.uncheckedThrow(e);
        return null;
    }
}
 
Example 3
Source File: U2MessageTextHandler.java    From wind-im with Apache License 2.0 4 votes vote down vote up
public Boolean handle(Command command) {
	try {
		int type = command.getMsgType();

		if (CoreProto.MsgType.TEXT_VALUE == type) {
			ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest
					.parseFrom(command.getParams());
			String siteUserId = command.getSiteUserId();
			String proxySiteUserId = request.getText().getSiteUserId();
			String siteFriendId = request.getText().getSiteFriendId();
			String msgId = request.getText().getMsgId();
			ByteString byteStr = request.getText().getText();
			String msgText = byteStr.toString(Charset.forName("UTF-8"));
			command.setSiteFriendId(siteFriendId);

			long msgTime = System.currentTimeMillis();
			U2MessageBean u2Bean = new U2MessageBean();
			u2Bean.setMsgId(msgId);
			u2Bean.setMsgType(type);
			u2Bean.setSiteUserId(siteFriendId);
			u2Bean.setSendUserId(command.isProxy() ? proxySiteUserId : siteUserId);
			u2Bean.setReceiveUserId(siteFriendId);
			u2Bean.setContent(msgText);
			u2Bean.setMsgTime(msgTime);

			LogUtils.requestDebugLog(logger, command, u2Bean.toString());

			boolean success = messageDao.saveU2Message(u2Bean);

			if (success && command.isProxy()) {
				U2MessageBean proxyBean = new U2MessageBean();
				proxyBean.setMsgId(buildU2MsgId(proxySiteUserId));
				proxyBean.setMsgType(type);
				proxyBean.setSiteUserId(proxySiteUserId);
				proxyBean.setSendUserId(proxySiteUserId);
				proxyBean.setReceiveUserId(siteFriendId);
				proxyBean.setContent(msgText);
				proxyBean.setMsgTime(msgTime);
				messageDao.saveU2Message(proxyBean);
			}

			msgStatusResponse(command, msgId, msgTime, success);

			return success;
		}

		return true;
	} catch (Exception e) {
		LogUtils.requestErrorLog(logger, command, this.getClass(), e);
	}

	return false;
}
 
Example 4
Source File: U2MessageTextHandler.java    From openzaly with Apache License 2.0 4 votes vote down vote up
public Boolean handle(Command command) {
	try {
		int type = command.getMsgType();

		if (CoreProto.MsgType.TEXT_VALUE == type) {
			ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest
					.parseFrom(command.getParams());
			String siteUserId = command.getSiteUserId();
			String proxySiteUserId = request.getText().getSiteUserId();
			String siteFriendId = request.getText().getSiteFriendId();
			String msgId = request.getText().getMsgId();
			ByteString byteStr = request.getText().getText();
			String msgText = byteStr.toString(Charset.forName("UTF-8"));
			command.setSiteFriendId(siteFriendId);

			long msgTime = System.currentTimeMillis();
			U2MessageBean u2Bean = new U2MessageBean();
			u2Bean.setMsgId(msgId);
			u2Bean.setMsgType(type);
			u2Bean.setSiteUserId(siteFriendId);
			u2Bean.setSendUserId(command.isProxy() ? proxySiteUserId : siteUserId);
			u2Bean.setReceiveUserId(siteFriendId);
			u2Bean.setContent(msgText);
			u2Bean.setMsgTime(msgTime);

			LogUtils.requestDebugLog(logger, command, u2Bean.toString());

			boolean success = messageDao.saveU2Message(u2Bean);

			if (success && command.isProxy()) {
				U2MessageBean proxyBean = new U2MessageBean();
				proxyBean.setMsgId(buildU2MsgId(proxySiteUserId));
				proxyBean.setMsgType(type);
				proxyBean.setSiteUserId(proxySiteUserId);
				proxyBean.setSendUserId(proxySiteUserId);
				proxyBean.setReceiveUserId(siteFriendId);
				proxyBean.setContent(msgText);
				proxyBean.setMsgTime(msgTime);
				messageDao.saveU2Message(proxyBean);
			}

			msgStatusResponse(command, msgId, msgTime, success);

			return success;
		}

		return true;
	} catch (Exception e) {
		LogUtils.requestErrorLog(logger, command, this.getClass(), e);
	}

	return false;
}
 
Example 5
Source File: U2MessageTextHandler.java    From openzaly with Apache License 2.0 4 votes vote down vote up
public Boolean handle(Command command) {
	try {
		int type = command.getMsgType();

		if (CoreProto.MsgType.TEXT_VALUE == type) {
			ImCtsMessageProto.ImCtsMessageRequest request = ImCtsMessageProto.ImCtsMessageRequest
					.parseFrom(command.getParams());
			String siteUserId = command.getSiteUserId();
			String proxySiteUserId = request.getText().getSiteUserId();
			String siteFriendId = request.getText().getSiteFriendId();
			String msgId = request.getText().getMsgId();
			ByteString byteStr = request.getText().getText();
			String msgText = byteStr.toString(Charset.forName("UTF-8"));
			command.setSiteFriendId(siteFriendId);

			long msgTime = System.currentTimeMillis();
			U2MessageBean u2Bean = new U2MessageBean();
			u2Bean.setMsgId(msgId);
			u2Bean.setMsgType(type);
			u2Bean.setSiteUserId(siteFriendId);
			u2Bean.setSendUserId(command.isProxy() ? proxySiteUserId : siteUserId);
			u2Bean.setReceiveUserId(siteFriendId);
			u2Bean.setContent(msgText);
			u2Bean.setMsgTime(msgTime);

			LogUtils.requestDebugLog(logger, command, u2Bean.toString());

			boolean success = messageDao.saveU2Message(u2Bean);

			if (success && command.isProxy()) {
				U2MessageBean proxyBean = new U2MessageBean();
				proxyBean.setMsgId(buildU2MsgId(proxySiteUserId));
				proxyBean.setMsgType(type);
				proxyBean.setSiteUserId(proxySiteUserId);
				proxyBean.setSendUserId(proxySiteUserId);
				proxyBean.setReceiveUserId(siteFriendId);
				proxyBean.setContent(msgText);
				proxyBean.setMsgTime(msgTime);
				messageDao.saveU2Message(proxyBean);
			}

			msgStatusResponse(command, msgId, msgTime, success);

			return success;
		}

		return true;
	} catch (Exception e) {
		LogUtils.requestErrorLog(logger, command, this.getClass(), e);
	}

	return false;
}
 
Example 6
Source File: TestUtils.java    From DataflowTemplates with Apache License 2.0 4 votes vote down vote up
static String toString(ByteString byteString) {
  return byteString.toString(Charset.forName("UTF-8"));
}