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:com.tomagoyaky.jdwp.IOUtils.java

/**
 * Gets the contents of an <code>InputStream</code> as a list of Strings,
 * one entry per line, using the specified character encoding.
 * <p/>//from www.  j  a  va 2s.  c o  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(final InputStream input, final Charset encoding) throws IOException {
    final 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 list of Strings,
 * one entry per line, using the specified character encoding.
 * <p/>//from   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 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 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 List<String> readLines(final InputStream input, final String encoding) throws IOException {
    return readLines(input, Charsets.toCharset(encoding));
}

From source file:launcher.net.CustomIOUtils.java

/**
 * Return an Iterator for the lines in an <code>InputStream</code>, using
 * the character encoding specified (or default encoding if null).
 * <p>/*from w ww. j  av a2 s .c o  m*/
 * <code>LineIterator</code> holds a reference to the open
 * <code>InputStream</code> specified here. When you have finished with
 * the iterator you should close the stream to free internal resources.
 * This can be done by closing the stream directly, or by calling
 * {@link LineIterator#close()} or {@link LineIterator#closeQuietly(LineIterator)}.
 * <p>
 * The recommended usage pattern is:
 * <pre>
 * try {
 *   LineIterator it = IOUtils.lineIterator(stream, charset);
 *   while (it.hasNext()) {
 *     String line = it.nextLine();
 *     /// do something with line
 *   }
 * } finally {
 *   IOUtils.closeQuietly(stream);
 * }
 * </pre>
 *
 * @param input  the <code>InputStream</code> to read from, not null
 * @param encoding  the encoding to use, null means platform default
 * @return an Iterator of the lines in the reader, never null
 * @throws IllegalArgumentException if the input is null
 * @throws IOException if an I/O error occurs, such as if the encoding is invalid
 * @since 2.3
 */
public static LineIterator lineIterator(InputStream input, Charset encoding) throws IOException {
    return new LineIterator(new InputStreamReader(input, Charsets.toCharset(encoding)));
}

From source file:launcher.net.CustomIOUtils.java

/**
 * Return an Iterator for the lines in an <code>InputStream</code>, using
 * the character encoding specified (or default encoding if null).
 * <p>/*from www .j a va  2s .  co m*/
 * <code>LineIterator</code> holds a reference to the open
 * <code>InputStream</code> specified here. When you have finished with
 * the iterator you should close the stream to free internal resources.
 * This can be done by closing the stream directly, or by calling
 * {@link LineIterator#close()} or {@link LineIterator#closeQuietly(LineIterator)}.
 * <p>
 * The recommended usage pattern is:
 * <pre>
 * try {
 *   LineIterator it = IOUtils.lineIterator(stream, "UTF-8");
 *   while (it.hasNext()) {
 *     String line = it.nextLine();
 *     /// do something with line
 *   }
 * } finally {
 *   IOUtils.closeQuietly(stream);
 * }
 * </pre>
 *
 * @param input  the <code>InputStream</code> to read from, not null
 * @param encoding  the encoding to use, null means platform default
 * @return an Iterator of the lines in the reader, never null
 * @throws IllegalArgumentException if the input is null
 * @throws IOException if an I/O error occurs, such as if the encoding is invalid
 * @throws UnsupportedCharsetException
 *             thrown instead of {@link UnsupportedEncodingException} in version 2.2 if the encoding is not
 *             supported.
 * @since 1.2
 */
public static LineIterator lineIterator(InputStream input, String encoding) throws IOException {
    return lineIterator(input, Charsets.toCharset(encoding));
}

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

/**
 * Converts the specified CharSequence to an input stream, encoded as bytes
 * using the specified character encoding.
 * <p/>//from  w w  w .j ava2 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 CharSequence to convert
 * @param encoding the encoding to use, null means platform default
 * @return an input stream
 * @throws IOException                                  if the encoding is invalid
 * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io
 *                                                      .UnsupportedEncodingException} in version 2.2 if the
 *                                                      encoding is not supported.
 * @since 2.0
 */
public static InputStream toInputStream(final CharSequence input, final String encoding) throws IOException {
    return toInputStream(input, Charsets.toCharset(encoding));
}

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

/**
 * Converts the specified string to an input stream, encoded as bytes
 * using the specified character encoding.
 *
 * @param input the string to convert/*w  ww. j av a 2  s .c  o m*/
 * @param encoding the encoding to use, null means platform default
 * @return an input stream
 * @since 2.3
 */
public static InputStream toInputStream(final String input, final Charset encoding) {
    return new ByteArrayInputStream(input.getBytes(Charsets.toCharset(encoding)));
}

From source file:launcher.net.CustomIOUtils.java

/**
 * Convert the specified CharSequence to an input stream, encoded as bytes
 * using the specified character encoding.
 * <p>/*from   w w w  .jav  a 2 s.c om*/
 * Character encoding names can be found at
 * <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
 *
 * @param input the CharSequence to convert
 * @param encoding the encoding to use, null means platform default
 * @return an input stream
 * @throws IOException if the encoding is invalid
 * @throws UnsupportedCharsetException
 *             thrown instead of {@link UnsupportedEncodingException} in version 2.2 if the encoding is not
 *             supported.
 * @since 2.0
 */
public static InputStream toInputStream(CharSequence input, String encoding) throws IOException {
    return toInputStream(input, Charsets.toCharset(encoding));
}

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

/**
 * Converts the specified string to an input stream, encoded as bytes
 * using the specified character encoding.
 * <p/>/*from  w ww.j  a  va2 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 string to convert
 * @param encoding the encoding to use, null means platform default
 * @return an input stream
 * @throws IOException                                  if the encoding is invalid
 * @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 InputStream toInputStream(final String input, final String encoding) throws IOException {
    final byte[] bytes = input.getBytes(Charsets.toCharset(encoding));
    return new ByteArrayInputStream(bytes);
}

From source file:launcher.net.CustomIOUtils.java

/**
 * Convert the specified string to an input stream, encoded as bytes
 * using the specified character encoding.
 *
 * @param input the string to convert// w  w  w  . j  a v a  2 s  . c  o  m
 * @param encoding the encoding to use, null means platform default
 * @return an input stream
 * @since 2.3
 */
public static InputStream toInputStream(String input, Charset encoding) {
    return new ByteArrayInputStream(input.getBytes(Charsets.toCharset(encoding)));
}

From source file:launcher.net.CustomIOUtils.java

/**
 * Convert the specified string to an input stream, encoded as bytes
 * using the specified character encoding.
 * <p>//from  ww w .  j  a v  a  2s.c o m
 * Character encoding names can be found at
 * <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
 *
 * @param input the string to convert
 * @param encoding the encoding to use, null means platform default
 * @return an input stream
 * @throws IOException if the encoding is invalid
 * @throws UnsupportedCharsetException
 *             thrown instead of {@link UnsupportedEncodingException} in version 2.2 if the encoding is not
 *             supported.
 * @since 1.1
 */
public static InputStream toInputStream(String input, String encoding) throws IOException {
    byte[] bytes = input.getBytes(Charsets.toCharset(encoding));
    return new ByteArrayInputStream(bytes);
}