Java Byte Array from getBytes(final String data, String charset)

Here you can find the source of getBytes(final String data, String charset)

Description

get Bytes

License

Open Source License

Declaration

public static byte[] getBytes(final String data, String charset) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.UnsupportedEncodingException;

public class Main {
    public static byte[] getBytes(final String data, String charset) {

        if (data == null) {
            throw new IllegalArgumentException("data may not be null");
        }/*from   w ww.  ja  v a2 s  .c om*/

        if (charset == null || charset.length() == 0) {
            throw new IllegalArgumentException(
                    "charset may not be null or empty");
        }

        try {
            return data.getBytes(charset);
        } catch (UnsupportedEncodingException e) {
            throw new IllegalArgumentException(String.format(
                    "Unsupported encoding: %s", charset));
        }
    }
}

Related

  1. getBytes(Class clazz)
  2. getBytes(Class cls, String resourceName)
  3. getBytes(final InputStream is)
  4. getBytes(final Serializable obj)
  5. getBytes(final String data, String charset)
  6. getBytes(final String value, final String characterEncoding)
  7. getBytes(int length, InputStream inStream)
  8. getBytes(int value)
  9. getBytes(String content)