Example usage for io.netty.util CharsetUtil UTF_8

List of usage examples for io.netty.util CharsetUtil UTF_8

Introduction

In this page you can find the example usage for io.netty.util CharsetUtil UTF_8.

Prototype

Charset UTF_8

To view the source code for io.netty.util CharsetUtil UTF_8.

Click Source Link

Document

8-bit UTF (UCS Transformation Format)

Usage

From source file:com.couchbase.client.core.message.kv.subdoc.multi.LookupResult.java

License:Open Source License

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (o == null || getClass() != o.getClass())
        return false;

    LookupResult that = (LookupResult) o;

    if (statusCode != that.statusCode)
        return false;
    if (status != that.status)
        return false;
    if (path != null ? !path.equals(that.path) : that.path != null)
        return false;
    if (operation != that.operation)
        return false;
    if (value == null)
        return that.value == null;

    return value.toString(CharsetUtil.UTF_8).equals(that.value.toString(CharsetUtil.UTF_8));

}

From source file:com.couchbase.client.core.message.kv.subdoc.multi.LookupResult.java

License:Open Source License

@Override
public int hashCode() {
    int result = (int) statusCode;
    result = 31 * result + (status != null ? status.hashCode() : 0);
    result = 31 * result + (path != null ? path.hashCode() : 0);
    result = 31 * result + (operation != null ? operation.hashCode() : 0);
    if (value != null) {
        result = 31 * result + value.toString(CharsetUtil.UTF_8).hashCode();
    }/* w  ww .ja va  2s  .  c o m*/
    return result;
}

From source file:com.couchbase.client.core.message.kv.subdoc.multi.LookupResult.java

License:Open Source License

@Override
public String toString() {
    StringBuilder builder = new StringBuilder();
    builder.append(operation()).append('(').append(path()).append(") = ").append(status());
    if (value.readableBytes() > 0) {
        builder.append(": ").append(value().toString(CharsetUtil.UTF_8));
    }/*w  ww .  ja v a2s .  co  m*/
    return builder.toString();
}

From source file:com.couchbase.client.core.message.kv.subdoc.multi.MultiResult.java

License:Apache License

@Override
public boolean equals(Object o) {
    if (this == o)
        return true;
    if (o == null || getClass() != o.getClass())
        return false;

    MultiResult that = (MultiResult) o;//from www  . jav  a2 s  .co  m

    if (statusCode != that.statusCode)
        return false;
    if (status != that.status)
        return false;
    if (path != null ? !path.equals(that.path) : that.path != null)
        return false;
    if (operation != that.operation)
        return false;
    if (value == null)
        return that.value == null;

    return value.toString(CharsetUtil.UTF_8).equals(that.value.toString(CharsetUtil.UTF_8));

}

From source file:com.couchbase.client.core.message.kv.subdoc.multi.MultiResult.java

License:Apache License

@Override
public String toString() {
    StringBuilder builder = new StringBuilder();
    builder.append(operation()).append('(').append(path()).append("): ").append(status());
    if (value.readableBytes() > 0) {
        builder.append(" = ").append(value().toString(CharsetUtil.UTF_8));
    }/* w w w.j a  v a 2 s . c o m*/
    return builder.toString();
}

From source file:com.couchbase.client.core.message.kv.subdoc.multi.SubMultiLookupRequest.java

License:Apache License

private static ByteBuf encode(List<LookupCommand> commands) {
    CompositeByteBuf compositeBuf = Unpooled.compositeBuffer(commands.size()); //FIXME pooled allocator?
    for (LookupCommand command : commands) {
        byte[] pathBytes = command.path().getBytes(CharsetUtil.UTF_8);
        short pathLength = (short) pathBytes.length;

        ByteBuf commandBuf = Unpooled.buffer(4 + pathLength); //FIXME a way of using the pooled allocator?
        commandBuf.writeByte(command.opCode());
        commandBuf.writeByte(0); //no flags supported for lookup
        commandBuf.writeShort(pathLength);
        //no value length
        commandBuf.writeBytes(pathBytes);

        compositeBuf.addComponent(commandBuf);
        compositeBuf.writerIndex(compositeBuf.writerIndex() + commandBuf.readableBytes());
    }/*from   w  w w.  j a va  2  s .  c  o m*/
    return compositeBuf;
}

