Java Code Examples for io.netty.util.internal.StringUtil#EMPTY_STRING

The following examples show how to use io.netty.util.internal.StringUtil#EMPTY_STRING . 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: DumpTreeVisitor.java    From cassandana with Apache License 2.0 6 votes vote down vote up
private String prettySubscriptions(CNode node) {
    if (node instanceof TNode) {
        return "TNode";
    }
    if (node.subscriptions.isEmpty()) {
        return StringUtil.EMPTY_STRING;
    }
    StringBuilder subScriptionsStr = new StringBuilder(" ~~[");
    int counter = 0;
    for (Subscription couple : node.subscriptions) {
        subScriptionsStr
            .append("{filter=").append(couple.topicFilter).append(", ")
            .append("qos=").append(couple.getRequestedQos()).append(", ")
            .append("client='").append(couple.clientId).append("'}");
        counter++;
        if (counter < node.subscriptions.size()) {
            subScriptionsStr.append(";");
        }
    }
    return subScriptionsStr.append("]").toString();
}
 
Example 2
Source File: DumpTreeVisitor.java    From spring-boot-protocol with Apache License 2.0 6 votes vote down vote up
private String prettySubscriptions(CNode node) {
    if (node instanceof TNode) {
        return "TNode";
    }
    if (node.subscriptions.isEmpty()) {
        return StringUtil.EMPTY_STRING;
    }
    StringBuilder subScriptionsStr = new StringBuilder(" ~~[");
    int counter = 0;
    for (Subscription couple : node.subscriptions) {
        subScriptionsStr
            .append("{filter=").append(couple.topicFilter).append(", ")
            .append("qos=").append(couple.getRequestedQos()).append(", ")
            .append("client='").append(couple.clientId).append("'}");
        counter++;
        if (counter < node.subscriptions.size()) {
            subScriptionsStr.append(";");
        }
    }
    return subScriptionsStr.append("]").toString();
}
 
Example 3
Source File: LinkDiscovery.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Add physical port to discovery process.
 * Send out initial LLDP and label it as slow port.
 *
 * @param port the port
 */
public void addPort(Port port) {
    Long portNum = port.number().toLong();
    String portName = port.annotations().value(PORT_NAME);
    if (portName == null) {
        portName = StringUtil.EMPTY_STRING;
    }

    boolean newPort = !containsPort(portNum);
    portMap.put(portNum, portName);

    boolean isMaster = context.mastershipService().isLocalMaster(deviceId);
    if (newPort && isMaster) {
        log.debug("Sending initial probe to port {}@{}", port.number().toLong(), deviceId);
        sendProbes(portNum, portName);
    }
}
 
Example 4
Source File: HttpPostRequestEncoder.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
/**
 * Add a file as a FileUpload
 *
 * @param name
 *            the name of the parameter
 * @param file
 *            the file to be uploaded (if not Multipart mode, only the filename will be included)
 * @param filename
 *            the filename to use for this File part, empty String will be ignored by
 *            the encoder
 * @param contentType
 *            the associated contentType for the File
 * @param isText
 *            True if this file should be transmitted in Text format (else binary)
 * @throws NullPointerException
 *             for name and file
 * @throws ErrorDataEncoderException
 *             if the encoding is in error or if the finalize were already done
 */
public void addBodyFileUpload(String name, String filename, File file, String contentType, boolean isText)
        throws ErrorDataEncoderException {
    checkNotNull(name, "name");
    checkNotNull(file, "file");
    if (filename == null) {
        filename = StringUtil.EMPTY_STRING;
    }
    String scontentType = contentType;
    String contentTransferEncoding = null;
    if (contentType == null) {
        if (isText) {
            scontentType = HttpPostBodyUtil.DEFAULT_TEXT_CONTENT_TYPE;
        } else {
            scontentType = HttpPostBodyUtil.DEFAULT_BINARY_CONTENT_TYPE;
        }
    }
    if (!isText) {
        contentTransferEncoding = HttpPostBodyUtil.TransferEncodingMechanism.BINARY.value();
    }
    FileUpload fileUpload = factory.createFileUpload(request, name, filename, scontentType,
            contentTransferEncoding, null, file.length());
    try {
        fileUpload.setContent(file);
    } catch (IOException e) {
        throw new ErrorDataEncoderException(e);
    }
    addBodyHttpData(fileUpload);
}
 
