public static String leafName ( final String path ) { final int bangIdx = path . indexOf ( ' ' ) ; final int endIdx = bangIdx >= 0 ? bangIdx : path . length ( ) ; int leafStartIdx = 1 + ( File . separatorChar == ' ' ? path . lastIndexOf ( ' ' , endIdx ) : Math . max ( path . lastIndexOf ( ' ' , endIdx ) , path . lastIndexOf ( File . separatorChar , endIdx ) ) ) ; // In case of temp files (for jars extracted from within jars), remove the temp filename prefix -- see // NestedJarHandler.unzipToTempFile() int sepIdx = path . indexOf ( NestedJarHandler . TEMP_FILENAME_LEAF_SEPARATOR ) ; if ( sepIdx >= 0 ) { sepIdx += NestedJarHandler . TEMP_FILENAME_LEAF_SEPARATOR . length ( ) ; } leafStartIdx = Math . max ( leafStartIdx , sepIdx ) ; leafStartIdx = Math . min ( leafStartIdx , endIdx ) ; return path . substring ( leafStartIdx , endIdx ) ; }
Returns the leafname of a path after first stripping off everything after the first ! if present .