Returns a copy of the input data as bytes in the correct charset.

@param aCharset
The charset to be used. May not be <code>null</code>.
@return an array of bytes. Never <code>null</code>.
423491
@Nonnull
  @ReturnsMutableCopy
  public byte [] toByteArray (@Nonnull final Charset aCharset)
  {
    return StringHelper.encodeCharToBytes (m_aBuf, 0, m_nCount, aCharset);
  }
1242314
public static String convert(String source, String srcCharset, String destCharset) {
		return convert(source, Charset.forName(srcCharset), Charset.forName(destCharset));
	}
98576
public static byte[] sha384Hash(String data, Charset charset) throws NoSuchAlgorithmException {
		return sha384Hash(data.getBytes(charset));
	}
218031
@Nonnull
  @ReturnsMutableCopy
  public static char [] getAsCharArray (@Nonnull final Set <Character> aChars)
  {
    ValueEnforcer.notNull (aChars, "Chars");

    final char [] ret = new char [aChars.size ()];
    int nIndex = 0;
    for (final Character aChar : aChars)
      ret[nIndex++] = aChar.charValue ();
    return ret;
  }
69109
public static String extractCHARSET(String charset){
	    final String arg = charset.replace("@charset","").replace(";","").trim();
	    if (arg.length() > 2)
	        return extractSTRING(arg);
	    else
	        return "";
	}
270088
public static byte[] chars2Bytes(final char[] chars) {
        if (chars == null || chars.length <= 0) return null;
        int    len   = chars.length;
        byte[] bytes = new byte[len];
        for (int i = 0; i < len; i++) {
            bytes[i] = (byte) (chars[i]);
        }
        return bytes;
    }
372924
public T charset(String charset) {
		if(StrUtil.isNotBlank(charset)){
			this.charset = Charset.forName(charset);
		}
		return (T) this;
	}
168121
protected static Charset getCharset(final Map<String, String> properties) {
		String charsetName = properties.get("charset");
		try {
			return charsetName == null ? Charset.defaultCharset() : Charset.forName(charsetName);
		} catch (IllegalArgumentException ex) {
			InternalLogger.log(Level.ERROR, "Invalid charset: " + charsetName);
			return Charset.defaultCharset();
		}
	}
196319
public String getString() {
        byte[] rawdata = get();
        String charset = getCharSet();
        if (charset == null) {
            charset = DEFAULT_CHARSET;
        }
        try {
            return new String(rawdata, charset);
        } catch (UnsupportedEncodingException e) {
            return new String(rawdata);
        }
    }
958569
public static byte[] sha224Hash(String data, Charset charset) throws NoSuchAlgorithmException {
		return sha224Hash(data.getBytes(charset));
	}
635872
public Object parse(byte [] bytes, String charset) {
        if (bytes == null) {
            throw new IllegalArgumentException("bytes must not be null");
        }

        if (charset == null) {
            throw new IllegalArgumentException("charset must not be null");
        }

        Object content;
        content = createParser().parse(bytes, charset);
        return content;
    }
637718
public Charset getCharset() {
		Charset charset = null;
		final String charsetName = getCharsetName();
		if (StrUtil.isNotBlank(charsetName)) {
			try {
				charset = Charset.forName(charsetName);
			} catch (UnsupportedCharsetException e) {
				// ignore
			}
		}
		return charset;
	}
1109152
@Nonnull
  public String getContentAsBase64EncodedString ()
  {
    // Add Base64 encoded String
    final byte [] aEncoded = Base64.encodeBytesToBytes (m_aContent);
    // Print the string in the specified charset
    return new String (aEncoded, m_aCharset);
  }
1075706
private static byte[] getBytes(String string, Charset charset) {
        if (string == null) {
            return null;
        }
        return string.getBytes(charset);
    }
50787
public String readStringLengthEncoded(final Charset charset) {
    int length = (int) getLengthEncodedNumeric();
    String string = new String(buf, position, length, charset);
    position += length;
    return string;
  }
1340396
private byte[] toByteArray(char[] chars, Charset charset) {
        assert chars != null;

        CharBuffer charBuffer = CharBuffer.wrap(chars);
        ByteBuffer byteBuffer = charset.encode(charBuffer);
        byte[] bytes = Arrays.copyOfRange(byteBuffer.array(),
                byteBuffer.position(), byteBuffer.limit());
        Arrays.fill(byteBuffer.array(), (byte) 0); // clear sensitive data
        return bytes;
    }
651536
@Override
    public void setCharacterEncoding(String charset) {
        if (null != this.outWriter || isCommitted()) {
            return;
        }
        if (null != charset) {
            this.encoding = connection.getEncodingUtils().stripQuotes(charset);
        }
        if (null != this.contentType) {
            int index = this.contentType.indexOf("charset=");
            StringBuilder sb = new StringBuilder();
            if (-1 != index) {
                sb.append(this.contentType.substring(0, index - 1).trim());
            } else {
                sb.append(this.contentType);
            }
            if (this.encoding != null) {
                sb.append(";charset=").append(this.encoding);
            }

            this.contentType = sb.toString();
            this.response.setHeader("Content-Type", this.contentType);
        }
    }