Example 5
Source File: HttpPostMultipartRequestDecoder.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
/**
 * Split one header in Multipart
 *
 * @return an array of String where rank 0 is the name of the header,
 *         follows by several values that were separated by ';' or ','
 */
private static String[] splitMultipartHeader(String sb) {
    ArrayList<String> headers = new ArrayList<String>(1);
    int nameStart;
    int nameEnd;
    int colonEnd;
    int valueStart;
    int valueEnd;
    nameStart = HttpPostBodyUtil.findNonWhitespace(sb, 0);
    for (nameEnd = nameStart; nameEnd < sb.length(); nameEnd++) {
        char ch = sb.charAt(nameEnd);
        if (ch == ':' || Character.isWhitespace(ch)) {
            break;
        }
    }
    for (colonEnd = nameEnd; colonEnd < sb.length(); colonEnd++) {
        if (sb.charAt(colonEnd) == ':') {
            colonEnd++;
            break;
        }
    }
    valueStart = HttpPostBodyUtil.findNonWhitespace(sb, colonEnd);
    valueEnd = HttpPostBodyUtil.findEndOfString(sb);
    headers.add(sb.substring(nameStart, nameEnd));
    String svalue = (valueStart >= valueEnd) ? StringUtil.EMPTY_STRING : sb.substring(valueStart, valueEnd);
    String[] values;
    if (svalue.indexOf(';') >= 0) {
        values = splitMultipartHeaderValues(svalue);
    } else {
        values = svalue.split(",");
    }
    for (String value : values) {
        headers.add(value.trim());
    }
    String[] array = new String[headers.size()];
    for (int i = 0; i < headers.size(); i++) {
        array[i] = headers.get(i);
    }
    return array;
}
 
Example 6
Source File: CloseWebSocketFrame.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private static ByteBuf newBinaryData(int statusCode, String reasonText) {
    if (reasonText == null) {
        reasonText = StringUtil.EMPTY_STRING;
    }

    ByteBuf binaryData = Unpooled.buffer(2 + reasonText.length());
    binaryData.writeShort(statusCode);
    if (!reasonText.isEmpty()) {
        binaryData.writeCharSequence(reasonText, CharsetUtil.UTF_8);
    }

    binaryData.readerIndex(0);
    return binaryData;
}
 
Example 7
Source File: Http2FrameLogger.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private String toString(ByteBuf buf) {
    if (!logger.isEnabled(level)) {
        return StringUtil.EMPTY_STRING;
    }

    if (level == InternalLogLevel.TRACE || buf.readableBytes() <= BUFFER_LENGTH_THRESHOLD) {
        // Log the entire buffer.
        return ByteBufUtil.hexDump(buf);
    }

    // Otherwise just log the first 64 bytes.
    int length = Math.min(buf.readableBytes(), BUFFER_LENGTH_THRESHOLD);
    return ByteBufUtil.hexDump(buf, buf.readerIndex(), length) + "...";
}
 
Example 8
Source File: ReferenceCountedOpenSslEngine.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
@Override
public String getProtocol() {
    String protocol = this.protocol;
    if (protocol == null) {
        synchronized (ReferenceCountedOpenSslEngine.this) {
            if (!isDestroyed()) {
                protocol = SSL.getVersion(ssl);
            } else {
                protocol = StringUtil.EMPTY_STRING;
            }
        }
    }
    return protocol;
}
 
Example 9
Source File: ByteBufUtil.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
static String decodeString(ByteBuf src, int readerIndex, int len, Charset charset) {
        if (len == 0) {
            return StringUtil.EMPTY_STRING;
        }
        final CharsetDecoder decoder = CharsetUtil.decoder(charset);
        final int maxLength = (int) ((double) len * decoder.maxCharsPerByte());
        CharBuffer dst = CHAR_BUFFERS.get();
        if (dst.length() < maxLength) {
            dst = CharBuffer.allocate(maxLength);
            if (maxLength <= MAX_CHAR_BUFFER_SIZE) {
                CHAR_BUFFERS.set(dst);
            }
        } else {
            dst.clear();
        }
        if (src.nioBufferCount() == 1) {
            decodeString(decoder, src.nioBuffer(readerIndex, len), dst);
        } else {
            // We use a heap buffer as CharsetDecoder is most likely able to use a fast-path if src and dst buffers
            // are both backed by a byte array.//我们使用堆缓冲区,因为如果src和dst缓冲区,CharsetDecoder最有可能使用快速路径
//            都是由字节数组支持的。
            ByteBuf buffer = src.alloc().heapBuffer(len);
            try {
                buffer.writeBytes(src, readerIndex, len);
                // Use internalNioBuffer(...) to reduce object creation.
                decodeString(decoder, buffer.internalNioBuffer(buffer.readerIndex(), len), dst);
            } finally {
                // Release the temporary buffer again.再次释放临时缓冲区。
                buffer.release();
            }
        }
        return dst.flip().toString();
    }
 
