當前位置: 首頁>>代碼示例>>Java>>正文


Java StringUtil.split方法代碼示例

本文整理匯總了Java中io.netty.util.internal.StringUtil.split方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtil.split方法的具體用法?Java StringUtil.split怎麽用?Java StringUtil.split使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.util.internal.StringUtil的用法示例。


在下文中一共展示了StringUtil.split方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: WebSocketServerHandshaker

import io.netty.util.internal.StringUtil; //導入方法依賴的package包/類
/**
 * Constructor specifying the destination web socket location
 *
 * @param version
 *            the protocol version
 * @param uri
 *            URL for web socket communications. e.g "ws://myhost.com/mypath". Subsequent web socket frames will be
 *            sent to this URL.
 * @param subprotocols
 *            CSV of supported protocols. Null if sub protocols not supported.
 * @param maxFramePayloadLength
 *            Maximum length of a frame's payload
 */
protected WebSocketServerHandshaker(
        WebSocketVersion version, String uri, String subprotocols,
        int maxFramePayloadLength) {
    this.version = version;
    this.uri = uri;
    if (subprotocols != null) {
        String[] subprotocolArray = StringUtil.split(subprotocols, ',');
        for (int i = 0; i < subprotocolArray.length; i++) {
            subprotocolArray[i] = subprotocolArray[i].trim();
        }
        this.subprotocols = subprotocolArray;
    } else {
        this.subprotocols = EmptyArrays.EMPTY_STRINGS;
    }
    this.maxFramePayloadLength = maxFramePayloadLength;
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:30,代碼來源:WebSocketServerHandshaker.java

示例2: selectSubprotocol

import io.netty.util.internal.StringUtil; //導入方法依賴的package包/類
/**
 * Selects the first matching supported sub protocol
 *
 * @param requestedSubprotocols
 *            CSV of protocols to be supported. e.g. "chat, superchat"
 * @return First matching supported sub protocol. Null if not found.
 */
protected String selectSubprotocol(String requestedSubprotocols) {
    if (requestedSubprotocols == null || subprotocols.length == 0) {
        return null;
    }

    String[] requestedSubprotocolArray = StringUtil.split(requestedSubprotocols, ',');
    for (String p: requestedSubprotocolArray) {
        String requestedSubprotocol = p.trim();

        for (String supportedSubprotocol: subprotocols) {
            if (SUB_PROTOCOL_WILDCARD.equals(supportedSubprotocol)
                    || requestedSubprotocol.equals(supportedSubprotocol)) {
                selectedSubprotocol = requestedSubprotocol;
                return requestedSubprotocol;
            }
        }
    }

    // No match found
    return null;
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:29,代碼來源:WebSocketServerHandshaker.java

示例3: checkMultipart

import io.netty.util.internal.StringUtil; //導入方法依賴的package包/類
/**
 * Check from the request ContentType if this request is a Multipart
 * request.
 */
private void checkMultipart(String contentType) throws ErrorDataDecoderException {
    // Check if Post using "multipart/form-data; boundary=--89421926422648"
    String[] headerContentType = splitHeaderContentType(contentType);
    if (headerContentType[0].toLowerCase().startsWith(HttpHeaders.Values.MULTIPART_FORM_DATA)
            && headerContentType[1].toLowerCase().startsWith(HttpHeaders.Values.BOUNDARY)) {
        String[] boundary = StringUtil.split(headerContentType[1], '=');
        if (boundary.length != 2) {
            throw new ErrorDataDecoderException("Needs a boundary value");
        }
        multipartDataBoundary = "--" + boundary[1];
        isMultipart = true;
        currentStatus = MultiPartStatus.HEADERDELIMITER;
    } else {
        isMultipart = false;
    }
}
 
開發者ID:kyle-liu,項目名稱:netty4study,代碼行數:21,代碼來源:HttpPostRequestDecoder.java

示例4: splitMultipartHeader

import io.netty.util.internal.StringUtil; //導入方法依賴的package包/類
/**
 * 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 = sb.substring(valueStart, valueEnd);
    String[] values;
    if (svalue.indexOf(';') >= 0) {
        values = splitMultipartHeaderValues(svalue);
    } else {
        values = StringUtil.split(svalue, ',');
    }
    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;
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:46,代碼來源:HttpPostMultipartRequestDecoder.java

示例5: getProtocol

import io.netty.util.internal.StringUtil; //導入方法依賴的package包/類
/**
 * Return the {@link SelectedProtocol} for the {@link SSLEngine}. If its not known yet implementations MUST return
 * {@link SelectedProtocol#UNKNOWN}.
 *
 */
protected SelectedProtocol getProtocol(SSLEngine engine) {
    String[] protocol = StringUtil.split(engine.getSession().getProtocol(), ':');
    if (protocol.length < 2) {
        // Use HTTP/1.1 as default
        return SelectedProtocol.HTTP_1_1;
    }
    SelectedProtocol selectedProtocol = SelectedProtocol.protocol(protocol[1]);
    return selectedProtocol;
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:15,代碼來源:SpdyOrHttpChooser.java

示例6: splitMultipartHeader

import io.netty.util.internal.StringUtil; //導入方法依賴的package包/類
/**
 * 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 = sb.substring(valueStart, valueEnd);
    String[] values;
    if (svalue.indexOf(';') >= 0) {
        values = StringUtil.split(svalue, ';');
    } else {
        values = StringUtil.split(svalue, ',');
    }
    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;
}
 
開發者ID:kyle-liu,項目名稱:netty4study,代碼行數:46,代碼來源:HttpPostRequestDecoder.java

示例7: determineWrapper

import io.netty.util.internal.StringUtil; //導入方法依賴的package包/類
protected ZlibWrapper determineWrapper(String acceptEncoding) {
    float starQ = -1.0f;
    float gzipQ = -1.0f;
    float deflateQ = -1.0f;
    for (String encoding: StringUtil.split(acceptEncoding, ',')) {
        float q = 1.0f;
        int equalsPos = encoding.indexOf('=');
        if (equalsPos != -1) {
            try {
                q = Float.valueOf(encoding.substring(equalsPos + 1));
            } catch (NumberFormatException e) {
                // Ignore encoding
                q = 0.0f;
            }
        }
        if (encoding.contains("*")) {
            starQ = q;
        } else if (encoding.contains("gzip") && q > gzipQ) {
            gzipQ = q;
        } else if (encoding.contains("deflate") && q > deflateQ) {
            deflateQ = q;
        }
    }
    if (gzipQ > 0.0f || deflateQ > 0.0f) {
        if (gzipQ >= deflateQ) {
            return ZlibWrapper.GZIP;
        } else {
            return ZlibWrapper.ZLIB;
        }
    }
    if (starQ > 0.0f) {
        if (gzipQ == -1.0f) {
            return ZlibWrapper.GZIP;
        }
        if (deflateQ == -1.0f) {
            return ZlibWrapper.ZLIB;
        }
    }
    return null;
}
 
開發者ID:kyle-liu,項目名稱:netty4study,代碼行數:41,代碼來源:HttpContentCompressor.java

示例8: getMultipartDataBoundary

import io.netty.util.internal.StringUtil; //導入方法依賴的package包/類
/**
 * 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);
    if (headerContentType[0].toLowerCase().startsWith(
            HttpHeaders.Values.MULTIPART_FORM_DATA.toString())) {
        int mrank = 1, crank = 2;
        if (headerContentType[1].toLowerCase().startsWith(
                HttpHeaders.Values.BOUNDARY.toString())) {
            mrank = 1;
            crank = 2;
        } else if (headerContentType[2].toLowerCase().startsWith(
                HttpHeaders.Values.BOUNDARY.toString())) {
            mrank = 2;
            crank = 1;
        } else {
            return null;
        }
        String[] boundary = StringUtil.split(headerContentType[mrank], '=');
        if (boundary.length != 2) {
            throw new ErrorDataDecoderException("Needs a boundary value");
        }
        if (headerContentType[crank].toLowerCase().startsWith(
                HttpHeaders.Values.CHARSET.toString())) {
            String[] charset = StringUtil.split(headerContentType[crank], '=');
            if (charset.length > 1) {
                return new String[] {"--" + boundary[1], charset[1]};
            }
        }
        return new String[] {"--" + boundary[1]};
    }
    return null;
}
 
開發者ID:nathanchen,項目名稱:netty-netty-5.0.0.Alpha1,代碼行數:38,代碼來源:HttpPostRequestDecoder.java

示例9: determineWrapper

import io.netty.util.internal.StringUtil; //導入方法依賴的package包/類
protected ZlibWrapper determineWrapper(CharSequence acceptEncoding) {
    float starQ = -1.0f;
    float gzipQ = -1.0f;
    float deflateQ = -1.0f;
    for (String encoding: StringUtil.split(acceptEncoding.toString(), ',')) {
        float q = 1.0f;
        int equalsPos = encoding.indexOf('=');
        if (equalsPos != -1) {
            try {
                q = Float.valueOf(encoding.substring(equalsPos + 1));
            } catch (NumberFormatException e) {
                // Ignore encoding
                q = 0.0f;
            }
        }
        if (encoding.contains("*")) {
            starQ = q;
        } else if (encoding.contains("gzip") && q > gzipQ) {
            gzipQ = q;
        } else if (encoding.contains("deflate") && q > deflateQ) {
            deflateQ = q;
        }
    }
    if (gzipQ > 0.0f || deflateQ > 0.0f) {
        if (gzipQ >= deflateQ) {
            return ZlibWrapper.GZIP;
        } else {
            return ZlibWrapper.ZLIB;
        }
    }
    if (starQ > 0.0f) {
        if (gzipQ == -1.0f) {
            return ZlibWrapper.GZIP;
        }
        if (deflateQ == -1.0f) {
            return ZlibWrapper.ZLIB;
        }
    }
    return null;
}
 
開發者ID:nathanchen,項目名稱:netty-netty-5.0.0.Alpha1,代碼行數:41,代碼來源:HttpContentCompressor.java

示例10: finishHandshake

import io.netty.util.internal.StringUtil; //導入方法依賴的package包/類
/**
 * Validates and finishes the opening handshake initiated by {@link #handshake}}.
 *
 * @param channel
 *            Channel
 * @param response
 *            HTTP response containing the closing handshake details
 */
public final void finishHandshake(Channel channel, FullHttpResponse response) {
    verify(response);

    // Verify the subprotocol that we received from the server.
    // This must be one of our expected subprotocols - or null/empty if we didn't want to speak a subprotocol
    String receivedProtocol = response.headers().get(HttpHeaders.Names.SEC_WEBSOCKET_PROTOCOL);
    receivedProtocol = receivedProtocol != null ? receivedProtocol.trim() : null;
    String expectedProtocol = expectedSubprotocol != null ? expectedSubprotocol : "";
    boolean protocolValid = false;

    if (expectedProtocol.isEmpty() && receivedProtocol == null) {
        // No subprotocol required and none received
        protocolValid = true;
        setActualSubprotocol(expectedSubprotocol); // null or "" - we echo what the user requested
    } else if (!expectedProtocol.isEmpty() && receivedProtocol != null && !receivedProtocol.isEmpty()) {
        // We require a subprotocol and received one -> verify it
        for (String protocol : StringUtil.split(expectedSubprotocol, ',')) {
            if (protocol.trim().equals(receivedProtocol)) {
                protocolValid = true;
                setActualSubprotocol(receivedProtocol);
                break;
            }
        }
    } // else mixed cases - which are all errors

    if (!protocolValid) {
        throw new WebSocketHandshakeException(String.format(
                "Invalid subprotocol. Actual: %s. Expected one of: %s",
                receivedProtocol, expectedSubprotocol));
    }

    setHandshakeComplete();

    ChannelPipeline p = channel.pipeline();
    // Remove decompressor from pipeline if its in use
    HttpContentDecompressor decompressor = p.get(HttpContentDecompressor.class);
    if (decompressor != null) {
        p.remove(decompressor);
    }

    // Remove aggregator if present before
    HttpObjectAggregator aggregator = p.get(HttpObjectAggregator.class);
    if (aggregator != null) {
        p.remove(aggregator);
    }

    ChannelHandlerContext ctx = p.context(HttpResponseDecoder.class);
    if (ctx == null) {
        ctx = p.context(HttpClientCodec.class);
        if (ctx == null) {
            throw new IllegalStateException("ChannelPipeline does not contain " +
                    "a HttpRequestEncoder or HttpClientCodec");
        }
        p.replace(ctx.name(), "ws-decoder", newWebsocketDecoder());
    } else {
        if (p.get(HttpRequestEncoder.class) != null) {
            p.remove(HttpRequestEncoder.class);
        }
        p.replace(ctx.name(),
                "ws-decoder", newWebsocketDecoder());
    }
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:71,代碼來源:WebSocketClientHandshaker.java

示例11: determineWrapper

import io.netty.util.internal.StringUtil; //導入方法依賴的package包/類
@SuppressWarnings("FloatingPointEquality")
protected ZlibWrapper determineWrapper(String acceptEncoding) {
    float starQ = -1.0f;
    float gzipQ = -1.0f;
    float deflateQ = -1.0f;
    for (String encoding: StringUtil.split(acceptEncoding, ',')) {
        float q = 1.0f;
        int equalsPos = encoding.indexOf('=');
        if (equalsPos != -1) {
            try {
                q = Float.valueOf(encoding.substring(equalsPos + 1));
            } catch (NumberFormatException e) {
                // Ignore encoding
                q = 0.0f;
            }
        }
        if (encoding.contains("*")) {
            starQ = q;
        } else if (encoding.contains("gzip") && q > gzipQ) {
            gzipQ = q;
        } else if (encoding.contains("deflate") && q > deflateQ) {
            deflateQ = q;
        }
    }
    if (gzipQ > 0.0f || deflateQ > 0.0f) {
        if (gzipQ >= deflateQ) {
            return ZlibWrapper.GZIP;
        } else {
            return ZlibWrapper.ZLIB;
        }
    }
    if (starQ > 0.0f) {
        if (gzipQ == -1.0f) {
            return ZlibWrapper.GZIP;
        }
        if (deflateQ == -1.0f) {
            return ZlibWrapper.ZLIB;
        }
    }
    return null;
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:42,代碼來源:HttpContentCompressor.java


注:本文中的io.netty.util.internal.StringUtil.split方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。