se.datadosen.util
Class StringCodec

java.lang.Object
  extended by se.datadosen.util.StringCodec

public class StringCodec
extends java.lang.Object

Convert Strings to and from byte array representation with auto detecting and marking of UTF-8 and UTF-16 encodings. This class is under LGPL licence


Field Summary
protected static java.util.Map encMap
           
 
Constructor Summary
StringCodec()
           
 
Method Summary
 java.lang.String decode(byte[] buf)
           
 java.lang.String decode(byte[] buf, int offset, int length)
           
 java.lang.String decode(byte[] buf, int offset, int length, java.lang.String defaultEncoding)
           
 java.lang.String decode(byte[] buf, java.lang.String defaultEncoding)
           
 byte[] encode(java.lang.String s)
           
 byte[] encode(java.lang.String s, java.lang.String encoding)
           
 java.lang.String getDetectedEncoding()
           
 boolean isAddSignature()
          Decide if this class is to add signature byte sequence indicating UTF-8 and UTF-16 Default is to not add signature
static boolean isEncodable(java.lang.String s, java.lang.String encoding)
           
static boolean isUTF8(byte[] buf)
           
static boolean isUTF8(byte[] buf, int offset, int length)
           
 void setAddSignature(boolean addIt)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

encMap

protected static java.util.Map encMap
Constructor Detail

StringCodec

public StringCodec()
Method Detail

isAddSignature

public boolean isAddSignature()
Decide if this class is to add signature byte sequence indicating UTF-8 and UTF-16 Default is to not add signature


setAddSignature

public void setAddSignature(boolean addIt)

encode

public byte[] encode(java.lang.String s,
                     java.lang.String encoding)
              throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

encode

public byte[] encode(java.lang.String s)
              throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

decode

public java.lang.String decode(byte[] buf)
                        throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

decode

public java.lang.String decode(byte[] buf,
                               java.lang.String defaultEncoding)
                        throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

decode

public java.lang.String decode(byte[] buf,
                               int offset,
                               int length)
                        throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

decode

public java.lang.String decode(byte[] buf,
                               int offset,
                               int length,
                               java.lang.String defaultEncoding)
                        throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException

isUTF8

public static boolean isUTF8(byte[] buf)

isUTF8

public static boolean isUTF8(byte[] buf,
                             int offset,
                             int length)

getDetectedEncoding

public java.lang.String getDetectedEncoding()

isEncodable

public static boolean isEncodable(java.lang.String s,
                                  java.lang.String encoding)
                           throws java.io.UnsupportedEncodingException
Throws:
java.io.UnsupportedEncodingException