Example usage for org.apache.commons.io Charsets toCharset

List of usage examples for org.apache.commons.io Charsets toCharset

Introduction

In this page you can find the example usage for org.apache.commons.io Charsets toCharset.

Prototype

public static Charset toCharset(String charset) 

Source Link

Document

Returns a Charset for the named charset.

Usage

From source file:launcher.net.CustomIOUtils.java

/**
 * Get the contents of an <code>InputStream</code> as a character array
 * using the specified character encoding.
 * <p>/* w w  w .  j av  a 2 s  .c o  m*/
 * Character encoding names can be found at
 * <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
 * <p>
 * This method buffers the input internally, so there is no need to use a
 * <code>BufferedInputStream</code>.
 * 
 * @param is  the <code>InputStream</code> to read from
 * @param encoding  the encoding to use, null means platform default
 * @return the requested character array
 * @throws NullPointerException if the input is null
 * @throws IOException if an I/O error occurs
 * @throws UnsupportedCharsetException
 *             thrown instead of {@link UnsupportedEncodingException} in version 2.2 if the encoding is not
 *             supported.
 * @since 1.1
 */
public static char[] toCharArray(InputStream is, String encoding) throws IOException {
    return toCharArray(is, Charsets.toCharset(encoding));
}

From source file:launcher.net.CustomIOUtils.java

/**
 * Get the contents of an <code>InputStream</code> as a String
 * using the specified character encoding.
 * <p>/*from  w w  w .  j a  v a  2 s.c  om*/
 * Character encoding names can be found at
 * <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
 * <p>
 * This method buffers the input internally, so there is no need to use a
 * <code>BufferedInputStream</code>.
 * 
 * @param input  the <code>InputStream</code> to read from
 * @param encoding  the encoding to use, null means platform default
 * @return the requested String
 * @throws NullPointerException if the input is null
 * @throws IOException if an I/O error occurs
 * @throws UnsupportedCharsetException
 *             thrown instead of {@link UnsupportedEncodingException} in version 2.2 if the encoding is not
 *             supported.
 */
public static String toString(InputStream input, String encoding) throws IOException {
    return toString(input, Charsets.toCharset(encoding));
}

From source file:launcher.net.CustomIOUtils.java

/**
 * Gets the contents at the given URI.//from   www  . j  av a  2s.  c  o m
 * 
 * @param uri
 *            The URI source.
 * @param encoding
 *            The encoding name for the URL contents.
 * @return The contents of the URL as a String.
 * @throws IOException if an I/O exception occurs.
 * @since 2.3.
 */
public static String toString(URI uri, Charset encoding) throws IOException {
    return toString(uri.toURL(), Charsets.toCharset(encoding));
}

From source file:com.tomagoyaky.jdwp.IOUtils.java

/**
 * Gets the contents of a <code>Reader</code> as a <code>byte[]</code>
 * using the specified character encoding.
 * <p/>/*from  w  ww  . ja v a 2s  .  com*/
 * Character encoding names can be found at
 * <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
 * <p/>
 * This method buffers the input internally, so there is no need to use a
 * <code>BufferedReader</code>.
 *
 * @param input the <code>Reader</code> to read from
 * @param encoding the encoding to use, null means platform default
 * @return the requested byte array
 * @throws NullPointerException                         if the input is null
 * @throws IOException                                  if an I/O error occurs
 * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
 *                                                      .UnsupportedEncodingException} in version 2.2 if the
 *                                                      encoding is not supported.
 * @since 1.1
 */
public static byte[] toByteArray(final Reader input, final String encoding) throws IOException {
    return toByteArray(input, Charsets.toCharset(encoding));
}

From source file:launcher.net.CustomIOUtils.java

/**
 * Gets the contents at the given URI./*from   w w w .  j  a va  2s.co  m*/
 * 
 * @param uri
 *            The URI source.
 * @param encoding
 *            The encoding name for the URL contents.
 * @return The contents of the URL as a String.
 * @throws IOException if an I/O exception occurs.
 * @throws UnsupportedCharsetException
 *             thrown instead of {@link UnsupportedEncodingException} in version 2.2 if the encoding is not
 *             supported.
 * @since 2.1
 */
