java.nio.charset

Class Charset

Implemented Interfaces:
Comparable<T>

public abstract class Charset
extends Object
implements Comparable<T>

A named mapping between sequences of sixteen-bit Unicode code units and sequences of bytes. This class defines methods for creating decoders and encoders and for retrieving the various names associated with a charset. Instances of this class are immutable.

This class also defines static methods for testing whether a particular charset is supported, for locating charset instances by name, and for constructing a map that contains every charset for which support is available in the current Java virtual machine. Support for new charsets can be added via the service-provider interface defined in the CharsetProvider class.

All of the methods defined in this class are safe for use by multiple concurrent threads.

Charset names

Charsets are named by strings composed of the following characters:

A charset name must begin with either a letter or a digit. The empty string is not a legal charset name. Charset names are not case-sensitive; that is, case is always ignored when comparing charset names. Charset names generally follow the conventions documented in
RFC 2278: IANA Charset Registration Procedures.

Every charset has a canonical name and may also have one or more aliases. The canonical name is returned by the name method of this class. Canonical names are, by convention, usually in upper case. The aliases of a charset are returned by the aliases method.

Some charsets have an historical name that is defined for compatibility with previous versions of the Java platform. A charset's historical name is either its canonical name or one of its aliases. The historical name is returned by the getEncoding() methods of the InputStreamReader and OutputStreamWriter classes.

If a charset listed in the IANA Charset Registry is supported by an implementation of the Java platform then its canonical name must be the name listed in the registry. Many charsets are given more than one name in the registry, in which case the registry identifies one of the names as MIME-preferred. If a charset has more than one registry name then its canonical name must be the MIME-preferred name and the other names in the registry must be valid aliases. If a supported charset is not listed in the IANA registry then its canonical name must begin with one of the strings "X-" or "x-".

The IANA charset registry does change over time, and so the canonical name and the aliases of a particular charset may also change over time. To ensure compatibility it is recommended that no alias ever be removed from a charset, and that if the canonical name of a charset is changed then its previous canonical name be made into an alias.

Standard charsets

Every implementation of the Java platform is required to support the following standard charsets. Consult the release documentation for your implementation to see if any other charsets are supported. The behavior of such optional charsets may differ between implementations.

Charset

Description

US-ASCIISeven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set
ISO-8859-1  ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1
UTF-8Eight-bit UCS Transformation Format
UTF-16BESixteen-bit UCS Transformation Format, big-endian byte order
UTF-16LESixteen-bit UCS Transformation Format, little-endian byte order
UTF-16Sixteen-bit UCS Transformation Format, byte order identified by an optional byte-order mark

The UTF-8 charset is specified by RFC 2279; the transformation format upon which it is based is specified in Amendment 2 of ISO 10646-1 and is also described in the Unicode Standard.

The UTF-16 charsets are specified by RFC 2781; the transformation formats upon which they are based are specified in Amendment 1 of ISO 10646-1 and are also described in the Unicode Standard.

The UTF-16 charsets use sixteen-bit quantities and are therefore sensitive to byte order. In these encodings the byte order of a stream may be indicated by an initial byte-order mark represented by the Unicode character '\uFEFF'. Byte-order marks are handled as follows:

In any case, when a byte-order mark is read at the beginning of a decoding operation it is omitted from the resulting sequence of characters. Byte order marks occuring after the first element of an input sequence are not omitted since the same code is used to represent ZERO-WIDTH NON-BREAKING SPACE.

Every instance of the Java virtual machine has a default charset, which may or may not be one of the standard charsets. The default charset is determined during virtual-machine startup and typically depends upon the locale and charset being used by the underlying operating system.

Terminology

The name of this class is taken from the terms used in RFC 2278.="">RFC 2278." In="In" that="that" document="document" a="a" charset="charset" is="is" defined="defined" as="as" the="the" combination="combination" of="of" a="a" coded="coded" character="character" set="set" and="and" a="a" character-encoding="character-encoding" scheme.="scheme."

="

" A="A" coded="coded" character="character" set="set" is="is" a="a" mapping="mapping" between="between" a="a" set="set" of="of" abstract="abstract" characters="characters" and="and" a="a" set="set" of="of" integers.="integers." US-ASCII,="US-ASCII," ISO 8859-1,="ISO 8859-1," JIS X 0201,="JIS X 0201," and="and" full="full" Unicode,="Unicode," which="which" is="is" the="the" same="same" as="as" ISO 10646-1,="ISO 10646-1," are="are" examples="examples" of="of" coded="coded" character="character" sets.="sets."

