本文整理汇总了Java中com.mpush.api.Constants.UTF_8属性的典型用法代码示例。如果您正苦于以下问题:Java Constants.UTF_8属性的具体用法?Java Constants.UTF_8怎么用?Java Constants.UTF_8使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类com.mpush.api.Constants
的用法示例。
在下文中一共展示了Constants.UTF_8属性的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handle
@SuppressWarnings("unchecked")
@Override
public void handle(HttpExchange httpExchange) throws IOException {
String body = new String(readBody(httpExchange), Constants.UTF_8);
Map<String, Object> params = Jsons.fromJson(body, Map.class);
sendPush(params);
byte[] data = "服务已经开始推送,请注意查收消息".getBytes(Constants.UTF_8);
httpExchange.getResponseHeaders().set("Content-Type", "text/plain; charset=utf-8");
httpExchange.sendResponseHeaders(200, data.length);//200, content-length
OutputStream out = httpExchange.getResponseBody();
out.write(data);
out.close();
httpExchange.close();
}
示例2: getSession
@Override
public String getSession() {
File file = new File(rootDir, fileName);
if (!file.exists()) return null;
InputStream in = null;
try {
in = new FileInputStream(file);
byte[] bytes = new byte[in.available()];
if (bytes.length > 0) {
in.read(bytes);
return new String(bytes, Constants.UTF_8);
}
in.close();
} catch (Exception e) {
ClientConfig.I.getLogger().e(e, "get session context ex,rootDir=%s", rootDir);
} finally {
IOUtils.close(in);
}
return null;
}
示例3: onReceive
@Override
public void onReceive(Context context, Intent intent) {
if (MPushService.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
byte[] bytes = intent.getByteArrayExtra(MPushService.EXTRA_PUSH_MESSAGE);
int messageId = intent.getIntExtra(MPushService.EXTRA_PUSH_MESSAGE_ID, 0);
String message = new String(bytes, Constants.UTF_8);
// Toast.makeText(context, "收到新的通知:" + message, Toast.LENGTH_SHORT).show();
if (messageId > 0) MPush.I.ack(messageId);
if (TextUtils.isEmpty(message)) return;
reactContext.getJSModule(RCTNativeAppEventEmitter.class).emit(MPUSH_EVENT_MESSAGE, message);
} else {
//reactContext.getJSModule(RCTNativeAppEventEmitter.class).emit(MPUSH_EVENT, intent.getAction());
}
Log.d("MPush", intent.toString());
if (MPushService.ACTION_KICK_USER.equals(intent.getAction())) {
Toast.makeText(context, "用户被踢下线了", Toast.LENGTH_SHORT).show();
} else if (MPushService.ACTION_BIND_USER.equals(intent.getAction())) {
Toast.makeText(context, "绑定用户:"
+ intent.getStringExtra(MPushService.EXTRA_USER_ID)
+ (intent.getBooleanExtra(MPushService.EXTRA_BIND_RET, false) ? "成功" : "失败")
, Toast.LENGTH_SHORT).show();
} else if (MPushService.ACTION_UNBIND_USER.equals(intent.getAction())) {
Toast.makeText(context, "解绑用户:"
+ (intent.getBooleanExtra(MPushService.EXTRA_BIND_RET, false)
? "成功"
: "失败")
, Toast.LENGTH_SHORT).show();
} else if (MPushService.ACTION_CONNECTIVITY_CHANGE.equals(intent.getAction())) {
Toast.makeText(context, intent.getBooleanExtra(MPushService.EXTRA_CONNECT_STATE, false)
? "MPUSH连接建立成功"
: "MPUSH连接断开"
, Toast.LENGTH_SHORT).show();
} else if (MPushService.ACTION_HANDSHAKE_OK.equals(intent.getAction())) {
Toast.makeText(context, "MPUSH握手成功, 心跳:" + intent.getIntExtra(MPushService.EXTRA_HEARTBEAT, 0)
, Toast.LENGTH_SHORT).show();
}
}
示例4: get
/**
* 获取数据,先从本地获取,本地找不到,从远程获取
*
* @param key
* @return
*/
public String get(final String key) {
if (null == cache) {
return null;
}
ChildData data = cache.getCurrentData(key);
if (null != data) {
return null == data.getData() ? null : new String(data.getData(), Constants.UTF_8);
}
return getFromRemote(key);
}
示例5: getFromRemote
/**
* 从远程获取数据
*
* @param key
* @return
*/
public String getFromRemote(final String key) {
if (isExisted(key)) {
try {
return new String(client.getData().forPath(key), Constants.UTF_8);
} catch (Exception ex) {
Logs.RSD.error("getFromRemote:{}", key, ex);
}
}
return null;
}
示例6: toString
@Override
public String toString() {
return "HttpResponse{" +
"statusCode=" + statusCode +
", reasonPhrase='" + reasonPhrase + '\'' +
", headers=" + headers +
", body=" + (body == null ? "" : new String(body, Constants.UTF_8)) +
'}';
}
示例7: decodeString
public String decodeString(ByteBuf body) {
byte[] bytes = decodeBytes(body);
if (bytes == null) return null;
return new String(bytes, Constants.UTF_8);
}
示例8: onReceive
@Override
public void onReceive(Context context, Intent intent) {
if (MPushService.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())) {
byte[] bytes = intent.getByteArrayExtra(MPushService.EXTRA_PUSH_MESSAGE);
int messageId = intent.getIntExtra(MPushService.EXTRA_PUSH_MESSAGE_ID, 0);
String message = new String(bytes, Constants.UTF_8);
Toast.makeText(context, "收到新的通知:" + message, Toast.LENGTH_SHORT).show();
if (messageId > 0) MPush.I.ack(messageId);
if (TextUtils.isEmpty(message)) return;
NotificationDO ndo = fromJson(message);
if (ndo != null) {
Intent it = new Intent(context, MyReceiver.class);
it.setAction(MPushService.ACTION_NOTIFICATION_OPENED);
if (ndo.getExtras() != null) it.putExtra("my_extra", ndo.getExtras().toString());
if (TextUtils.isEmpty(ndo.getTitle())) ndo.setTitle("MPush");
if (TextUtils.isEmpty(ndo.getTicker())) ndo.setTicker(ndo.getTitle());
if (TextUtils.isEmpty(ndo.getContent())) ndo.setContent(ndo.getTitle());
Notifications.I.notify(ndo, it);
}
} else if (MPushService.ACTION_NOTIFICATION_OPENED.equals(intent.getAction())) {
Notifications.I.clean(intent);
String extras = intent.getStringExtra("my_extra");
Toast.makeText(context, "通知被点击了, extras=" + extras, Toast.LENGTH_SHORT).show();
} else if (MPushService.ACTION_KICK_USER.equals(intent.getAction())) {
Toast.makeText(context, "用户被踢下线了", Toast.LENGTH_SHORT).show();
} else if (MPushService.ACTION_BIND_USER.equals(intent.getAction())) {
Toast.makeText(context, "绑定用户:"
+ intent.getStringExtra(MPushService.EXTRA_USER_ID)
+ (intent.getBooleanExtra(MPushService.EXTRA_BIND_RET, false) ? "成功" : "失败")
, Toast.LENGTH_SHORT).show();
} else if (MPushService.ACTION_UNBIND_USER.equals(intent.getAction())) {
Toast.makeText(context, "解绑用户:"
+ (intent.getBooleanExtra(MPushService.EXTRA_BIND_RET, false)
? "成功"
: "失败")
, Toast.LENGTH_SHORT).show();
} else if (MPushService.ACTION_CONNECTIVITY_CHANGE.equals(intent.getAction())) {
Toast.makeText(context, intent.getBooleanExtra(MPushService.EXTRA_CONNECT_STATE, false)
? "MPUSH连接建立成功"
: "MPUSH连接断开"
, Toast.LENGTH_SHORT).show();
} else if (MPushService.ACTION_HANDSHAKE_OK.equals(intent.getAction())) {
Toast.makeText(context, "MPUSH握手成功, 心跳:" + intent.getIntExtra(MPushService.EXTRA_HEARTBEAT, 0)
, Toast.LENGTH_SHORT).show();
}
}
示例9: decodeString
protected String decodeString(ByteBuffer body) {
byte[] bytes = decodeBytes(body);
if (bytes == null) return null;
return new String(bytes, Constants.UTF_8);
}
示例10: encode
/**
* <p>
* 二进制数据编码为BASE64字符串
* </p>
*
* @param bytes base64
* @return BASE64后的二进制数据
*/
public static String encode(byte[] bytes) {
return new String(Base64.getEncoder().encode(bytes), Constants.UTF_8);
}
示例11: encode
/**
* <p>
* 二进制数据编码为BASE64字符串
* </p>
*
* @param bytes xxx
* @return return
* @throws Exception xxx
*/
public static String encode(byte[] bytes) throws Exception {
return new String(Base64.getEncoder().encode(bytes), Constants.UTF_8);
}