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