protected byte[] toBytes(InputStream in) {
        if (in == null) {
            throw new IllegalArgumentException("InputStream argument cannot be null.");
        }
        final int BUFFER_SIZE = 512;
        ByteArrayOutputStream out = new ByteArrayOutputStream(BUFFER_SIZE);
        byte[] buffer = new byte[BUFFER_SIZE];
        int bytesRead;
        try {
            while ((bytesRead = in.read(buffer)) != -1) {
                out.write(buffer, 0, bytesRead);
            }
            return out.toByteArray();
        } catch (IOException ioe) {
            throw new CodecException(ioe);
        } finally {
            try {
                in.close();
            } catch (IOException ignored) {
            }
            try {
                out.close();
            } catch (IOException ignored) {
            }
        }
    }
Converts the specified {@link InputStream InputStream} into a byte array.

@param in the InputStream to convert to a byte array
@return the bytes of the input stream
@throws IllegalArgumentException if the {@code InputStream} argument is {@code null}.
@throws CodecException           if there is any problem reading from the {@link InputStream}.
@since 1.0
src/main/java/org/apache/shiro/lang/codec/CodecSupport.java