本文整理匯總了Java中io.netty.util.internal.StringUtil類的典型用法代碼示例。如果您正苦於以下問題:Java StringUtil類的具體用法?Java StringUtil怎麽用?Java StringUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
StringUtil類屬於io.netty.util.internal包,在下文中一共展示了StringUtil類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleWebSocketFrame
import io.netty.util.internal.StringUtil; //導入依賴的package包/類
private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
if (logger.isLoggable(Level.FINE)) {
logger.fine(String.format(
"Channel %s received %s", ctx.channel().hashCode(), StringUtil.simpleClassName(frame)));
}
if (frame instanceof CloseWebSocketFrame) {
handshaker.close(ctx.channel(), (CloseWebSocketFrame) frame);
} else if (frame instanceof PingWebSocketFrame) {
ctx.write(new PongWebSocketFrame(frame.isFinalFragment(), frame.rsv(), frame.content()), ctx.voidPromise());
} else if (frame instanceof TextWebSocketFrame) {
ctx.write(frame, ctx.voidPromise());
} else if (frame instanceof BinaryWebSocketFrame) {
ctx.write(frame, ctx.voidPromise());
} else if (frame instanceof ContinuationWebSocketFrame) {
ctx.write(frame, ctx.voidPromise());
} else if (frame instanceof PongWebSocketFrame) {
frame.release();
// Ignore
} else {
throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass()
.getName()));
}
}
示例2: getImplClass
import io.netty.util.internal.StringUtil; //導入依賴的package包/類
/**
* 獲取一個接口的實現類
* @param defineClass
* @param lookup 指定名稱的實現類
* @return
*/
public Class<?> getImplClass(Class<?> defineClass, String lookup) {
if (StringUtil.isNullOrEmpty(lookup)) {
return null;
}
Collection<SessionBean> beans = serviceimplmap.get(defineClass.getName());
if (CollectionUtil.isNotEmpty(beans)) {
Iterator<SessionBean> beanite = beans.iterator();
while (beanite.hasNext()) {
SessionBean bean = beanite.next();
if (lookup.toLowerCase().equals(bean.getLookup().toLowerCase())) {
return bean.getImplClass().getCls();
}
}
}
return null;
}
示例3: doLeaveRoom
import io.netty.util.internal.StringUtil; //導入依賴的package包/類
private void doLeaveRoom(Channel channel, LeaveRoomMessage leaveRoom) {
UserInfo userInfo = NetoChannelUtil.getUserInfo(channel);
if (userInfo == null || StringUtil.isNullOrEmpty(userInfo.getUserId())) {
throw new NotFoundUserInfoException(Constants.StatusCode.NOT_FOUND_USERINFO, "Not Found User Info");
}
String inputId = leaveRoom.getUserId();
String sessionId = userInfo.getUserId();
if (userInfo.getAccessLevel() > Constants.AccessLevel.ADMIN) {
globalChannelGroup.stream().filter(c -> c != null && leaveRoom.getUserId().equals(NetoChannelUtil.getUserInfo(c).getUserId()))
.forEach(c -> {
leaveRoom(c);
leaveRoom.setStatusCode(Constants.StatusCode.OK);
channel.writeAndFlush(leaveRoom);
});
} else if (sessionId.equals(inputId)) {
leaveRoom(channel);
leaveRoom.setStatusCode(Constants.StatusCode.OK);
sendMessage(channel, leaveRoom);
} else {
throw new BadAccessException(Constants.StatusCode.FAIL, "bad access!");
}
}
示例4: createNodeKey
import io.netty.util.internal.StringUtil; //導入依賴的package包/類
private String createNodeKey(String... nodes) {
if (nodes == null || StringUtil.isNullOrEmpty(nodes[0])) {
return "";
}
final StringBuilder sb = new StringBuilder();
for (int i = 0, len = nodes.length; i < len; i++) {
if (i > 0) {
sb.append(":");
}
sb.append(nodes[i]);
}
return sb.toString();
}
示例5: getEncodedTargetAddress
import io.netty.util.internal.StringUtil; //導入依賴的package包/類
private ByteBuf getEncodedTargetAddress(ByteBufAllocator allocator, boolean resolve) throws ProxyConnectException {
InetSocketAddress remoteAddress = destinationAddress();
SocksAddressType remoteAddressType;
String remoteHost;
if (!resolve || remoteAddress.isUnresolved()) {
remoteAddressType = SocksAddressType.DOMAIN;
remoteHost = remoteAddress.getHostString();
} else {
remoteHost = remoteAddress.getAddress().getHostAddress();
if (NetUtil.isValidIpV4Address(remoteHost)) {
remoteAddressType = SocksAddressType.IPv4;
} else if (NetUtil.isValidIpV6Address(remoteHost)) {
remoteAddressType = SocksAddressType.IPv6;
} else {
throw new ProxyConnectException("unknown address type: " + StringUtil.simpleClassName(remoteHost));
}
}
int remotePort = remoteAddress.getPort();
SocksCmdRequest request = new SocksCmdRequest(SocksCmdType.UNKNOWN, remoteAddressType, remoteHost, remotePort);
return SSocksAddressEncoder.INSTANCE.encode(allocator, request);
}
示例6: execute
import io.netty.util.internal.StringUtil; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public void execute(ShardingContext shardingContext) {
List<MessageEntity> findList = this.messageEntityMapper.queryTransactionNotComplete();
log.info("查詢沒有完成的事務消息(查詢1分鍾之前的)記錄數:{}",findList);
if(findList.isEmpty()){
return;
}
try {
for(MessageEntity entity : findList){
Message message = new Message();
message.setMessageId(entity.getMessageId());
message.setBody(entity.getBody());
message.setDestination(entity.getDestination());
if(!StringUtil.isNullOrEmpty(entity.getProperties())){
message.setProperties(JSON.parseObject(entity.getProperties(), Map.class));
}
RemotingCommand request = RemotingCommand.buildRequestCmd(message, RequestCode.SEND_MESSAGE, MessageCode.TRANSACTION_CHECK_MESSAGE);
request.setGroup(entity.getGroup());
sentToClient(request);
}
} catch (Exception e) {
log.error("回查發送異常:{}",e);
}
}
示例7: checkMessage
import io.netty.util.internal.StringUtil; //導入依賴的package包/類
public static void checkMessage(Message msg,DefaultMQProducer defaultMQProducer) throws MQClientException {
if (null == msg) {
throw new MQClientException(1,"the message is null");
}
if (null == msg.getBody()) {
throw new MQClientException(2,"the message body is null");
}
if (0 == msg.getBody().length) {
throw new MQClientException(3,"the message body length is zero");
}
if (msg.getBody().length > defaultMQProducer.getMaxMessageSize()) {
throw new MQClientException(4,"the message body size over max value, MAX: " + defaultMQProducer.getMaxMessageSize());
}
if(StringUtil.isNullOrEmpty(msg.getMessageId())){
msg.setMessageId(UUID.randomUUID().toString());
}
}
示例8: toPoolName
import io.netty.util.internal.StringUtil; //導入依賴的package包/類
public static String toPoolName(Class<?> poolType) {
if (poolType == null) {
throw new NullPointerException("poolType");
}
String poolName = StringUtil.simpleClassName(poolType);
switch (poolName.length()) {
case 0:
return "unknown";
case 1:
return poolName.toLowerCase(Locale.US);
default:
if (Character.isUpperCase(poolName.charAt(0)) && Character.isLowerCase(poolName.charAt(1))) {
return Character.toLowerCase(poolName.charAt(0)) + poolName.substring(1);
} else {
return poolName;
}
}
}
示例9: toString
import io.netty.util.internal.StringUtil; //導入依賴的package包/類
public String toString() {
StringBuilder buf = new StringBuilder();
buf.append(directArenas.length);
buf.append(" direct arena(s):");
buf.append(StringUtil.NEWLINE);
for (PoolArena<ByteBuffer> a : directArenas) {
buf.append(a);
}
buf.append("Large buffers outstanding: ");
buf.append(this.hugeBufferCount.get());
buf.append(" totaling ");
buf.append(this.hugeBufferSize.get());
buf.append(" bytes.");
buf.append('\n');
buf.append("Normal buffers outstanding: ");
buf.append(this.normalBufferCount.get());
buf.append(" totaling ");
buf.append(this.normalBufferSize.get());
buf.append(" bytes.");
return buf.toString();
}
示例10: calculateProcessingTime_ShouldSetProcessingTimeInAllUnitsAndHumanReadableString
import io.netty.util.internal.StringUtil; //導入依賴的package包/類
@Test
public void calculateProcessingTime_ShouldSetProcessingTimeInAllUnitsAndHumanReadableString() throws
InterruptedException {
assertThat(baseSyncStatistics.getLatestBatchProcessingTimeInMillis()).isEqualTo(0);
assertThat(baseSyncStatistics.getLatestBatchHumanReadableProcessingTime()).isEqualTo(StringUtil.EMPTY_STRING);
final int waitingTimeInMillis = 100;
Thread.sleep(waitingTimeInMillis);
baseSyncStatistics.calculateProcessingTime();
assertThat(baseSyncStatistics.getLatestBatchProcessingTimeInDays()).isGreaterThanOrEqualTo(0);
assertThat(baseSyncStatistics.getLatestBatchProcessingTimeInHours()).isGreaterThanOrEqualTo(0);
assertThat(baseSyncStatistics.getLatestBatchProcessingTimeInMinutes()).isGreaterThanOrEqualTo(0);
assertThat(baseSyncStatistics.getLatestBatchProcessingTimeInSeconds())
.isGreaterThanOrEqualTo(waitingTimeInMillis / 1000);
assertThat(baseSyncStatistics.getLatestBatchProcessingTimeInMillis())
.isGreaterThanOrEqualTo(waitingTimeInMillis);
final long remainingMillis = baseSyncStatistics.getLatestBatchProcessingTimeInMillis()
- TimeUnit.SECONDS.toMillis(baseSyncStatistics.getLatestBatchProcessingTimeInSeconds());
assertThat(baseSyncStatistics.getLatestBatchHumanReadableProcessingTime())
.contains(format(", %dms", remainingMillis));
}
示例11: filterOutboundMessage
import io.netty.util.internal.StringUtil; //導入依賴的package包/類
@Override
protected Object filterOutboundMessage(Object msg) {
if (msg instanceof UkcpPacket) {
UkcpPacket p = (UkcpPacket) msg;
ByteBuf content = p.content();
if (isSingleDirectBuffer(content)) {
return p;
}
content.retain(); // newDirectBuffer method call release method of content
UkcpPacket np = UkcpPacket.newInstance(newDirectBuffer(content), p.remoteAddress());
p.release();
return np;
}
throw new UnsupportedOperationException(
"unsupported message type: " + StringUtil.simpleClassName(msg) + EXPECTED_TYPES);
}
示例12: checkParams
import io.netty.util.internal.StringUtil; //導入依賴的package包/類
private void checkParams(String cluster, String ipAddress, Integer port, List<SeedMember> seedMembers) throws Exception {
String f = "[%s] is required!";
String who = null;
if (StringUtil.isNullOrEmpty(cluster)) {
who = "cluster";
} else if (StringUtil.isNullOrEmpty(ipAddress)) {
who = "ip";
} else if (StringUtil.isNullOrEmpty(String.valueOf(port))) {
who = "port";
} else if (seedMembers == null || seedMembers.isEmpty()) {
who = "seed member";
}
if (who != null) {
throw new IllegalArgumentException(String.format(f, who));
}
}
示例13: parseRange
import io.netty.util.internal.StringUtil; //導入依賴的package包/類
private long[] parseRange(String range, long availableLength)
throws IllegalArgumentException {
if (StringUtil.isNullOrEmpty(range)) {
return null;
}
Matcher m = RANGE_HEADER.matcher(range);
if (!m.matches()) {
throw new IllegalArgumentException("Unsupported range: %s" + range);
}
long[] result = new long[2];
result[0] = Long.parseLong(m.group(1));
String sed = m.group(2);
result[1] = StringUtil.isNullOrEmpty(sed) ? availableLength - 1 : Long.parseLong(sed);
if (result[0] > result[1] || result[1] >= availableLength) {
throw new IllegalArgumentException("Unsupported range: %s" + range);
}
return result;
}
示例14: filter
import io.netty.util.internal.StringUtil; //導入依賴的package包/類
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
String version = requestContext.getHeaderString(HEADER_VERSION);
if (StringUtil.isNullOrEmpty(version)) {
return;
}
URI requestUri = requestContext.getUriInfo().getRequestUri();
try {
URI newUri = new URI(requestUri.getScheme(), requestUri.getAuthority(), "/" + version + requestUri.getPath(), requestUri.getQuery(), requestUri.getFragment());
requestContext.setRequestUri(newUri);
} catch (URISyntaxException e) {
String info = String.format("requestContext.setRequestUri error: version[%s]=>requestUri[%s]", version, requestUri);
log.error(info, e);
}
}
示例15: EventHub
import io.netty.util.internal.StringUtil; //導入依賴的package包/類
EventHub(String name, String grpcURL, ExecutorService executorService, Properties properties) throws InvalidArgumentException {
Exception e = checkGrpcUrl(grpcURL);
if (e != null) {
throw new InvalidArgumentException("Bad event hub url.", e);
}
if (StringUtil.isNullOrEmpty(name)) {
throw new InvalidArgumentException("Invalid name for eventHub");
}
this.url = grpcURL;
this.name = name;
this.executorService = executorService;
this.properties = properties == null ? null : (Properties) properties.clone(); //keep our own copy.
}