Example 10
Source File: ByteBufUtil.java    From netty-4.1.22 with Apache License 2.0 5 votes vote down vote up
private static String prettyHexDump(ByteBuf buffer, int offset, int length) {
    if (length == 0) {
      return StringUtil.EMPTY_STRING;
    } else {
        int rows = length / 16 + (length % 15 == 0? 0 : 1) + 4;
        StringBuilder buf = new StringBuilder(rows * 80);
        appendPrettyHexDump(buf, buffer, offset, length);
        return buf.toString();
    }
}
 
Example 11
Source File: HttpPostMultipartRequestDecoder.java    From dorado with Apache License 2.0 5 votes vote down vote up
/**
 * Split one header in Multipart
 *
 * @return an array of String where rank 0 is the name of the header, follows by
 *         several values that were separated by ';' or ','
 */
private static String[] splitMultipartHeader(String sb) {
	ArrayList<String> headers = new ArrayList<String>(1);
	int nameStart;
	int nameEnd;
	int colonEnd;
	int valueStart;
	int valueEnd;
	nameStart = HttpPostBodyUtil.findNonWhitespace(sb, 0);
	for (nameEnd = nameStart; nameEnd < sb.length(); nameEnd++) {
		char ch = sb.charAt(nameEnd);
		if (ch == ':' || Character.isWhitespace(ch)) {
			break;
		}
	}
	for (colonEnd = nameEnd; colonEnd < sb.length(); colonEnd++) {
		if (sb.charAt(colonEnd) == ':') {
			colonEnd++;
			break;
		}
	}
	valueStart = HttpPostBodyUtil.findNonWhitespace(sb, colonEnd);
	valueEnd = HttpPostBodyUtil.findEndOfString(sb);
	headers.add(sb.substring(nameStart, nameEnd));
	String svalue = (valueStart >= valueEnd) ? StringUtil.EMPTY_STRING : sb.substring(valueStart, valueEnd);
	String[] values;
	if (svalue.indexOf(';') >= 0) {
		values = splitMultipartHeaderValues(svalue);
	} else {
		values = svalue.split(",");
	}
	for (String value : values) {
		headers.add(value.trim());
	}
	String[] array = new String[headers.size()];
	for (int i = 0; i < headers.size(); i++) {
		array[i] = headers.get(i);
	}
	return array;
}
 
Example 12
Source File: BaseSyncStatistics.java    From commercetools-sync-java with Apache License 2.0 5 votes vote down vote up
/**
 * 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 13
Source File: AbstractDnsOptPseudoRrRecord.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
protected AbstractDnsOptPseudoRrRecord(int maxPayloadSize, int extendedRcode, int version) {
    super(StringUtil.EMPTY_STRING, DnsRecordType.OPT, maxPayloadSize, packIntoLong(extendedRcode, version));
}
 
Example 14
Source File: AbstractDnsOptPseudoRrRecord.java    From netty-4.1.22 with Apache License 2.0 4 votes vote down vote up
protected AbstractDnsOptPseudoRrRecord(int maxPayloadSize) {
    super(StringUtil.EMPTY_STRING, DnsRecordType.OPT, maxPayloadSize, 0);
}
 
Example 15
Source File: HttpPostRequestEncoder.java    From netty-4.1.22 with Apache License 2.0 2 votes vote down vote up
/**
 * Add a simple attribute in the body as Name=Value
 *
 * @param name
 *            name of the parameter
 * @param value
 *            the value of the parameter
 * @throws NullPointerException
 *             for name
 * @throws ErrorDataEncoderException
 *             if the encoding is in error or if the finalize were already done
 */
public void addBodyAttribute(String name, String value) throws ErrorDataEncoderException {
    String svalue = value != null? value : StringUtil.EMPTY_STRING;
    Attribute data = factory.createAttribute(request, checkNotNull(name, "name"), svalue);
    addBodyHttpData(data);
}