docs: public static byte[] encode(String s, Charset charset)
      {
          CharsetEncoder encoder = charset.newEncoder();
          try
          {
              ByteBuffer buffer = encoder.encode(CharBuffer.wrap(s));
              byte[] bytes = buffer.array();
  
              // Make another copy iff there's garbage after the limit.
              int limit = buffer.limit();
              if (limit < bytes.length)
              {
                  bytes = copyOf(bytes, limit);
              }
  
              return bytes;
          }
          catch (CharacterCodingException e)
          {
              throw new IonException("Invalid string data", e);
          }
      }