="

" A="A" character-encoding="character-encoding" scheme="scheme" is="is" a="a" mapping="mapping" between="between" a="a" coded="coded" character="character" set="set" and="and" a="a" set="set" of="of" octet="octet" (eight-bit="(eight-bit" byte)="byte)" sequences.="sequences." UTF-8,="UTF-8," UCS-2,="UCS-2," UTF-16,="UTF-16," ISO 2022,="ISO 2022," and="and" EUC="EUC" are="are" examples="examples" of="of" character-encoding="character-encoding" schemes.="schemes." Encoding="Encoding" schemes="schemes" are="are" often="often" associated="associated" with="with" a="a" particular="particular" coded="coded" character="character" set;="set;" UTF-8,="UTF-8," for="for" example,="example," is="is" used="used" only="only" to="to" encode="encode" Unicode.="Unicode." Some="Some" schemes,="schemes," however,="however," are="are" associated="associated" with="with" multiple="multiple" character="character" sets;="sets;" EUC,="EUC," for="for" example,="example," can="can" be="be" used="used" to="to" encode="encode" characters="characters" in="in" a="a" variety="variety" of="of" Asian="Asian" character="character" sets.="sets."

="

" When="When" a="a" coded="coded" character="character" set="set" is="is" used="used" exclusively="exclusively" with="with" a="a" single="single" character-encoding="character-encoding" scheme="scheme" then="then" the="the" corresponding="corresponding" charset="charset" is="is" usually="usually" named="named" for="for" the="the" character="character" set;="set;" otherwise="otherwise" a="a" charset="charset" is="is" usually="usually" named="named" for="for" the="the" encoding="encoding" scheme="scheme" and,="and," possibly,="possibly," the="the" locale="locale" of="of" the="the" character="character" sets="sets" that="that" it="it" supports.="supports." Hence="Hence" US-ASCII="US-ASCII" is="is" the="the" name="name" of="of" the="the" charset="charset" for="for" US-ASCII="US-ASCII" while="while" EUC-JP="EUC-JP" is="is" the="the" name="name" of="of" the="the" charset="charset" that="that" encodes="encodes" the="the" JIS X 0201,="JIS X 0201," JIS X 0208,="JIS X 0208," and="and" JIS X 0212="JIS X 0212" character="character" sets.="sets."

="

" The="The" native="native" character="character" encoding="encoding" of="of" the="the" Java="Java" programming="programming" language="language" is="is" UTF-16.="UTF-16." A="A" charset="charset" in="in" the="the" Java="Java" platform="platform" therefore="therefore" defines="defines" a="a" mapping="mapping" between="between" sequences="sequences" of="of" sixteen-bit="sixteen-bit" UTF-16="UTF-16" code="code" units="units" and="and" sequences="sequences" of="of" bytes.="bytes."

="

">
Since:
1.4
See Also:
CharsetDecoder, CharsetEncoder, CharsetProvider, Character

Constructor Summary

Charset(String canonicalName, String[] aliases)
Initializes a new charset with the given canonical name and alias set.

Method Summary

Set
aliases()
Returns a set containing this charset's aliases.
static SortedMap
availableCharsets()
Constructs a sorted map from canonical charset names to charset objects.
boolean
canEncode()
Tells whether or not this charset supports encoding.
int
compareTo(Charset that)
Compares this charset to another.
abstract boolean
contains(Charset cs)
Tells whether or not this charset contains the given charset.
CharBuffer
decode(ByteBuffer bb)
Convenience method that decodes bytes in this charset into Unicode characters.
static Charset
defaultCharset()
Returns the default charset of this Java virtual machine.
String
displayName()
Returns this charset's human-readable name for the default locale.
String
displayName(Locale locale)
Returns this charset's human-readable name for the given locale.
ByteBuffer
encode(String str)
Convenience method that encodes a string into bytes in this charset.
ByteBuffer
encode(CharBuffer cb)
Convenience method that encodes Unicode characters into bytes in this charset.
boolean
equals(Object ob)
Tells whether or not this object is equal to another.
static Charset
forName(String charsetName)
Returns a charset object for the named charset.
int
hashCode()
Computes a hashcode for this charset.
boolean
isRegistered()
Tells whether or not this charset is registered in the IANA Charset Registry.
static boolean
isSupported(String charsetName)
Tells whether the named charset is supported.
String
name()
Returns this charset's canonical name.
abstract CharsetDecoder
newDecoder()
Constructs a new decoder for this charset.
abstract CharsetEncoder
newEncoder()
Constructs a new encoder for this charset.
String
toString()
Returns a string describing this charset.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

