public class StringUtils
extends java.lang.Object
Constructor and Description |
---|
StringUtils() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
fromASCII(byte[] bytes) |
static java.lang.String |
fromASCII(byte[] bytes,
int offset,
int len) |
static java.lang.String |
fromUTF8(byte[] bytes) |
static java.lang.String |
fromUTF8(byte[] bytes,
int offset,
int len) |
static byte[] |
toASCII(java.lang.String str) |
static byte[] |
toUTF8(java.lang.String str)
In all src and test code, the String(byte[], ...) constructor and
String.getBytes method must always be passed a charset name, to avoid
portability issues.
|
public static byte[] toUTF8(java.lang.String str)
In most cases, the UTF8 or ASCII charset should be used for portability. UTF8 should be used when any character may be represented. ASCII can be used when all characters are in the ASCII range. The default charset should only be used when handling user-input data directly, e.g., console input/output or user-visible files.
Rather than using getBytes() and String() directly, the methods here are used to avoid having to clutter code with a catch for java.io.UnsupportedEncodingException, which should never be thrown for the "UTF-8" or "US-ASCII" charsets.
public static java.lang.String fromUTF8(byte[] bytes)
public static java.lang.String fromUTF8(byte[] bytes, int offset, int len)
public static byte[] toASCII(java.lang.String str)
public static java.lang.String fromASCII(byte[] bytes)
public static java.lang.String fromASCII(byte[] bytes, int offset, int len)
Copyright (c) 2004-2012 Oracle. All rights reserved.