All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ning.api.client.auth.UTF8Codec Maven / Gradle / Ivy

There is a newer version: 0.5.1
Show newest version
package com.ning.api.client.auth;

import java.io.UnsupportedEncodingException;
//import java.nio.charset.Charset;

/**
 * Wrapper class for (more) efficient UTF-8 encoding and decoding
 */
public class UTF8Codec
{
    // Crap: Android does not have methods needed....
    //private final Charset utf8;
    
    public UTF8Codec() {
        //utf8 = Charset.forName("UTF-8");
    }

    public byte[] toUTF8(String input) {
//        return input.getBytes(utf8);
        try {
            return input.getBytes("UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("UTF-8 encoder not found");
        }
    }

    public String fromUTF8(byte[] input) {
        return fromUTF8(input, 0, input.length);
    }
    
    public String fromUTF8(byte[] input, int offset, int len) {
//        return new String(input, offset, len, utf8);
        try {
            return new String(input, offset, len, "UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException("UTF-8 decoder not found");
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy