001/*
002 * Copyright (C) 2007 The Guava Authors
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License
010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011 * or implied. See the License for the specific language governing permissions and limitations under
012 * the License.
013 */
014
015package com.google.common.base;
016
017import com.google.common.annotations.GwtCompatible;
018import com.google.common.annotations.GwtIncompatible;
019import java.nio.charset.Charset;
020
021/**
022 * Contains constant definitions for the six standard {@link Charset} instances, which are
023 * guaranteed to be supported by all Java platform implementations.
024 *
025 * <p>Assuming you're free to choose, note that <b>{@link #UTF_8} is widely preferred</b>.
026 *
027 * <p>See the Guava User Guide article on
028 * <a href="https://github.com/google/guava/wiki/StringsExplained#charsets">{@code Charsets}</a>.
029 *
030 * @author Mike Bostock
031 * @since 1.0
032 */
033@GwtCompatible(emulated = true)
034public final class Charsets {
035  private Charsets() {}
036
037  /**
038   * US-ASCII: seven-bit ASCII, the Basic Latin block of the Unicode character set (ISO646-US).
039   *
040   * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use
041   * {@link java.nio.charset.StandardCharsets#US_ASCII} instead.
042   *
043   */
044  @GwtIncompatible // Non-UTF-8 Charset
045  public static final Charset US_ASCII = Charset.forName("US-ASCII");
046
047  /**
048   * ISO-8859-1: ISO Latin Alphabet Number 1 (ISO-LATIN-1).
049   *
050   * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use
051   * {@link java.nio.charset.StandardCharsets#ISO_8859_1} instead.
052   *
053   */
054  @GwtIncompatible // Non-UTF-8 Charset
055  public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1");
056
057  /**
058   * UTF-8: eight-bit UCS Transformation Format.
059   *
060   * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use
061   * {@link java.nio.charset.StandardCharsets#UTF_8} instead.
062   *
063   */
064  public static final Charset UTF_8 = Charset.forName("UTF-8");
065
066  /**
067   * UTF-16BE: sixteen-bit UCS Transformation Format, big-endian byte order.
068   *
069   * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use
070   * {@link java.nio.charset.StandardCharsets#UTF_16BE} instead.
071   *
072   */
073  @GwtIncompatible // Non-UTF-8 Charset
074  public static final Charset UTF_16BE = Charset.forName("UTF-16BE");
075
076  /**
077   * UTF-16LE: sixteen-bit UCS Transformation Format, little-endian byte order.
078   *
079   * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use
080   * {@link java.nio.charset.StandardCharsets#UTF_16LE} instead.
081   *
082   */
083  @GwtIncompatible // Non-UTF-8 Charset
084  public static final Charset UTF_16LE = Charset.forName("UTF-16LE");
085
086  /**
087   * UTF-16: sixteen-bit UCS Transformation Format, byte order identified by an optional byte-order
088   * mark.
089   *
090   * <p><b>Note for Java 7 and later:</b> this constant should be treated as deprecated; use
091   * {@link java.nio.charset.StandardCharsets#UTF_16} instead.
092   *
093   */
094  @GwtIncompatible // Non-UTF-8 Charset
095  public static final Charset UTF_16 = Charset.forName("UTF-16");
096
097  /*
098   * Please do not add new Charset references to this class, unless those character encodings are
099   * part of the set required to be supported by all Java platform implementations! Any Charsets
100   * initialized here may cause unexpected delays when this class is loaded. See the Charset
101   * Javadocs for the list of built-in character encodings.
102   */
103}