Example usage for org.apache.commons.codec Charsets US_ASCII

List of usage examples for org.apache.commons.codec Charsets US_ASCII

Introduction

In this page you can find the example usage for org.apache.commons.codec Charsets US_ASCII.

Prototype

Charset US_ASCII

To view the source code for org.apache.commons.codec Charsets US_ASCII.

Click Source Link

Document

Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.

Usage

From source file:com.anrisoftware.prefdialog.csvimportdialog.panelproperties.panelproperties.CsvPanelPropertiesModule.java

@SuppressWarnings("deprecation")
@Provides//from   w ww.j  a v a2  s.  co  m
@Singleton
@Named("charsetDefaults")
Collection<Charset> getCharsetDefaults() {
    List<Charset> list = new ArrayList<Charset>();
    list.add(Charsets.UTF_8);
    list.add(Charsets.UTF_16);
    list.add(Charsets.UTF_16BE);
    list.add(Charsets.UTF_16LE);
    list.add(Charsets.US_ASCII);
    list.add(Charsets.ISO_8859_1);
    return list;
}

From source file:com.yhspy.zbartest.StringUtils.java

/**
 * Encodes the given string into a sequence of bytes using the US-ASCII charset, storing the result into a new byte
 * array./*from  w ww .  j a  va2  s .c  o m*/
 *
 * @param string
 *            the String to encode, may be {@code null}
 * @return encoded bytes, or {@code null} if the input string was {@code null}
 * @throws NullPointerException
 *             Thrown if {@link Charsets#US_ASCII} is not initialized, which should never happen since it is
 *             required by the Java platform specification.
 * @since As of 1.7, throws {@link NullPointerException} instead of UnsupportedEncodingException
 * @see <a href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
 * @see #getBytesUnchecked(String, String)
 */
public static byte[] getBytesUsAscii(final String string) {
    return getBytes(string, Charsets.US_ASCII);
}

From source file:com.yhspy.zbartest.StringUtils.java

/**
 * Constructs a new <code>String</code> by decoding the specified array of bytes using the US-ASCII charset.
 *
 * @param bytes/*from w  w w  .ja  v  a2 s.co  m*/
 *            The bytes to be decoded into characters
 * @return A new <code>String</code> decoded from the specified array of bytes using the US-ASCII charset,
 *         or {@code null} if the input byte array was {@code null}.
 * @throws NullPointerException
 *             Thrown if {@link Charsets#US_ASCII} is not initialized, which should never happen since it is
 *             required by the Java platform specification.
 * @since As of 1.7, throws {@link NullPointerException} instead of UnsupportedEncodingException
 */
public static String newStringUsAscii(final byte[] bytes) {
    return new String(bytes, Charsets.US_ASCII);
}