当前位置: 首页>>代码示例>>Java>>正文


Java CharsetUtil类代码示例

本文整理汇总了Java中com.couchbase.client.deps.io.netty.util.CharsetUtil的典型用法代码示例。如果您正苦于以下问题:Java CharsetUtil类的具体用法?Java CharsetUtil怎么用?Java CharsetUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CharsetUtil类属于com.couchbase.client.deps.io.netty.util包,在下文中一共展示了CharsetUtil类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: recoverState

import com.couchbase.client.deps.io.netty.util.CharsetUtil; //导入依赖的package包/类
/**
 * Initializes the {@link SessionState} from a previous snapshot with specific state information.
 *
 * If a system needs to be built that withstands outages and needs to resume where left off, this method,
 * combined with the periodic persistence of the {@link SessionState} provides resume capabilities. If you
 * need to start fresh, take a look at {@link #initializeState(StreamFrom, StreamTo)} as well as
 * {@link #recoverOrInitializeState(StateFormat, byte[], StreamFrom, StreamTo)}.
 *
 * @param format         the format used when persisting.
 * @param persistedState the opaque byte array representing the persisted state.
 * @return A {@link Completable} indicating the success or failure of the state recovery.
 */
public Completable recoverState(final StateFormat format, final byte[] persistedState) {
    return Completable.create(new Completable.OnSubscribe() {
        @Override
        public void call(CompletableSubscriber subscriber) {
            LOGGER.info("Recovering state from format {}", format);
            LOGGER.debug("PersistedState on recovery is: {}", new String(persistedState, CharsetUtil.UTF_8));

            try {
                if (format == StateFormat.JSON) {
                    sessionState().setFromJson(persistedState);
                    subscriber.onCompleted();
                } else {
                    subscriber.onError(new IllegalStateException("Unsupported StateFormat " + format));
                }
            } catch (Exception ex) {
                subscriber.onError(ex);
            }
        }
    });
}
 
开发者ID:couchbase,项目名称:java-dcp-client,代码行数:33,代码来源:Client.java

示例2: decodeChunk

import com.couchbase.client.deps.io.netty.util.CharsetUtil; //导入依赖的package包/类
/**
 * Helper method to decode and analyze the chunk.
 *
 * @param chunk the chunk to analyze.
 */
private void decodeChunk(final ByteBuf chunk) {
    responseContent.writeBytes(chunk);

    String currentChunk = responseContent.toString(CharsetUtil.UTF_8);
    int separatorIndex = currentChunk.indexOf("\n\n\n\n");
    if (separatorIndex > 0) {
        String rawConfig = currentChunk
                .substring(0, separatorIndex)
                .trim()
                .replace("$HOST", hostname.getAddress().getHostAddress());

        configStream.onNext((CouchbaseBucketConfig) BucketConfigParser.parse(rawConfig, environment));
        responseContent.clear();
        responseContent.writeBytes(currentChunk.substring(separatorIndex + 4).getBytes(CharsetUtil.UTF_8));
    }
}
 
开发者ID:couchbase,项目名称:java-dcp-client,代码行数:22,代码来源:ConfigHandler.java

示例3: hello

import com.couchbase.client.deps.io.netty.util.CharsetUtil; //导入依赖的package包/类
private void hello(ChannelHandlerContext ctx, ByteBuf msg) {
    connectionName = connectionNameGenerator.name();
    String response = MessageUtil.getContent(msg).toString(CharsetUtil.UTF_8);
    int majorVersion;
    try {
        majorVersion = Integer.parseInt(response.substring(0, 1));
    } catch (NumberFormatException e) {
        originalPromise().setFailure(
                new IllegalStateException("Version returned by the server couldn't be parsed " + response, e));
        ctx.close(ctx.voidPromise());
        return;
    }
    if (majorVersion < 5) {
        step = OPEN;
        open(ctx);
    } else {
        ByteBuf request = ctx.alloc().buffer();
        HelloRequest.init(request, Unpooled.copiedBuffer(connectionName, CharsetUtil.UTF_8));
        ctx.writeAndFlush(request);
    }
}
 
