How to convert TIS-620 string to UTF-8 string in Java? [closed]

How do I convert TIS-620 (the extended ASCII Thai Character code page) string to UTF-8 string in Java?


Asked by: Julia432 | Posted: 28-01-2022






Answer 1

import java.nio.ByteBuffer
import java.nio.CharBuffer

....

public static ByteBuffer toByteBuffer(String content, String encode) {  
      Charset charset = Charset.forName(encode);  
      ByteBuffer bb = charset.encode(content);  
       return bb;  
   }  

Pass as encode argument "UTF-8"

Answered by: Roland175 | Posted: 01-03-2022



Answer 2

private byte[] convertTis620ToUTF8(byte[] encoded)
{
    try
    {
        String theString = new String(encoded, "TIS620");
        return theString.getBytes("UTF-8");
    } 
    catch(UnsupportedEncodingException uee)
    {
        /* Didn't work out */
    }
}

...

byte[] utf8 = convertTis620ToUTF8(tis620);

Also, you might need to put charsets.jar on your classpath to support the TIS620 encoding.

Answered by: Kellan541 | Posted: 01-03-2022



Similar questions

Convert audio stream to WAV byte array in Java without temp file

Given an InputStream called in which contains audio data in a compressed format (such as MP3 or OGG), I wish to create a byte array containing a WAV conversion of the input data. Unfortunately, if you try to do this, JavaSound hands you the following error: java.io.IOException: stream length not specified I managed to get it to work by writing the wav...


java - Convert to date

I'm trying to create number of Evenement instances and set the date for them: for (int i=2004; i<2009; i++){ evenementen.add(new Evenement("Rock Werchter", "Rock", "Werchter", 200000, (Date)formatter.parse(i+"/07/03"))); But I can't seem to get it to work, Any ideas?


java - Convert PNG to bitonal TIFF

-Edit- FYI.. I am converting b&w documents scanned in as greyscale or color. 1)The first solution worked, it just reversed black & white (black background, white text). It also took nearly 10 minutes. 2)The JAI solution in the 2nd answer didn't work for me. I tried it before posting here. Has anyone worked with other libraries free or pay that handle image manipulation well? -Original...


java - How to convert a double to long without casting?

What is the best way to convert a double to a long without casting? For example: double d = 394.000; long l = (new Double(d)).longValue(); System.out.println("double=" + d + ", long=" + l);


Convert String from ASCII to EBCDIC in Java?

I need to write a 'simple' util to convert from ASCII to EBCDIC? The Ascii is coming from Java, Web and going to an AS400. I've had a google around, can't seem to find a easy solution (maybe coz there isn't one :( ). I was hoping for an opensource util or paid for util that has already been written. Like this maybe? Converter.convertToAscii(String textFromAS400) Converter.convertToEBCD...


How do I convert an audio stream to MP3 using Java?

Is it possible using Java to convert a real time audio stream from the mixer to MP3? It has to be converted chunk by chunk otherwise the memory will be exhausted. I already know how to record but only to lossless formats such as wav and aiff. I need conversion as the audio comes in.


Need to convert EPS files to jpg/png in Java

We have a webapp where people can upload various image file types and on the backend we convert them to a standard type (typically png or jpeg). Right now we are using ImageIO to do this. However the new requirement is to be able to support eps files. I haven't found any libraries that support EPS in ImageIO, or much in the way of support for reading eps files in java. Any suggestions for reading eps files and c...


java - Convert JSON to Map

What is the best way to convert a JSON code as this: { "data" : { "field1" : "value1", "field2" : "value2" } } in a Java Map in which one the keys are (field1, field2) and the values for those fields are (value1, value2). Any ideas? Should I use Json-lib for that? Or better if I write my own parser?


is there a simple way to convert my XML object back to String in java?

I have an xml document object that I need to convert into a string. Is there as simple way to do this?


java - how to convert hex to byte for the following program?

public static String asHex (byte buf[]) { StringBuffer strbuf = new StringBuffer(buf.length * 2); int i; for (i = 0; i < buf.length; i++) { if (((int) buf[i] & 0xff) < 0x10) strbuf.append("0"); strbuf.append(Long.toString((int) buf[i] & 0xff, 16)); } return strbuf.toString(); }






Still can't find your answer? Check out these amazing Java communities for help...



Java Reddit Community | Java Help Reddit Community | Dev.to Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)



top