public static String toString(URI uri, String encoding) throws IOException {
    return toString(uri, Charsets.toCharset(encoding));
}

From source file:launcher.net.CustomIOUtils.java

/**
 * Gets the contents at the given URL.//from   w w w  . j  av  a2  s .  co  m
 * 
 * @param url
 *            The URL source.
 * @param encoding
 *            The encoding name for the URL contents.
 * @return The contents of the URL as a String.
 * @throws IOException if an I/O exception occurs.
 * @throws UnsupportedCharsetException
 *             thrown instead of {@link UnsupportedEncodingException} in version 2.2 if the encoding is not
 *             supported.
 * @since 2.1
 */
public static String toString(URL url, String encoding) throws IOException {
    return toString(url, Charsets.toCharset(encoding));
}

From source file:launcher.net.CustomIOUtils.java

/**
 * Get the contents of a <code>byte[]</code> as a String
 * using the specified character encoding.
 * <p>/*from  w ww .  j  a  v a 2 s  .  c  o  m*/
 * Character encoding names can be found at
 * <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
 * 
 * @param input the byte array to read from
 * @param encoding  the encoding to use, null means platform default
 * @return the requested String
 * @throws NullPointerException if the input is null
 * @throws IOException if an I/O error occurs (never occurs)
 */
public static String toString(byte[] input, String encoding) throws IOException {
    return new String(input, Charsets.toCharset(encoding));
}

From source file:launcher.net.CustomIOUtils.java

/**
 * Get the contents of an <code>InputStream</code> as a list of Strings,
 * one entry per line, using the specified character encoding.
 * <p>//from w w w.j a va  2s  .  co m
 * This method buffers the input internally, so there is no need to use a
 * <code>BufferedInputStream</code>.
 *
 * @param input  the <code>InputStream</code> to read from, not null
 * @param encoding  the encoding to use, null means platform default
 * @return the list of Strings, never null
 * @throws NullPointerException if the input is null
 * @throws IOException if an I/O error occurs
 * @since 2.3
 */
public static List<String> readLines(InputStream input, Charset encoding) throws IOException {
    InputStreamReader reader = new InputStreamReader(input, Charsets.toCharset(encoding));
    return readLines(reader);
}

From source file:com.tomagoyaky.jdwp.IOUtils.java

/**
 * Gets the contents of an <code>InputStream</code> as a character array
 * using the specified character encoding.
 * <p/>//  www  . j a va  2s. c om
 * Character encoding names can be found at
 * <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
 * <p/>
 * This method buffers the input internally, so there is no need to use a
 * <code>BufferedInputStream</code>.
 *
 * @param is the <code>InputStream</code> to read from
 * @param encoding the encoding to use, null means platform default
 * @return the requested character array
 * @throws NullPointerException                         if the input is null
 * @throws IOException                                  if an I/O error occurs
 * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
 *                                                      .UnsupportedEncodingException} in version 2.2 if the
 *                                                      encoding is not supported.
 * @since 1.1
 */
public static char[] toCharArray(final InputStream is, final String encoding) throws IOException {
    return toCharArray(is, Charsets.toCharset(encoding));
}

From source file:launcher.net.CustomIOUtils.java

/**
 * Get the contents of an <code>InputStream</code> as a list of Strings,
 * one entry per line, using the specified character encoding.
 * <p>//from   w ww. j  av a 2 s .c  om
 * Character encoding names can be found at
 * <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
 * <p>
 * This method buffers the input internally, so there is no need to use a
 * <code>BufferedInputStream</code>.
 *
 * @param input  the <code>InputStream</code> to read from, not null
 * @param encoding  the encoding to use, null means platform default
 * @return the list of Strings, never null
 * @throws NullPointerException if the input is null
 * @throws IOException if an I/O error occurs
 * @throws UnsupportedCharsetException
 *             thrown instead of {@link UnsupportedEncodingException} in version 2.2 if the encoding is not
 *             supported.
 * @since 1.1
 */
public static List<String> readLines(InputStream input, String encoding) throws IOException {
    return readLines(input, Charsets.toCharset(encoding));
}