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

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

Introduction

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

Prototype

String US_ASCII

To view the source code for org.apache.commons.codec CharEncoding 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.bfd.util.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 ww w.  j  av a2 s . c o m
 * 
 * @param string
 *            the String to encode, may be <code>null</code>
 * @return encoded bytes, or <code>null</code> if the input string was <code>null</code>
 * @throws IllegalStateException
 *             Thrown when the charset is missing, which should be never according the the Java specification.
 * @see <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
 * @see #getBytesUnchecked(String, String)
 */
public static byte[] getBytesUsAscii(String string) {
    return StringUtils.getBytesUnchecked(string, CharEncoding.US_ASCII);
}

From source file:com.bfd.util.StringUtils.java

/**
 * Constructs a new <code>String</code> by decoding the specified array of bytes using the US-ASCII charset.
 * /*from w  w  w  .  j  av  a  2  s .  c  om*/
 * @param bytes
 *            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</code> if the input byte array was <code>null</code>.
 * @throws IllegalStateException
 *             Thrown when a {@link UnsupportedEncodingException} is caught, which should never happen since the
 *             charset is required.
 */
public static String newStringUsAscii(byte[] bytes) {
    return StringUtils.newString(bytes, CharEncoding.US_ASCII);
}