private static String normalize(StringBuilder sb,String path,int off){
  int len=path.length();
  off=nextNonSlash(path,off,len);
  int start=off;
  char lastC=0;
  while (off < len) {
    char c=path.charAt(off);
    if (isSlash(c)) {
      if (lastC == ' ')       throw new InvalidPathException(path,"Trailing char <" + lastC + ">",off - 1);
      sb.append(path,start,off);
      off=nextNonSlash(path,off,len);
      if (off != len)       sb.append('\\');
      start=off;
    }
 else {
      if (isInvalidPathChar(c))       throw new InvalidPathException(path,"Illegal char <" + c + ">",off);
      lastC=c;
      off++;
    }
  }
  if (start != off) {
    if (lastC == ' ')     throw new InvalidPathException(path,"Trailing char <" + lastC + ">",off - 1);
    sb.append(path,start,off);
  }
  return sb.toString();
}

private static String normalize ( StringBuilder sb , String path , int off ) { int len = path . length ( ) ; off = nextNonSlash ( path , off , len ) ; int start = off ; char lastC = 0 ; while ( off < len ) { char c = path . charAt ( off ) ; if ( isSlash ( c ) ) { if ( lastC == ' ' ) throw new InvalidPathException ( path , "Trailing char <" + lastC + ">" , off - 1 ) ; sb . append ( path , start , off ) ; off = nextNonSlash ( path , off , len ) ; if ( off != len ) sb . append ( '\\' ) ; start = off ; } else { if ( isInvalidPathChar ( c ) ) throw new InvalidPathException ( path , "Illegal char <" + c + ">" , off ) ; lastC = c ; off ++ ; } } if ( start != off ) { if ( lastC == ' ' ) throw new InvalidPathException ( path , "Trailing char <" + lastC + ">" , off - 1 ) ; sb . append ( path , start , off ) ; } return sb . toString ( ) ; }
remove redundant slashes from the rest of the path , forcing all slashes into the preferred slash .
