io.netty.util.internal.StringUtil Java Examples
The following examples show how to use
io.netty.util.internal.StringUtil.
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: DefaultSpdySynReplyFrame.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
@Override public String toString() { StringBuilder buf = new StringBuilder() .append(StringUtil.simpleClassName(this)) .append("(last: ") .append(isLast()) .append(')') .append(StringUtil.NEWLINE) .append("--> Stream-ID = ") .append(streamId()) .append(StringUtil.NEWLINE) .append("--> Headers:") .append(StringUtil.NEWLINE); appendHeaders(buf); // Remove the last newline. buf.setLength(buf.length() - StringUtil.NEWLINE.length()); return buf.toString(); }
Example #2
Source File: MsgTimeoutTimerManager.java From NettyChat with Apache License 2.0 | 6 votes |
/** * 从发送超时管理器中移除消息,并停止定时器 * * @param msgId */ public void remove(String msgId) { if (StringUtil.isNullOrEmpty(msgId)) { return; } MsgTimeoutTimer timer = mMsgTimeoutMap.remove(msgId); MessageProtobuf.Msg msg = null; if (timer != null) { msg = timer.getMsg(); timer.cancel(); timer = null; } System.out.println("从发送消息管理器移除消息,message=" + msg); }
Example #3
Source File: NioSctpChannel.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Override protected final Object filterOutboundMessage(Object msg) throws Exception { if (msg instanceof SctpMessage) { SctpMessage m = (SctpMessage) msg; ByteBuf buf = m.content(); if (buf.isDirect() && buf.nioBufferCount() == 1) { return m; } return new SctpMessage(m.protocolIdentifier(), m.streamIdentifier(), m.isUnordered(), newDirectBuffer(m, buf)); } throw new UnsupportedOperationException( "unsupported message type: " + StringUtil.simpleClassName(msg) + " (expected: " + StringUtil.simpleClassName(SctpMessage.class)); }
Example #4
Source File: ArmeriaHttpUtil.java From armeria with Apache License 2.0 | 6 votes |
/** * Filter the {@link HttpHeaderNames#TE} header according to the * <a href="https://tools.ietf.org/html/rfc7540#section-8.1.2.2">special rules in the HTTP/2 RFC</a>. * * @param entry the entry whose name is {@link HttpHeaderNames#TE}. * @param out the resulting HTTP/2 headers. */ private static void toHttp2HeadersFilterTE(Entry<CharSequence, CharSequence> entry, HttpHeadersBuilder out) { if (AsciiString.indexOf(entry.getValue(), ',', 0) == -1) { if (AsciiString.contentEqualsIgnoreCase(AsciiString.trim(entry.getValue()), HttpHeaderValues.TRAILERS)) { out.add(HttpHeaderNames.TE, HttpHeaderValues.TRAILERS.toString()); } } else { final List<CharSequence> teValues = StringUtil.unescapeCsvFields(entry.getValue()); for (CharSequence teValue : teValues) { if (AsciiString.contentEqualsIgnoreCase(AsciiString.trim(teValue), HttpHeaderValues.TRAILERS)) { out.add(HttpHeaderNames.TE, HttpHeaderValues.TRAILERS.toString()); break; } } } }
Example #5
Source File: DefaultHttpPriorityFrame.java From netty-http2 with Apache License 2.0 | 6 votes |
@Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append(StringUtil.simpleClassName(this)); buf.append(StringUtil.NEWLINE); buf.append("--> Stream-ID = "); buf.append(getStreamId()); buf.append(StringUtil.NEWLINE); buf.append("--> Dependency = "); buf.append(getDependency()); buf.append(" (exclusive: "); buf.append(isExclusive()); buf.append(", weight: "); buf.append(getWeight()); buf.append(')'); return buf.toString(); }
Example #6
Source File: DefaultSpdyDataFrame.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Override public String toString() { StringBuilder buf = new StringBuilder() .append(StringUtil.simpleClassName(this)) .append("(last: ") .append(isLast()) .append(')') .append(StringUtil.NEWLINE) .append("--> Stream-ID = ") .append(streamId()) .append(StringUtil.NEWLINE) .append("--> Size = "); if (refCnt() == 0) { buf.append("(freed)"); } else { buf.append(content().readableBytes()); } return buf.toString(); }
Example #7
Source File: DefaultSpdySynReplyFrame.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Override public String toString() { StringBuilder buf = new StringBuilder() .append(StringUtil.simpleClassName(this)) .append("(last: ") .append(isLast()) .append(')') .append(StringUtil.NEWLINE) .append("--> Stream-ID = ") .append(streamId()) .append(StringUtil.NEWLINE) .append("--> Headers:") .append(StringUtil.NEWLINE); appendHeaders(buf); // Remove the last newline. buf.setLength(buf.length() - StringUtil.NEWLINE.length()); return buf.toString(); }
Example #8
Source File: PhpFormatDocumentationProvider.java From idea-php-advanced-autocomplete with MIT License | 6 votes |
@Override public @Nullable PsiElement getDocumentationElementForLookupItem(PsiManager psiManager, Object object, PsiElement psiElement) { if (!(object instanceof String)) { return null; } String fqn = getCallToFormatFunc(psiElement); if (StringUtil.isNullOrEmpty(fqn)) { return null; } String tokenText = (String)object; if ("%%".equals(tokenText)) { tokenText = "%"; } else if (!"%".equals(tokenText)) { tokenText = StringUtils.strip((String)object, "%"); } String functionName = StringUtils.strip(fqn, "\\"); return new FormatTokenDocElement(psiManager, psiElement.getLanguage(), tokenText, functionName); }
Example #9
Source File: DefaultDnsRawRecord.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Override public String toString() { final StringBuilder buf = new StringBuilder(64).append(StringUtil.simpleClassName(this)).append('('); final DnsRecordType type = type(); if (type != DnsRecordType.OPT) { buf.append(name().isEmpty()? "<root>" : name()) .append(' ') .append(timeToLive()) .append(' '); DnsMessageUtil.appendRecordClass(buf, dnsClass()) .append(' ') .append(type.name()); } else { buf.append("OPT flags:") .append(timeToLive()) .append(" udp:") .append(dnsClass()); } buf.append(' ') .append(content().readableBytes()) .append("B)"); return buf.toString(); }
Example #10
Source File: AbstractDnsRecord.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Override public String toString() { StringBuilder buf = new StringBuilder(64); buf.append(StringUtil.simpleClassName(this)) .append('(') .append(name()) .append(' ') .append(timeToLive()) .append(' '); DnsMessageUtil.appendRecordClass(buf, dnsClass()) .append(' ') .append(type().name()) .append(')'); return buf.toString(); }
Example #11
Source File: DefaultThreadFactory.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
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; } } }
Example #12
Source File: URLHttpDownBootstrapBuilder.java From pdown-core with MIT License | 6 votes |
@Override public HttpDownBootstrap build() { try { HttpRequestInfo request = HttpDownUtil.buildRequest(method, url, heads, body); request(request); if (getLoopGroup() == null) { loopGroup(new NioEventLoopGroup(1)); } HttpResponseInfo response = HttpDownUtil.getHttpResponseInfo(request, null, getProxyConfig(), getLoopGroup()); if (getResponse() == null) { response(response); } else { if (StringUtil.isNullOrEmpty(getResponse().getFileName())) { getResponse().setFileName(response.getFileName()); } getResponse().setSupportRange(response.isSupportRange()); getResponse().setTotalSize(response.getTotalSize()); } } catch (Exception e) { if (getLoopGroup() != null) { getLoopGroup().shutdownGracefully(); } throw new BootstrapBuildException("build URLHttpDownBootstrap error", e); } return super.build(); }
Example #13
Source File: Base64Test.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
private static void testEncodeDecode(int size, ByteOrder order) { byte[] bytes = new byte[size]; PlatformDependent.threadLocalRandom().nextBytes(bytes); ByteBuf src = Unpooled.wrappedBuffer(bytes).order(order); ByteBuf encoded = Base64.encode(src); ByteBuf decoded = Base64.decode(encoded); ByteBuf expectedBuf = Unpooled.wrappedBuffer(bytes); try { assertEquals(StringUtil.NEWLINE + "expected: " + ByteBufUtil.hexDump(expectedBuf) + StringUtil.NEWLINE + "actual--: " + ByteBufUtil.hexDump(decoded), expectedBuf, decoded); } finally { src.release(); encoded.release(); decoded.release(); expectedBuf.release(); } }
Example #14
Source File: FingerprintTrustManagerFactory.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
private static byte[][] toFingerprintArray(Iterable<String> fingerprints) { if (fingerprints == null) { throw new NullPointerException("fingerprints"); } List<byte[]> list = new ArrayList<byte[]>(); for (String f: fingerprints) { if (f == null) { break; } if (!FINGERPRINT_PATTERN.matcher(f).matches()) { throw new IllegalArgumentException("malformed fingerprint: " + f); } f = FINGERPRINT_STRIP_PATTERN.matcher(f).replaceAll(""); if (f.length() != SHA1_HEX_LEN) { throw new IllegalArgumentException("malformed fingerprint: " + f + " (expected: SHA1)"); } list.add(StringUtil.decodeHexDump(f)); } return list.toArray(new byte[list.size()][]); }
Example #15
Source File: DefaultSocks4CommandResponse.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Override public String toString() { StringBuilder buf = new StringBuilder(96); buf.append(StringUtil.simpleClassName(this)); DecoderResult decoderResult = decoderResult(); if (!decoderResult.isSuccess()) { buf.append("(decoderResult: "); buf.append(decoderResult); buf.append(", dstAddr: "); } else { buf.append("(dstAddr: "); } buf.append(dstAddr()); buf.append(", dstPort: "); buf.append(dstPort()); buf.append(')'); return buf.toString(); }
Example #16
Source File: LocalChannelRegistry.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
static LocalAddress register( Channel channel, LocalAddress oldLocalAddress, SocketAddress localAddress) { if (oldLocalAddress != null) { throw new ChannelException("already bound"); } if (!(localAddress instanceof LocalAddress)) { throw new ChannelException("unsupported address type: " + StringUtil.simpleClassName(localAddress)); } LocalAddress addr = (LocalAddress) localAddress; if (LocalAddress.ANY.equals(addr)) { addr = new LocalAddress(channel); } Channel boundChannel = boundChannels.putIfAbsent(addr, channel); if (boundChannel != null) { throw new ChannelException("address already in use by: " + boundChannel); } return addr; }
Example #17
Source File: AutobahnServerHandler.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
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())); } }
Example #18
Source File: DefaultDnsQuestion.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
@Override public String toString() { StringBuilder buf = new StringBuilder(64); buf.append(StringUtil.simpleClassName(this)) .append('(') .append(name()) .append(' '); DnsMessageUtil.appendRecordClass(buf, dnsClass()) .append(' ') .append(type().name()) .append(')'); return buf.toString(); }
Example #19
Source File: HttpPostRequestEncoderTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Test public void testMultiFileUploadInHtml5Mode() throws Exception { DefaultFullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "http://localhost"); DefaultHttpDataFactory factory = new DefaultHttpDataFactory(DefaultHttpDataFactory.MINSIZE); HttpPostRequestEncoder encoder = new HttpPostRequestEncoder(factory, request, true, CharsetUtil.UTF_8, EncoderMode.HTML5); File file1 = new File(getClass().getResource("/file-01.txt").toURI()); encoder.addBodyAttribute("foo", "bar"); encoder.addBodyFileUpload("quux", file1, "text/plain", false); String multipartDataBoundary = encoder.multipartDataBoundary; String content = getRequestBody(encoder); String expected = "--" + multipartDataBoundary + "\r\n" + CONTENT_DISPOSITION + ": form-data; name=\"foo\"" + "\r\n" + CONTENT_LENGTH + ": 3" + "\r\n" + CONTENT_TYPE + ": text/plain; charset=UTF-8" + "\r\n" + "\r\n" + "bar" + "\r\n" + "--" + multipartDataBoundary + "\r\n" + CONTENT_DISPOSITION + ": form-data; name=\"quux\"; filename=\"file-01.txt\"" + "\r\n" + CONTENT_LENGTH + ": " + file1.length() + "\r\n" + CONTENT_TYPE + ": text/plain" + "\r\n" + CONTENT_TRANSFER_ENCODING + ": binary" + "\r\n" + "\r\n" + "File 01" + StringUtil.NEWLINE + "\r\n" + "--" + multipartDataBoundary + "--" + "\r\n"; assertEquals(expected, content); }
Example #20
Source File: AbstractOioByteChannel.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@Override protected void doWrite(ChannelOutboundBuffer in) throws Exception { for (;;) { Object msg = in.current(); if (msg == null) { // nothing left to write break; } if (msg instanceof ByteBuf) { ByteBuf buf = (ByteBuf) msg; int readableBytes = buf.readableBytes(); while (readableBytes > 0) { doWriteBytes(buf); int newReadableBytes = buf.readableBytes(); in.progress(readableBytes - newReadableBytes); readableBytes = newReadableBytes; } in.remove(); } else if (msg instanceof FileRegion) { FileRegion region = (FileRegion) msg; long transfered = region.transfered(); doWriteFileRegion(region); in.progress(region.transfered() - transfered); in.remove(); } else { in.remove(new UnsupportedOperationException( "unsupported message type: " + StringUtil.simpleClassName(msg))); } } }
Example #21
Source File: MqttPublishVariableHeader.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public String toString() { return new StringBuilder(StringUtil.simpleClassName(this)) .append('[') .append("topicName=").append(topicName) .append(", packetId=").append(packetId) .append(']') .toString(); }
Example #22
Source File: BaseSyncStatistics.java From commercetools-sync-java with Apache License 2.0 | 5 votes |
/** * Creates a new {@link BaseSyncStatistics} with initial values {@code 0} of created, updated, failed and processed * counters, an empty reportMessage and latestBatchHumanReadableProcessingTime. */ public BaseSyncStatistics() { updated = new AtomicInteger(); created = new AtomicInteger(); failed = new AtomicInteger(); processed = new AtomicInteger(); reportMessage = StringUtil.EMPTY_STRING; latestBatchHumanReadableProcessingTime = StringUtil.EMPTY_STRING; }
Example #23
Source File: HttpPostRequestDecoder.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * Check from the request ContentType if this request is a Multipart request. 检查请求内容类型是否该请求是多部分请求。 * @return an array of String if multipartDataBoundary exists with the multipartDataBoundary * as first element, charset if any as second (missing if not set), else null */ protected static String[] getMultipartDataBoundary(String contentType) { // Check if Post using "multipart/form-data; boundary=--89421926422648 [; charset=xxx]" String[] headerContentType = splitHeaderContentType(contentType); final String multiPartHeader = HttpHeaderValues.MULTIPART_FORM_DATA.toString(); if (headerContentType[0].regionMatches(true, 0, multiPartHeader, 0 , multiPartHeader.length())) { int mrank; int crank; final String boundaryHeader = HttpHeaderValues.BOUNDARY.toString(); if (headerContentType[1].regionMatches(true, 0, boundaryHeader, 0, boundaryHeader.length())) { mrank = 1; crank = 2; } else if (headerContentType[2].regionMatches(true, 0, boundaryHeader, 0, boundaryHeader.length())) { mrank = 2; crank = 1; } else { return null; } String boundary = StringUtil.substringAfter(headerContentType[mrank], '='); if (boundary == null) { throw new ErrorDataDecoderException("Needs a boundary value"); } if (boundary.charAt(0) == '"') { String bound = boundary.trim(); int index = bound.length() - 1; if (bound.charAt(index) == '"') { boundary = bound.substring(1, index); } } final String charsetHeader = HttpHeaderValues.CHARSET.toString(); if (headerContentType[crank].regionMatches(true, 0, charsetHeader, 0, charsetHeader.length())) { String charset = StringUtil.substringAfter(headerContentType[crank], '='); if (charset != null) { return new String[] {"--" + boundary, charset}; } } return new String[] {"--" + boundary}; } return null; }
Example #24
Source File: Native41AuthenticatorTest.java From vertx-sql-client with Apache License 2.0 | 5 votes |
@Test public void testEncode() { scrambledPasswordHexStr = "f2671df1862aed0340be809405b30bb93d29142d"; challenge = new byte[]{ // part1 0x18, 0x38, 0x55, 0x7e, 0x3a, 0x77, 0x65, 0x35, // part2 0x34, 0x1f, 0x44, 0x4a, 0x36, 0x60, 0x5d, 0x79, 0x5c, 0x09, 0x6c, 0x08}; assertEquals(scrambledPasswordHexStr, StringUtil.toHexString(Native41Authenticator.encode(PASSWORD, challenge))); }
Example #25
Source File: HpackDecoderTest.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
private void decode(String encoded) throws Http2Exception { byte[] b = StringUtil.decodeHexDump(encoded); ByteBuf in = Unpooled.wrappedBuffer(b); try { hpackDecoder.decode(0, in, mockHeaders, true); } finally { in.release(); } }
Example #26
Source File: AbstractChannelHandlerContext.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
private boolean isNotValidPromise(ChannelPromise promise, boolean allowVoidPromise) { if (promise == null) { throw new NullPointerException("promise"); } // 如果任务完成 if (promise.isDone()) { // Check if the promise was cancelled and if so signal that the processing of the operation 检查承诺是否被取消,如果取消,说明操作的处理 // should not be performed.不应该被执行 // // See https://github.com/netty/netty/issues/2349 // 如果任务取消了 if (promise.isCancelled()) { return true; } throw new IllegalArgumentException("promise already done: " + promise); } if (promise.channel() != channel()) { throw new IllegalArgumentException(String.format( "promise.channel does not match: %s (expected: %s)", promise.channel(), channel())); } if (promise.getClass() == DefaultChannelPromise.class) { return false; } if (!allowVoidPromise && promise instanceof VoidChannelPromise) { throw new IllegalArgumentException( StringUtil.simpleClassName(VoidChannelPromise.class) + " not allowed for this operation"); } if (promise instanceof AbstractChannel.CloseFuture) { throw new IllegalArgumentException( StringUtil.simpleClassName(AbstractChannel.CloseFuture.class) + " not allowed in a pipeline"); } return false; }
Example #27
Source File: DefaultHttpSettingsFrame.java From netty-http2 with Apache License 2.0 | 5 votes |
@Override public String toString() { StringBuilder buf = new StringBuilder(); buf.append(StringUtil.simpleClassName(this)); buf.append("(ack: "); buf.append(isAck()); buf.append(')'); buf.append(StringUtil.NEWLINE); appendSettings(buf); buf.setLength(buf.length() - StringUtil.NEWLINE.length()); return buf.toString(); }
Example #28
Source File: MqttTopicSubscription.java From mithqtt with Apache License 2.0 | 5 votes |
@Override public String toString() { return StringUtil.simpleClassName(this) + '[' + "topic=" + topic + ", requestedQos=" + requestedQos + ']'; }
Example #29
Source File: DefaultSpdyWindowUpdateFrame.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
@Override public String toString() { return new StringBuilder() .append(StringUtil.simpleClassName(this)) .append(StringUtil.NEWLINE) .append("--> Stream-ID = ") .append(streamId()) .append(StringUtil.NEWLINE) .append("--> Delta-Window-Size = ") .append(deltaWindowSize()) .toString(); }
Example #30
Source File: MqttFixedHeader.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
@Override public String toString() { return new StringBuilder(StringUtil.simpleClassName(this)) .append('[') .append("messageType=").append(messageType) .append(", isDup=").append(isDup) .append(", qosLevel=").append(qosLevel) .append(", isRetain=").append(isRetain) .append(", remainingLength=").append(remainingLength) .append(']') .toString(); }