incubator-cassandra-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From A J <s5a...@gmail.com>
Subject Re: java thrift error
Date Tue, 20 Dec 2011 21:49:53 GMT
The following worked:
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CodingErrorAction;
.....
public static Charset charset = Charset.forName("UTF-8");
public static CharsetEncoder encoder = charset.newEncoder();
public static CharsetDecoder decoder = charset.newDecoder();

public static ByteBuffer str_to_bb(String msg){
  try{
    return encoder.encode(CharBuffer.wrap(msg));
  }catch(Exception e){e.printStackTrace();}
  return null;
}

and then instead of "count_key".getBytes("UTF-8")
do
str_to_bb("count_key")

On Tue, Dec 20, 2011 at 4:03 PM, Dave Brosius <dbrosius@mebigfatguy.com>wrote:

> A ByteBuffer is not a byte[] to convert a String to a ByteBuffer do
> something like
>
> public static ByteBuffer toByteBuffer(String value)     throws UnsupportedEncodingException
   {        return ByteBuffer.wrap(value.getBytes("UTF-8"));    }
>
>
>
> see http://wiki.apache.org/cassandra/ThriftExamples
>
>
> *----- Original Message -----*
> *From:* "A J" <s5alye@gmail.com>
> *Sent:* Tue, December 20, 2011 15:52
> *Subject:* java thrift error
>
> The following syntax :
> import org.apache.cassandra.thrift.*;
> .....
> .....
> ColumnOrSuperColumn col = client.get("count_key".getBytes("UTF-8"),
> cp, ConsistencyLevel.QUORUM);
>
>
> is giving the error:
> get(java.nio.ByteBuffer,org.apache.cassandra.thrift.ColumnPath,org.apache.cassandra.thrift.ConsistencyLevel)
> in org.apache.cassandra.thrift.Cassandra.Client cannot be applied to
> (byte[],org.apache.cassandra.thrift.ColumnPath,org.apache.cassandra.thrift.ConsistencyLevel)
>
>
> Any idea on how to cast?
>
> Thanks.
>
>

Mime
View raw message