Charset

protected Charset(String canonicalName,
                  String[] aliases)
Initializes a new charset with the given canonical name and alias set.
Parameters:
canonicalName - The canonical name of this charset
aliases - An array of this charset's aliases, or null if it has no aliases
Throws:
IllegalCharsetNameException - If the canonical name or any of the aliases are illegal

Method Details

aliases

public final Set aliases()
Returns a set containing this charset's aliases.
Returns:
An immutable set of this charset's aliases
Usages and Demos :

View More Examples of aliases()
   1: 
   2: package gnu.java.nio.charset;
   3: 
   4:         ...
   5: import java.nio.charset.Charset;
   6:         ...
   7: import java.nio.charset.spi.CharsetProvider;
   8: import java.util.Collections;
   9:         ...
  10: 
  11:     for (Iterator i = cs.aliases().iterator (); i.hasNext (); )

View Full Code Here

availableCharsets

public static SortedMap availableCharsets()
Constructs a sorted map from canonical charset names to charset objects.

The map returned by this method will have one entry for each charset for which support is available in the current Java virtual machine. If two or more supported charsets have the same canonical name then the resulting map will contain just one of them; which one it will contain is not specified.

The invocation of this method, and the subsequent use of the resulting map, may cause time-consuming disk or network I/O operations to occur. This method is provided for applications that need to enumerate all of the available charsets, for example to allow user charset selection. This method is not used by the forName method, which instead employs an efficient incremental lookup algorithm.

This method may return different results at different times if new charset providers are dynamically made available to the current Java virtual machine. In the absence of such changes, the charsets returned by this method are exactly those that can be retrieved via the forName method.

Returns:
An immutable, case-insensitive map from canonical charset names to charset objects
Usages and Demos :

