@Override
    public Charset detect(InputStream input, Metadata metadata) throws IOException {
        for (EncodingDetector detector : getDetectors()) {
            Charset detected = detector.detect(input, metadata);
            if (detected != null) {
                metadata.set(TikaCoreProperties.DETECTED_ENCODING, detected.name());
                //if this has been set by a leaf detector, do not overwrite
                if (! detector.getClass().getSimpleName().equals("CompositeEncodingDetector")) {
                    metadata.set(TikaCoreProperties.ENCODING_DETECTOR,
                            detector.getClass().getSimpleName());
                }
                return detected;
            }
        }
        return null;
    }
@param input    text document input stream, or <code>null</code>
@param metadata input metadata for the document
@return the detected Charset or null if no charset could be detected
@throws IOException
tika-core/src/main/java/org/apache/tika/detect/CompositeEncodingDetector.java