class ByteUtil {

    public static void asciiEncode(final CharSequence chars, final int charOffset,
                                   final byte[] buffer, final int bufferOffset, final int length)
    {
        for (int i = 0; i < length; i++)
        {
            int charValue = chars.charAt(i + charOffset);

            if (charValue > 127)
            {
                throw new IllegalArgumentException("Character " + chars.charAt(i + charOffset) + " is not " + StandardCharsets.US_ASCII);
            }

            buffer[i + bufferOffset] = (byte) charValue;
        }
    }

}