View More Examples of availableCharsets()
   1: 
   2: import java.nio.charset.*;
   3: 
   4:         ...
   5:   private static final Object[] CHARSETS=
   6:     Charset.availableCharsets().values().toArray();
   7: 
   8:         ...
   9:   public static final Charset[] getCharsets()
  10:   {
  11:         ...
  12:     int       l=CHARSETS.length;
  13:     Charset[] r=new Charset[l];

View Full Code Here
   1: import java.nio.charset.*;
   2: import java.util.*;
   3:         ...
   4:   public static void main(String[] args) {
   5:     SortedMap<String,Charset> charSets =
   6:         ...
   7:       Charset.availableCharsets();
   8:     Iterator<String> it = charSets.keySet().iterator();

View Full Code Here
   1: package sk.uniba.euromath.tests;
   2: import java.nio.charset.Charset;
   3: public class CharsetsTest {
   4:         ...
   5:         TestTools.printTimer();
   6:         for (String charName : Charset.availableCharsets().keySet()) {
   7:             System.out.print(charName + ": ");
   8:         ...
   9:             Charset c = Charset.availableCharsets().get(charName);
  10:             for (String alias : c.aliases()) {

View Full Code Here
   1: 
   2: import java.nio.charset.Charset;
   3: import java.util.Iterator;
   4:         ...
   5:         System.out.println("\n\n");
   6:         Map m = Charset.availableCharsets();
   7:         for( Iterator itr=m.keySet().iterator(); itr.hasNext(); ) {
   8:         ...
   9:         try {
  10:             Charset cs = Charset.forName(name);
  11:             System.out.println(name+" is suppoted. canonical="+cs);

View Full Code Here
   1: import java.awt.GraphicsEnvironment;
   2: import java.nio.charset.Charset;
   3: import java.util.Arrays;
   4:         ...
   5: 
   6:     SortedMap map = Charset.availableCharsets();
   7:     String[] charSets = new String[map.size()];
   8:     int i = 0;
   9:     for (Iterator iter = map.keySet().iterator(); iter.hasNext(); i++) {

View Full Code Here

canEncode

public boolean canEncode()
Tells whether or not this charset supports encoding.

Nearly all charsets support encoding. The primary exceptions are special-purpose auto-detect charsets whose decoders can determine which of several possible encoding schemes is in use by examining the input byte sequence. Such charsets do not support encoding because there is no way to determine which encoding should be used on output. Implementations of such charsets should override this method to return false.

Returns:
true if, and only if, this charset supports encoding

compareTo

public final int compareTo(Charset that)
Compares this charset to another.

Charsets are ordered by their canonical names, without regard to case.

Parameters:
that - The charset to which this charset is to be compared
Returns:
A negative integer, zero, or a positive integer as this charset is less than, equal to, or greater than the specified charset

contains

public abstract boolean contains(Charset cs)
Tells whether or not this charset contains the given charset.

A charset C is said to contain a charset D if, and only if, every character representable in D is also representable in C. If this relationship holds then it is guaranteed that every string that can be encoded in D can also be encoded in C without performing any replacements.

That C contains D does not imply that each character representable in C by a particular byte sequence is represented in D by the same byte sequence, although sometimes this is the case.

Every charset contains itself.

This method computes an approximation of the containment relation: If it returns true then the given charset is known to be contained by this charset; if it returns false, however, then it is not necessarily the case that the given charset is not contained in this charset.

Returns:
true if, and only if, the given charset is contained in this charset

decode

public final CharBuffer decode(ByteBuffer bb)
Convenience method that decodes bytes in this charset into Unicode characters.

An invocation of this method upon a charset cs returns the same result as the expression

     cs.newDecoder()
       .onMalformedInput(CodingErrorAction.REPLACE)
       .onUnmappableCharacter(CodingErrorAction.REPLACE)
       .decode(bb); 
except that it is potentially more efficient because it can cache decoders between successive invocations.

This method always replaces malformed-input and unmappable-character sequences with this charset's default replacement byte array. In order to detect such sequences, use the CharsetDecoder.decode(ByteBuffer) method directly.

Parameters:
bb - The byte buffer to be decoded
Returns:
A char buffer containing the decoded characters
Usages and Demos :

View More Examples of decode(ByteBuffer bb)
   1: import java.nio.ByteBuffer;
   2: import java.nio.charset.Charset;
   3: 
   4:         ...
   5:     super(null);
   6:     Charset utf8 = Charset.forName("UTF-8");
   7:     ByteBuffer idBuf = utf8.encode(identity);
   8:         ...
   9:     Charset utf8 = Charset.forName("UTF-8");
  10:     return utf8.decode((ByteBuffer) buffer.duplicate().position(2).limit
  11:                        (identityLength())).toString();

View Full Code Here
   1: import java.nio.CharBuffer;
   2: import java.nio.charset.Charset;
   3: 
   4:         ...
   5:     super(null);
   6:     Charset utf8 = Charset.forName("UTF-8");
   7:     ByteBuffer idBuf = utf8.encode(CharBuffer.wrap(identity));
   8:         ...
   9:     Charset utf8 = Charset.forName("UTF-8");
  10:     return utf8.decode((ByteBuffer) buffer.duplicate().position(2).limit(length())).toString();
  11:   }

View Full Code Here
   1: import java.nio.ByteOrder;
   2: import java.nio.charset.Charset;
   3: 
   4:         ...
   5:   {
   6:     Charset utf8 = Charset.forName("UTF-8");
   7:     ByteBuffer identityHintBuffer = utf8.encode(identityHint);
   8:         ...
   9:     Charset utf8 = Charset.forName("UTF-8");
  10:     return utf8.decode((ByteBuffer) buffer.duplicate().position(2).limit(length())).toString();
  11:   }

View Full Code Here
   1: import java.nio.ByteOrder;
   2: import java.nio.charset.Charset;
   3: 
   4:         ...
   5:     super(null);
   6:     Charset utf8 = Charset.forName("UTF-8");
   7:     ByteBuffer idBuf = utf8.encode(identity);
   8:         ...
   9:     Charset utf8 = Charset.forName("UTF-8");
  10:     return utf8.decode((ByteBuffer) buffer.duplicate().position(2).limit
  11:                        (identityLength())).toString();

View Full Code Here
   1: import java.nio.ByteOrder;
   2: import java.nio.charset.Charset;
   3: 
   4:         ...
   5:   {
   6:     Charset utf8 = Charset.forName("UTF-8");
   7:     ByteBuffer hintBuf = utf8.encode(identityHint);
   8:         ...
   9:     Charset utf8 = Charset.forName("UTF-8");
  10:     return utf8.decode((ByteBuffer) buffer.duplicate().position(2).limit
  11:                        (hintLength())).toString();

View Full Code Here

defaultCharset

public static Charset defaultCharset()
Returns the default charset of this Java virtual machine.

The default charset is determined during virtual-machine startup and typically depends upon the locale and charset of the underlying operating system.

Returns:
A charset object for the default charset
Since:
1.5
Usages and Demos :

View More Examples of defaultCharset()
   1: import java.nio.channels.*;
   2: import java.nio.charset.*;
   3: public class FileChannelTester {
   4:   public static void main(String args[])throws IOException{
   5:     final int BSIZE=1024;

View Full Code Here
   1: import java.nio.channels.ReadableByteChannel;
   2: import java.nio.charset.Charset;
   3:         ...
   4: import java.nio.charset.CharsetDecoder;
   5: 
   6:         ...
   7:   {
   8:     this(in, Charset.defaultCharset());
   9:   }
  10:         ...
  11:   {
  12:     this(in, charset(encoding));

View Full Code Here
   1: import java.nio.channels.WritableByteChannel;
   2: import java.nio.charset.Charset;
   3:         ...
   4: import java.nio.charset.CharsetEncoder;
   5: 
   6:         ...
   7:   {
   8:     this(out, Charset.defaultCharset());
   9:   }
  10:         ...
  11:   {
  12:     this(out, charset(encoding));

View Full Code Here
   1: import java.util.Map;
   2: import java.nio.charset.Charset;
   3: 
   4:         ...
   5: 
   6:                 Charset cs = Charset.defaultCharset();
   7: 
   8:                 FileOutputStream out = new FileOutputStream(new File(destdir,value));
   9:                 try {

View Full Code Here
   1: import java.net.URLConnection;
   2: import java.nio.charset.Charset;
   3: import java.util.Arrays;
   4:         ...
   5: 
   6:     public static Charset getCharset(String type) {
   7:         ...
   8:         int x = type.indexOf("charset=");
   9:         if (x != -1)
  10:         ...
  11:                     .trim());
  12:         return Charset.defaultCharset();

View Full Code Here

displayName

public String displayName()
Returns this charset's human-readable name for the default locale.

The default implementation of this method simply returns this charset's canonical name. Concrete subclasses of this class may override this method in order to provide a localized display name.

Returns:
The display name of this charset in the default locale
Usages and Demos :

View More Examples of displayName()
   1: import java.io.UnsupportedEncodingException;
   2: import java.nio.charset.Charset;
   3: import java.util.Date;
   4:         ...
   5:         final String charSetName = System.getProperty("file.encoding");
   6:         final Charset charSet = Charset.forName(charSetName);
   7:         ...
   8:         return charSet.displayName();
   9:     }

View Full Code Here

displayName

public String displayName(Locale locale)
Returns this charset's human-readable name for the given locale.

The default implementation of this method simply returns this charset's canonical name. Concrete subclasses of this class may override this method in order to provide a localized display name.

Parameters:
locale - The locale for which the display name is to be retrieved
Returns:
The display name of this charset in the given locale

encode

public final ByteBuffer encode(String str)
Convenience method that encodes a string into bytes in this charset.

An invocation of this method upon a charset cs returns the same result as the expression

     cs.encode(CharBuffer.wrap(s)); 
Parameters:
str - The string to be encoded
Returns:
A byte buffer containing the encoded characters
Usages and Demos :

View More Examples of encode(String str)
   1: import java.nio.channels.*;
   2: import java.nio.charset.*;
   3: import java.net.*;
   4:         ...
   5:   }
   6:   private Charset charset=Charset.forName("GBK");
   7:     CharBuffer charBuffer= charset.decode(buffer);
   8:         ...
   9:   }
  10:     return charset.encode(str);
  11:   }

View Full Code Here
   1: import java.nio.channels.ReadableByteChannel;
   2: import java.nio.charset.Charset;
   3: import java.util.logging.Logger;
   4:         ...
   5:     public void writeTo(ByteBuffer buf) {
   6:         Charset charSet = Charset.forName("US-ASCII");
   7: 
   8:         ...
   9:         ByteBuffer tmp = charSet.encode(SIGNATURE);
  10:         tmp.position(0);

View Full Code Here
   1: import java.io.*;
   2: import java.nio.charset.*;
   3: import java.util.*;
   4:         ...
   5:   private ByteBuffer receiveBuffer=ByteBuffer.allocate(1024);
   6:   private Charset charset=Charset.forName("GBK");
   7:   private Selector selector;
   8:         ...
   9:   }
  10:     return charset.encode(str);
  11:   }

View Full Code Here
   1: import java.nio.channels.*;
   2: import java.nio.charset.*;
   3: import java.net.*;
   4:         ...
   5:   private int port = 8000;
   6:   private Charset charset=Charset.forName("GBK");
   7: 
   8:         ...
   9:   }
  10:     return charset.encode(str);
  11:   }

View Full Code Here
   1: import java.io.*;
   2: import java.nio.charset.*;
   3: import java.util.*;
   4:         ...
   5:   private ByteBuffer receiveBuffer=ByteBuffer.allocate(1024);
   6:   private Charset charset=Charset.forName("GBK");
   7:   private Selector selector;
   8:         ...
   9:   }
  10:     return charset.encode(str);
  11:   }

View Full Code Here

encode

public final ByteBuffer encode(CharBuffer cb)
Convenience method that encodes Unicode characters into bytes in this charset.

An invocation of this method upon a charset cs returns the same result as the expression

     cs.newEncoder()
       .onMalformedInput(CodingErrorAction.REPLACE)
       .onUnmappableCharacter(CodingErrorAction.REPLACE)
       .encode(bb); 
except that it is potentially more efficient because it can cache encoders between successive invocations.

This method always replaces malformed-input and unmappable-character sequences with this charset's default replacement string. In order to detect such sequences, use the CharsetEncoder.encode(CharBuffer) method directly.

Parameters:
cb - The char buffer to be encoded
Returns:
A byte buffer containing the encoded characters
Usages and Demos :

View More Examples of encode(CharBuffer cb)
   1: import java.nio.channels.*;
   2: import java.nio.charset.*;
   3: import java.net.*;
   4:         ...
   5:   }
   6:   private Charset charset=Charset.forName("GBK");
   7:     CharBuffer charBuffer= charset.decode(buffer);
   8:         ...
   9:   }
  10:     return charset.encode(str);
  11:   }

View Full Code Here
   1: import java.nio.channels.ReadableByteChannel;
   2: import java.nio.charset.Charset;
   3: import java.util.logging.Logger;
   4:         ...
   5:     public void writeTo(ByteBuffer buf) {
   6:         Charset charSet = Charset.forName("US-ASCII");
   7: 
   8:         ...
   9:         ByteBuffer tmp = charSet.encode(SIGNATURE);
  10:         tmp.position(0);

View Full Code Here
   1: import java.io.*;
   2: import java.nio.charset.*;
   3: import java.util.*;
   4:         ...
   5:   private ByteBuffer receiveBuffer=ByteBuffer.allocate(1024);
   6:   private Charset charset=Charset.forName("GBK");
   7:   private Selector selector;
   8:         ...
   9:   }
  10:     return charset.encode(str);
  11:   }

