package org.apache.cassandra.db.marshal;
/*
 * 
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 * 
 */


import java.io.UnsupportedEncodingException;

public class UTF8Type extends AbstractType
{
    public static final UTF8Type instance = new UTF8Type();

    UTF8Type() {} // singleton

    public int compare(byte[] o1, byte[] o2)
    {
        try
        {
            return new String(o1, "UTF-8").compareTo(new String(o2, "UTF-8"));
        }
        catch (UnsupportedEncodingException e)
        {
            throw new RuntimeException(e);
        }
    }

    public String getString(byte[] bytes)
    {
        try
        {
            return new String(bytes, "UTF-8");
        }
        catch (UnsupportedEncodingException e)
        {
            throw new RuntimeException(e);
        }
    }
}

@@ -853,17 +853,16 @@
 * %0A */%0A%0A
-%0A
 import j
@@ -872,36 +872,142 @@
 .io.
-UnsupportedEncodingException
+IOException;%0Aimport java.nio.charset.CharacterCodingException;%0Aimport java.util.Arrays;%0A%0Aimport org.apache.cassandra.utils.FBUtilities
 ;%0A%0Ap
@@ -1039,16 +1039,13 @@
 nds 
-Abstract
+Bytes
 Type
@@ -1155,40 +1155,37 @@
 lic 
-int compare(byte%5B%5D o1, byte%5B%5D o2
+String getString(byte%5B%5D bytes
 )%0A  
@@ -1233,65 +1233,38 @@
 urn 
-new String(o1, %22UTF-8%22).compareTo(new String(o2, %22UTF-8%22)
+FBUtilities.decodeToUTF8(bytes
 );%0A 
@@ -1283,38 +1283,34 @@
      catch (
-UnsupportedEnc
+CharacterC
 odingExcepti
@@ -1339,39 +1339,39 @@
       throw new 
-Runtime
+Marshal
 Exception(e);%0A  
@@ -1368,253 +1368,54 @@
 ion(
-e);%0A        %7D%0A    %7D%0A%0A    public String getString(byte%5B%5D bytes)%0A    %7B%0A        try%0A        %7B%0A            return new String(bytes, %22UTF-8%22);%0A        %7D%0A        catch (UnsupportedEncodingException e)%0A        %7B%0A            throw new RuntimeException(e
+%22invalid UTF8 bytes %22 + Arrays.toString(bytes)
 );%0A 

use lexical comparison for UTF8Type. patch by Nick Bailey; reviewed by jbellis for CASSANDRA-1232