code: private static String normalize( String pathName )
      {
          // replaces multiple '/' by one unique '/'
          pathName = pathName.replaceAll( "/+", "/" );
  
          // removes a '/' if it finishes a path and is not root
          pathName = pathName.replaceAll( "(.+)/$", "$1" );
  
          if ( !pathName.startsWith( "/" ) ) {
              pathName = "/" + pathName;
          }
          return pathName;
      }
docs: Replaces double slashes with single slash, remove any trailing slash except for root path '/'. Checks that given
  pathname does not contain any backslash.
  
  @param pathName
  @return normalized string