View Full Code Here
   1: import java.nio.channels.*;
   2: import java.nio.charset.*;
   3: import java.net.*;
   4:         ...
   5:   private int port = 8000;
   6:   private Charset charset=Charset.forName("GBK");
   7: 
   8:         ...
   9:   }
  10:     return charset.encode(str);
  11:   }

View Full Code Here
   1: import java.io.*;
   2: import java.nio.charset.*;
   3: import java.util.*;
   4:         ...
   5:   private ByteBuffer receiveBuffer=ByteBuffer.allocate(1024);
   6:   private Charset charset=Charset.forName("GBK");
   7:   private Selector selector;
   8:         ...
   9:   }
  10:     return charset.encode(str);
  11:   }

View Full Code Here

equals

public final boolean equals(Object ob)
Tells whether or not this object is equal to another.

Two charsets are equal if, and only if, they have the same canonical names. A charset is never equal to any other type of object.

Overrides:
equals in interface Object
Returns:
true if, and only if, this charset is equal to the given object

forName

public static Charset forName(String charsetName)
Returns a charset object for the named charset.
Parameters:
charsetName - The name of the requested charset; may be either a canonical name or an alias
Returns:
A charset object for the named charset
Throws:
IllegalCharsetNameException - If the given charset name is illegal
UnsupportedCharsetException - If no support for the named charset is available in this instance of the Java virtual machine
Usages and Demos :

