code: public static byte[] toByteArray(String value) {
          if (value == null) {
              return null;
          }
          try {
              CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder().onMalformedInput(CodingErrorAction.REPORT)
                      .onUnmappableCharacter(CodingErrorAction.REPORT);
              ByteBuffer buf = encoder.encode(CharBuffer.wrap(value));
              // don't use ByteBuffer.array(), as it returns internal, and
              // possibly larger, byte array
              byte[] res = new byte[buf.remaining()];
              buf.get(res);
              return res;
          } catch (CharacterCodingException e) {
              throw new RuntimeException("Unexpected exception", e);
          }
      }
docs: Encodes the given string in UTF-8.
  
  @param value
  the string to encode.
  
  @return A newly allocated array containing the encoding result.