code: public static byte[] asBytes(String string, Charset charset)
      {
          if (string == null)
          {
              return null;
          }
  
          if (charset == null)
          {
              throw new IllegalArgumentException("Cannot get bytes without a Charset");
          }
  
          try
          {
              return string.getBytes(charset.name());
          }
          catch (UnsupportedEncodingException e)
          {
              //since we are using *actual* charsets, not string lookups, this
              //should *never* happen. But it is better to throw it up than swallow it.
              throw new IllegalStateException("Charset present", e);
          }
      }
docs: Turn a string into an array of bytes using the passed {@link Charset}
  
  @param string
  @param charset
  @return a byte[] array