public static ContentInfo findExtensionMatch ( String name ) { name = name . toLowerCase ( ) ; // look up the whole name first ContentType type = ContentType . fromFileExtension ( name ) ; if ( type != ContentType . OTHER ) { return new ContentInfo ( type ) ; } // now find the .ext part, if any int index = name . lastIndexOf ( ' ' ) ; if ( index < 0 || index == name . length ( ) - 1 ) { return null ; } type = ContentType . fromFileExtension ( name . substring ( index + 1 ) ) ; if ( type == ContentType . OTHER ) { return null ; } else { return new ContentInfo ( type ) ; } }
Return the content type if the extension from the file - name matches our internal list . This can either be just the extension part or it will look for the last period and take the string after that as the extension .