• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Guava Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 
15 package com.google.common.base;
16 
17 import com.google.common.annotations.GwtCompatible;
18 import com.google.common.annotations.GwtIncompatible;
19 import com.google.common.annotations.J2ktIncompatible;
20 import java.nio.charset.Charset;
21 
22 /**
23  * Contains constant definitions for the six standard {@link Charset} instances, which are
24  * guaranteed to be supported by all Java platform implementations.
25  *
26  * <p>Assuming you're free to choose, note that <b>{@link #UTF_8} is widely preferred</b>.
27  *
28  * <p>See the Guava User Guide article on <a
29  * href="https://github.com/google/guava/wiki/StringsExplained#charsets">{@code Charsets}</a>.
30  *
31  * @author Mike Bostock
32  * @since 1.0
33  */
34 @GwtCompatible(emulated = true)
35 @ElementTypesAreNonnullByDefault
36 public final class Charsets {
Charsets()37   private Charsets() {}
38 
39   /**
40    * US-ASCII: seven-bit ASCII, the Basic Latin block of the Unicode character set (ISO646-US).
41    *
42    * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use {@link
43    * java.nio.charset.StandardCharsets#US_ASCII} instead.
44    *
45    */
46   @J2ktIncompatible
47   @GwtIncompatible // Charset not supported by GWT
48   public static final Charset US_ASCII = Charset.forName("US-ASCII");
49 
50   /**
51    * ISO-8859-1: ISO Latin Alphabet Number 1 (ISO-LATIN-1).
52    *
53    * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use {@link
54    * java.nio.charset.StandardCharsets#ISO_8859_1} instead.
55    *
56    */
57   public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
58 
59   /**
60    * UTF-8: eight-bit UCS Transformation Format.
61    *
62    * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use {@link
63    * java.nio.charset.StandardCharsets#UTF_8} instead.
64    *
65    */
66   public static final Charset UTF_8 = Charset.forName("UTF-8");
67 
68   /**
69    * UTF-16BE: sixteen-bit UCS Transformation Format, big-endian byte order.
70    *
71    * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use {@link
72    * java.nio.charset.StandardCharsets#UTF_16BE} instead.
73    *
74    */
75   @J2ktIncompatible
76   @GwtIncompatible // Charset not supported by GWT
77   public static final Charset UTF_16BE = Charset.forName("UTF-16BE");
78 
79   /**
80    * UTF-16LE: sixteen-bit UCS Transformation Format, little-endian byte order.
81    *
82    * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use {@link
83    * java.nio.charset.StandardCharsets#UTF_16LE} instead.
84    *
85    */
86   @J2ktIncompatible
87   @GwtIncompatible // Charset not supported by GWT
88   public static final Charset UTF_16LE = Charset.forName("UTF-16LE");
89 
90   /**
91    * UTF-16: sixteen-bit UCS Transformation Format, byte order identified by an optional byte-order
92    * mark.
93    *
94    * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use {@link
95    * java.nio.charset.StandardCharsets#UTF_16} instead.
96    *
97    */
98   @J2ktIncompatible
99   @GwtIncompatible // Charset not supported by GWT
100   public static final Charset UTF_16 = Charset.forName("UTF-16");
101 
102   /*
103    * Please do not add new Charset references to this class, unless those character encodings are
104    * part of the set required to be supported by all Java platform implementations! Any Charsets
105    * initialized here may cause unexpected delays when this class is loaded. See the Charset
106    * Javadocs for the list of built-in character encodings.
107    */
108 }
109