public void setMetadata ( String moduleKeyWithBranch , final DefaultInputFile inputFile , Charset defaultEncoding ) { CharsetDetector charsetDetector = new CharsetDetector ( inputFile . path ( ) , defaultEncoding ) ; try { Charset charset ; if ( charsetDetector . run ( ) ) { charset = charsetDetector . charset ( ) ; } else { LOG . debug ( "Failed to detect a valid charset for file '{}'. Using default charset." , inputFile ) ; charset = defaultEncoding ; } InputStream is = charsetDetector . inputStream ( ) ; inputFile . setCharset ( charset ) ; Metadata metadata = fileMetadata . readMetadata ( is , charset , inputFile . absolutePath ( ) , exclusionsScanner . createCharHandlerFor ( inputFile ) ) ; inputFile . setMetadata ( metadata ) ; inputFile . setStatus ( statusDetection . status ( moduleKeyWithBranch , inputFile , metadata . hash ( ) ) ) ; LOG . debug ( "'{}' generated metadata{} with charset '{}'" , inputFile , inputFile . type ( ) == Type . TEST ? " as test " : "" , charset ) ; } catch ( Exception e ) { throw new IllegalStateException ( e ) ; } }
Sets all metadata in the file including charset and status . It is an expensive computation reading the entire file .