Java Code Examples for com.alibaba.csp.sentinel.config.SentinelConfig#charset()

The following examples show how to use com.alibaba.csp.sentinel.config.SentinelConfig#charset() . 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: HttpEventTask.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
private static String readLine(InputStream in) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream(64);
    int data;
    while (true) {
        data = in.read();
        if (data < 0) {
            break;
        }
        if (data == '\n') {
            break;
        }
        bos.write(data);
    }
    byte[] arr = bos.toByteArray();
    if (arr.length > 0 && arr[arr.length - 1] == '\r') {
        return new String(arr, 0, arr.length - 1, SentinelConfig.charset());
    }
    return new String(arr, SentinelConfig.charset());
}
 
Example 2
Source File: HttpEventTask.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
private static String readBody(InputStream in, int bodyLength)
    throws IOException, RequestException {
    byte[] buf = new byte[bodyLength];
    int pos = 0;
    while (pos < bodyLength) {
        int l = in.read(buf, pos, Math.min(512, bodyLength - pos));
        if (l < 0) {
            break;
        }
        if (l == 0) {
            continue;
        }
        pos += l;
    }
    // Only allow partial
    return new String(buf, 0, pos, SentinelConfig.charset());
}
 
Example 3
Source File: EtcdConfig.java    From Sentinel with Apache License 2.0 5 votes vote down vote up
public static String getCharset() {
    String etcdCharset = SentinelConfig.getConfig(CHARSET);
    if (StringUtil.isNotBlank(etcdCharset)) {
        return etcdCharset;
    }
    return SentinelConfig.charset();
}