public CompressionCodec getCodec ( Path file ) { CompressionCodec result = null ; if ( codecs != null ) { String filename = file . getName ( ) ; String reversedFilename = new StringBuffer ( filename ) . reverse ( ) . toString ( ) ; SortedMap < String , CompressionCodec > subMap = codecs . headMap ( reversedFilename ) ; if ( ! subMap . isEmpty ( ) ) { String potentialSuffix = subMap . lastKey ( ) ; if ( reversedFilename . startsWith ( potentialSuffix ) ) { result = codecs . get ( potentialSuffix ) ; } } } return result ; }
Find the relevant compression codec for the given file based on its filename suffix .