View More Examples of forName(String charsetName)
   1: import java.io.LineNumberReader;
   2: import java.nio.charset.Charset;
   3: import java.text.ParseException;
   4:         ...
   5:             new FileInputStream(f),
   6:             Charset.forName("ISO-8859-1")));
   7:         String read;
   8:         int len;
   9:         int count = 0;

View Full Code Here
   1: import java.nio.channels.ReadableByteChannel;
   2: import java.nio.charset.Charset;
   3:         ...
   4: import java.nio.charset.CharsetEncoder;
   5: import java.util.Arrays;
   6:         ...
   7:   
   8:   static final Charset[] charsets = new Charset[] 
   9:   {
  10:         ...
  11:     Charset.forName("Big5"),

View Full Code Here

hashCode

public final int hashCode()
Computes a hashcode for this charset.
Overrides:
hashCode in interface Object
Returns:
An integer hashcode

isRegistered

public final boolean isRegistered()
Tells whether or not this charset is registered in the IANA Charset Registry.
Returns:
true if, and only if, this charset is known by its implementor to be registered with the IANA

isSupported

public static boolean isSupported(String charsetName)
Tells whether the named charset is supported.
Parameters:
charsetName - The name of the requested charset; may be either a canonical name or an alias
Returns:
true if, and only if, support for the named charset is available in the current Java virtual machine
Throws:
IllegalCharsetNameException - If the given charset name is illegal
Usages and Demos :

View More Examples of isSupported(String charsetName)
   1: 
   2:                             this.logger.AppliInfo("Ecoding"+ow.getEncoding()+"support "+java.nio.charset.Charset.isSupported(this.enc));
   3:                         }
   4:                     catch (java.io.UnsupportedEncodingException ue)
   5:                         {

View Full Code Here
   1: 
   2: import java.nio.charset.Charset;
   3:         ...
   4: import java.nio.charset.IllegalCharsetNameException;
   5: import java.util.List;
   6:         ...
   7:         try {
   8:             return Charset.isSupported(enc);
   9:         } catch (IllegalCharsetNameException e) {

View Full Code Here

name

public final String name()
Returns this charset's canonical name.
Returns:
The canonical name of this charset
Usages and Demos :

View More Examples of name()
   1: import java.net.URL;
   2: import java.nio.charset.Charset;
   3: import java.util.Collection;
   4:         ...
   5:                 
   6:                     Charset charSet = null;
   7:                     try {
   8:         ...
   9:                     ows.setCharSet( charSet );
  10:                     request.setCharacterEncoding( charSet.name() );
  11:                 }

View Full Code Here
   1: import java.io.OutputStreamWriter;
   2: import java.nio.charset.Charset;
   3: 
   4:         ...
   5: 
   6:         Charset defaultCs = Charset.forName(new OutputStreamWriter(new ByteArrayOutputStream()).getEncoding());
   7:         ...
   8:         System.out.println("Default Charset: " + defaultCs.name());
   9:         String decoded = CmsEncoder.decode(param, CmsEncoder.ENCODING_UTF_8);

View Full Code Here
   1: import java.nio.channels.ReadableByteChannel;
   2: import java.nio.charset.Charset;
   3:         ...
   4: import java.nio.charset.CharsetEncoder;
   5: import java.util.Arrays;
   6:         ...
   7:   
   8:   static final Charset[] charsets = new Charset[] 
   9:   {
  10:         ...
  11:     {
  12:       String csName = cs.name();

View Full Code Here
   1: import java.io.StringWriter;
   2: import java.nio.charset.Charset;
   3: import java.util.HashMap;
   4:         ...
   5:     private boolean nsDecl = true;
   6:     private Charset charset = Charset.forName("UTF-8");
   7: 
   8:         ...
   9: 
  10:     transformer.setOutputProperty(OutputKeys.ENCODING, charset.name());

View Full Code Here
   1: import java.io.UnsupportedEncodingException;
   2: import java.nio.charset.Charset;
   3: import java.util.ArrayList;
   4:         ...
   5: 
   6:     protected String charset;
   7: 
   8:         ...
   9:     {
  10:         Charset set = Charset.forName(newCharset);
  11:         ...
  12:         this.charset = set.name();

View Full Code Here

newDecoder

public abstract CharsetDecoder newDecoder()
Constructs a new decoder for this charset.
Returns:
A new decoder for this charset
Usages and Demos :

View More Examples of newDecoder()
   1: import java.nio.channels.*;
   2: import java.nio.charset.*;
   3: 
   4:         ...
   5: 
   6:     private static Charset charset = Charset.forName("US-ASCII");
   7:         ...
   8:     private static CharsetDecoder decoder = charset.newDecoder();
   9:     private static ByteBuffer dbuf = ByteBuffer.allocateDirect(1024);

View Full Code Here
   1: import java.nio.*;
   2: import java.nio.charset.*;
   3: import java.nio.channels.*;
   4:         ...
   5:     public static void copy(ReadableByteChannel channel, Writer writer,
   6:                 Charset charset)
   7:     throws IOException
   8:         ...
   9:     {
  10:     CharsetDecoder decoder = charset.newDecoder();
  11:     decoder.onMalformedInput(CodingErrorAction.IGNORE);

View Full Code Here
   1: import java.io.*;
   2: import java.nio.charset.Charset;
   3:         ...
   4: import java.nio.charset.CharsetDecoder;
   5:         ...
   6: import java.nio.charset.CharacterCodingException;
   7: import java.nio.charset.CodingErrorAction;
   8:         ...
   9:         Charset        cset        = Charset.forName( encoding );
  10:         CharsetDecoder csetdecoder = cset.newDecoder();

View Full Code Here
   1: import java.nio.CharBuffer;
   2: import java.nio.charset.CharacterCodingException;
   3:         ...
   4: import java.nio.charset.Charset;
   5:         ...
   6: import java.nio.charset.CharsetDecoder;
   7: import java.nio.charset.CharsetEncoder;
   8:         ...
   9:         _charSetEncoder = _charset.newEncoder();
  10:         _charSetDecoder = _charset.newDecoder();

View Full Code Here
   1: import java.nio.channels.ReadableByteChannel;
   2: import java.nio.charset.Charset;
   3:         ...
   4: import java.nio.charset.CharsetDecoder;
   5: 
   6:         ...
   7:     public PrjFileReader(ReadableByteChannel channel) throws IOException, FactoryException {
   8:         Charset chars = Charset.forName("ISO-8859-1");
   9:         ...
  10:         decoder = chars.newDecoder();

View Full Code Here

newEncoder

public abstract CharsetEncoder newEncoder()
Constructs a new encoder for this charset.
Returns:
A new encoder for this charset
Throws:
UnsupportedOperationException - If this charset does not support encoding
Usages and Demos :

View More Examples of newEncoder()
   1: import java.lang.reflect.Constructor;
   2: import java.nio.charset.Charset;
   3:         ...
   4: import java.nio.charset.CharsetEncoder;
   5: 
   6:         ...
   7:     public static CharsetEncoder createEncoder( String encodin ) {
   8:         Charset cs = Charset.forName(System.getProperty("file.encoding"));
   9:         ...
  10:         CharsetEncoder encoder = cs.newEncoder();

View Full Code Here
   1: import java.lang.reflect.Constructor;
   2: import java.nio.charset.Charset;
   3:         ...
   4: import java.nio.charset.CharsetEncoder;
   5: 
   6:         ...
   7:     static CharsetEncoder createEncoder( String encodin ) {
   8:         Charset cs = Charset.forName(System.getProperty("file.encoding"));
   9:         ...
  10:         CharsetEncoder encoder = cs.newEncoder();

View Full Code Here
   1: 
   2: import java.nio.charset.Charset;
   3:         ...
   4: import java.nio.charset.CharsetEncoder;
   5: 
   6:         ...
   7: 
   8:     protected UnknownCharacterSet(Charset charset) {
   9:         ...
  10:         encoder = charset.newEncoder();

View Full Code Here
   1: 
   2: import java.nio.charset.CharsetEncoder;
   3:         ...
   4: import java.nio.charset.Charset;
   5:         ...
   6: import java.nio.charset.CharacterCodingException;
   7: import java.nio.CharBuffer;
   8:         ...
   9:     protected BuggyCharacterSet(Charset charset) {
  10:         encoder = charset.newEncoder();

View Full Code Here
   1: import java.util.Stack;
   2: import java.nio.charset.Charset;
   3:         ...
   4: import java.nio.charset.UnsupportedCharsetException;
   5:         ...
   6: import java.nio.charset.CharsetEncoder;
   7: 
   8:         ...
   9:                     charset = Charset.forName(encoding);
  10:                     encoder = charset.newEncoder();

View Full Code Here

toString

public final String toString()
Returns a string describing this charset.
Overrides:
toString in interface Object
Returns:
A string describing this charset