Java UTF8 Encode toUTF8InputStream(String str)

Here you can find the source of toUTF8InputStream(String str)

Description

Replacement for deprecated StringBufferInputStream().

License

Apache License

Declaration

public static InputStream toUTF8InputStream(String str) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.io.ByteArrayInputStream;

import java.io.InputStream;

import java.io.UnsupportedEncodingException;

public class Main {
    /**//from   w w  w  . ja  v  a 2s  . c  o  m
     * Replacement for deprecated StringBufferInputStream(). Instead of:
     * InputStream is = new StringBuilderInputStream(str);
     * do:
     * InputStream is = StringUtil.toUTF8InputStream(str);
     */
    public static InputStream toUTF8InputStream(String str) {
        InputStream is = null;
        try {
            is = new ByteArrayInputStream(str.getBytes("UTF-8"));
        } catch (UnsupportedEncodingException e) {
            // UTF-8 should always be supported
            throw new AssertionError();
        }
        return is;
    }
}

Related

  1. toUTF8(String value)
  2. toUTF8ByteArray(char[] string)
  3. toUTF8Bytes(final String s)
  4. toUTF8Bytes(String src)
  5. toUTF8Bytes(String string)
  6. toUTF8String(byte[] b, int offset, int length)
  7. utf8Code(String str)
  8. Utf8codeCheck(String text)
  9. utf8Encode(final Collection col)