protected byte[] toBytes(Object object) {
        if (object == null) {
            String msg = "Argument for byte conversion cannot be null.";
            throw new IllegalArgumentException(msg);
        }
        if (object instanceof byte[]) {
            return (byte[]) object;
        } else if (object instanceof ByteSource) {
            return ((ByteSource) object).getBytes();
        } else if (object instanceof char[]) {
            return toBytes((char[]) object);
        } else if (object instanceof String) {
            return toBytes((String) object);
        } else if (object instanceof File) {
            return toBytes((File) object);
        } else if (object instanceof InputStream) {
            return toBytes((InputStream) object);
        } else {
            return objectToBytes(object);
        }
    }
Converts the specified Object into a byte array.
<p/>
If the argument is a {@code byte[]}, {@code char[]}, {@link ByteSource}, {@link String}, {@link File}, or
{@link InputStream}, it will be converted automatically and returned.}
<p/>
If the argument is anything other than these types, it is passed to the
{@link #objectToBytes(Object) objectToBytes} method which must be overridden by subclasses.

@param object the Object to convert into a byte array
@return a byte array representation of the Object argument.
lang/src/main/java/org/apache/shiro/lang/codec/CodecSupport.java