encoder and decoder use a supplied ByteBuffer : Charset « I18N « Java






encoder and decoder use a supplied ByteBuffer

    


import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;

public class Main {
  public static void main(String[] argv) throws Exception {
    Charset charset = Charset.forName("ISO-8859-1");
    CharsetDecoder decoder = charset.newDecoder();
    CharsetEncoder encoder = charset.newEncoder();
    ByteBuffer bbuf = ByteBuffer.allocateDirect(1024);

    CharBuffer cbuf = CharBuffer.allocate(1024);

    encoder.encode(cbuf, bbuf, false);

    bbuf.flip();

    decoder.decode(bbuf, cbuf, false);

    cbuf.flip();

  }
}

   
    
    
    
  








Related examples in the same category

1.List the Charset in your system
2.Converting Between Strings (Unicode) and Other Character Set Encodings
3.Charset encoding test
4.Translate Charset
5.Detect non-ASCII characters in string
6.Displays Charsets and aliasesDisplays Charsets and aliases
7.Encode and DecodeEncode and Decode
8.extends CharsetDecoder to create Base64 Decoder
9.extends Charset to create Hex Charset
10.Get the default charset
11.Charset Toolkit
12.Defines common charsets supported in all Java platforms.
13.How to auto-detect a file's encoding