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 com.google.common.annotations.J2ktIncompatible; 020import java.nio.charset.Charset; 021 022/** 023 * Contains constant definitions for the six standard {@link Charset} instances, which are 024 * guaranteed to be supported by all Java platform implementations. 025 * 026 * <p>Assuming you're free to choose, note that <b>{@link #UTF_8} is widely preferred</b>. 027 * 028 * <p>See the Guava User Guide article on <a 029 * href="https://github.com/google/guava/wiki/StringsExplained#charsets">{@code Charsets}</a>. 030 * 031 * @author Mike Bostock 032 * @since 1.0 033 */ 034@GwtCompatible(emulated = true) 035@ElementTypesAreNonnullByDefault 036public final class Charsets { 037 private Charsets() {} 038 039 /** 040 * US-ASCII: seven-bit ASCII, the Basic Latin block of the Unicode character set (ISO646-US). 041 * 042 * <p><b>Java 7+ users:</b> this constant should be treated as deprecated; use {@link 043 * java.nio.charset.StandardCharsets#US_ASCII} instead. 044 * 045 */ 046 @J2ktIncompatible 047 @GwtIncompatible // Charset not supported by GWT 048 public static final Charset US_ASCII = Charset.forName("US-ASCII"); 049 050 /** 051 * ISO-8859-1: ISO Latin Alphabet Number 1 (ISO-LATIN-1). 052 * 053 * <p><b>Java 7+ users:</b> this constant should be treated as deprecated; use {@link 054 * java.nio.charset.StandardCharsets#ISO_8859_1} instead. 055 * 056 */ 057 public static final Charset ISO_8859_1 = Charset.forName("ISO-8859-1"); 058 059 /** 060 * UTF-8: eight-bit UCS Transformation Format. 061 * 062 * <p><b>Java 7+ users:</b> this constant should be treated as deprecated; use {@link 063 * java.nio.charset.StandardCharsets#UTF_8} instead. 064 * 065 */ 066 public static final Charset UTF_8 = Charset.forName("UTF-8"); 067 068 /** 069 * UTF-16BE: sixteen-bit UCS Transformation Format, big-endian byte order. 070 * 071 * <p><b>Java 7+ users:</b> this constant should be treated as deprecated; use {@link 072 * java.nio.charset.StandardCharsets#UTF_16BE} instead. 073 * 074 */ 075 @J2ktIncompatible 076 @GwtIncompatible // Charset not supported by GWT 077 public static final Charset UTF_16BE = Charset.forName("UTF-16BE"); 078 079 /** 080 * UTF-16LE: sixteen-bit UCS Transformation Format, little-endian byte order. 081 * 082 * <p><b>Java 7+ users:</b> this constant should be treated as deprecated; use {@link 083 * java.nio.charset.StandardCharsets#UTF_16LE} instead. 084 * 085 */ 086 @J2ktIncompatible 087 @GwtIncompatible // Charset not supported by GWT 088 public static final Charset UTF_16LE = Charset.forName("UTF-16LE"); 089 090 /** 091 * UTF-16: sixteen-bit UCS Transformation Format, byte order identified by an optional byte-order 092 * mark. 093 * 094 * <p><b>Java 7+ users:</b> this constant should be treated as deprecated; use {@link 095 * java.nio.charset.StandardCharsets#UTF_16} instead. 096 * 097 */ 098 @J2ktIncompatible 099 @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}