开发者ID:couchbase,项目名称:java-dcp-client,代码行数:22,代码来源:DcpConnectHandler.java

示例4: negotiate

import com.couchbase.client.deps.io.netty.util.CharsetUtil; //导入依赖的package包/类
/**
 * Helper method to walk the iterator and create a new request that defines which control param
 * should be negotiated right now.
 */
private void negotiate(final ChannelHandlerContext ctx) {
    if (controlSettings.hasNext()) {
        Map.Entry<String, String> setting = controlSettings.next();

        LOGGER.debug("Negotiating DCP Control {}: {}", setting.getKey(), setting.getValue());
        ByteBuf request = ctx.alloc().buffer();
        DcpControlRequest.init(request);
        DcpControlRequest.key(Unpooled.copiedBuffer(setting.getKey(), CharsetUtil.UTF_8), request);
        DcpControlRequest.value(Unpooled.copiedBuffer(setting.getValue(), CharsetUtil.UTF_8), request);

        ctx.writeAndFlush(request);
    } else {
        originalPromise().setSuccess();
        ctx.pipeline().remove(this);
        ctx.fireChannelActive();
        LOGGER.debug("Negotiated all DCP Control settings against Node {}", ctx.channel().remoteAddress());
    }
}
 
开发者ID:couchbase,项目名称:java-dcp-client,代码行数:23,代码来源:DcpControlHandler.java

示例5: open

import com.couchbase.client.deps.io.netty.util.CharsetUtil; //导入依赖的package包/类
private void open(ChannelHandlerContext ctx) {
    ByteBuf request = ctx.alloc().buffer();
    DcpOpenConnectionRequest.init(request);
    DcpOpenConnectionRequest.connectionName(request, Unpooled.copiedBuffer(connectionName, CharsetUtil.UTF_8));
    ctx.writeAndFlush(request);

}
 
开发者ID:couchbase,项目名称:java-dcp-client,代码行数:8,代码来源:DcpConnectHandler.java

示例6: addHttpBasicAuth

import com.couchbase.client.deps.io.netty.util.CharsetUtil; //导入依赖的package包/类
/**
 * Helper method to add authentication credentials to the config stream request.
 */
private void addHttpBasicAuth(final ChannelHandlerContext ctx, final HttpRequest request) {
    final String pw = password == null ? "" : password;
    ByteBuf raw = ctx.alloc().buffer(username.length() + pw.length() + 1);
    raw.writeBytes((username + ":" + pw).getBytes(CharsetUtil.UTF_8));
    ByteBuf encoded = Base64.encode(raw, false);
    request.headers().add(HttpHeaders.Names.AUTHORIZATION, "Basic " + encoded.toString(CharsetUtil.UTF_8));
    encoded.release();
    raw.release();
}
 
开发者ID:couchbase,项目名称:java-dcp-client,代码行数:13,代码来源:StartStreamHandler.java

示例7: testSetConnectionName

import com.couchbase.client.deps.io.netty.util.CharsetUtil; //导入依赖的package包/类
@Test
public void testSetConnectionName() {
    ByteBuf buffer = Unpooled.buffer();
    DcpOpenConnectionRequest.init(buffer);

    ByteBuf name = Unpooled.copiedBuffer("name", CharsetUtil.UTF_8);
    DcpOpenConnectionRequest.connectionName(buffer, name);

    assertEquals("name", DcpOpenConnectionRequest.connectionName(buffer).toString(CharsetUtil.UTF_8));
}
 
开发者ID:couchbase,项目名称:java-dcp-client,代码行数:11,代码来源:OpenConnectionRequestTest.java

示例8: bufToString

import com.couchbase.client.deps.io.netty.util.CharsetUtil; //导入依赖的package包/类
private static String bufToString(ByteBuf buf) {
    return new String(bufToBytes(buf), CharsetUtil.UTF_8);
}
 
开发者ID:Talend,项目名称:components,代码行数:4,代码来源:CouchbaseEventGenericRecordConverter.java


注:本文中的com.couchbase.client.deps.io.netty.util.CharsetUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。