From source file:com.couchbase.client.core.message.kv.subdoc.multi.SubMultiMutationRequest.java

License:Apache License

private static ByteBuf encode(List<MutationCommand> commands) {
    //FIXME a way of using the pooled allocator?
    CompositeByteBuf compositeBuf = Unpooled.compositeBuffer(commands.size());
    for (MutationCommand command : commands) {
        byte[] pathBytes = command.path().getBytes(CharsetUtil.UTF_8);
        short pathLength = (short) pathBytes.length;

        ByteBuf commandBuf = Unpooled.buffer(4 + pathLength + command.fragment().readableBytes());
        commandBuf.writeByte(command.opCode());
        if (command.createIntermediaryPath()) {
            commandBuf.writeByte(KeyValueHandler.SUBDOC_BITMASK_MKDIR_P); //0 | SUBDOC_BITMASK_MKDIR_P
        } else {//w  w  w  . j av a  2s  . com
            commandBuf.writeByte(0);
        }
        commandBuf.writeShort(pathLength);
        commandBuf.writeInt(command.fragment().readableBytes());
        commandBuf.writeBytes(pathBytes);

        //copy the fragment but don't move indexes (in case it is retained and reused)
        commandBuf.writeBytes(command.fragment(), command.fragment().readerIndex(),
                command.fragment().readableBytes());
        //eagerly release the fragment once it's been copied
        command.fragment().release();

        //add the command to the composite buffer
        compositeBuf.addComponent(commandBuf);
        compositeBuf.writerIndex(compositeBuf.writerIndex() + commandBuf.readableBytes());
    }
    return compositeBuf;
}

From source file:com.couchbase.client.core.message.kv.subdoc.simple.AbstractSubdocRequest.java

License:Apache License

/**
 * Creates a new {@link AbstractSubdocRequest}.
 *
 * @param key           the key of the document.
 * @param path          the subdocument path to consider inside the document.
 * @param bucket        the bucket of the document.
 * @param observable    the observable which receives responses.
 * @param restOfContent the optional remainder of the {@link #content()} of the final protocol message, or null if not applicable
 * @throws NullPointerException if the path is null (see {@link #EXCEPTION_NULL_PATH})
 *///from ww  w  .  j a  va 2s. c  o m
public AbstractSubdocRequest(String key, String path, String bucket,
        Subject<CouchbaseResponse, CouchbaseResponse> observable, ByteBuf... restOfContent) {
    super(key, bucket, null, observable);
    this.path = path;
    ByteBuf pathByteBuf;
    if (path == null || path.isEmpty()) {
        pathByteBuf = Unpooled.EMPTY_BUFFER;
    } else {
        pathByteBuf = Unpooled.wrappedBuffer(path.getBytes(CharsetUtil.UTF_8));
    }
    this.pathLength = pathByteBuf.readableBytes();
    this.content = createContent(pathByteBuf, restOfContent);

    //checking nullity here allows to release all of restOfContent through cleanUpAndThrow releasing content()
    if (this.path == null) {
        cleanUpAndThrow(EXCEPTION_NULL_PATH);
    }
}

From source file:com.couchbase.client.core.message.kv.subdoc.simple.SubCounterRequest.java

License:Apache License

private static ByteBuf deltaToFragment(long delta) {
    String sDelta = "" + delta;
    return Unpooled.copiedBuffer(sDelta, CharsetUtil.UTF_8);
}

From source file:com.couchbase.client.core.node.locate.BinaryLocator.java

License:Open Source License

private long ketamaHash(final String key) {
    try {/*from   ww  w  .  ja va  2 s.  c o  m*/
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(key.getBytes(CharsetUtil.UTF_8));
        byte[] digest = md5.digest();
        long rv = ((long) (digest[3] & 0xFF) << 24) | ((long) (digest[2] & 0xFF) << 16)
                | ((long) (digest[1] & 0xFF) << 8) | (digest[0] & 0xFF);
        return rv & 0xffffffffL;
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException("Could not encode ketama hash.", e);
    }
}