public String normalizeUri(String uri,boolean isWindows) throws IOException {
  CharBuffer cb=new CharBuffer();
  int len=uri.length();
  if (_maxURILength < len)   throw new BadRequestException(L.l("The request contains an illegal URL because it is too long."));
  char ch;
  if (len == 0 || (ch=uri.charAt(0)) != '/' && ch != '\\')   cb.append('/');
  for (int i=0; i < len; i++) {
    ch=uri.charAt(i);
    if (ch == '/' || ch == '\\') {
      dots:       while (i + 1 < len) {
        ch=uri.charAt(i + 1);
        if (ch == '/' || ch == '\\')         i++;
 else         if (ch != '.')         break dots;
 else         if (len <= i + 2 || (ch=uri.charAt(i + 2)) == '/' || ch == '\\') {
          i+=2;
        }
 else         if (ch != '.')         break dots;
 else         if (len <= i + 3 || (ch=uri.charAt(i + 3)) == '/' || ch == '\\') {
          int j;
          for (j=cb.length() - 1; j >= 0; j--) {
            if ((ch=cb.charAt(j)) == '/' || ch == '\\')             break;
          }
          if (j > 0)           cb.length(j);
 else           cb.length(0);
          i+=3;
        }
 else {
          throw new BadRequestException(L.l("The request contains an illegal URL."));
        }
      }
      while (isWindows && cb.length() > 0 && ((ch=cb.lastChar()) == '.' || ch == ' ')) {
        cb.length(cb.length() - 1);
        if (cb.length() > 0 && (ch=cb.lastChar()) == '/' || ch == '\\') {
          cb.length(cb.length() - 1);
          continue;
        }
      }
      cb.append('/');
    }
 else     if (ch == 0)     throw new BadRequestException(L.l("The request contains an illegal URL."));
 else     cb.append(ch);
  }
  while (isWindows && cb.length() > 0 && ((ch=cb.lastChar()) == '.' || ch == ' ')) {
    cb.length(cb.length() - 1);
  }
  return cb.toString();
}

public String normalizeUri ( String uri , boolean isWindows ) throws IOException { CharBuffer cb = new CharBuffer ( ) ; int len = uri . length ( ) ; if ( _maxURILength < len ) throw new BadRequestException ( L . l ( "The request contains an illegal URL because it is too long." ) ) ; char ch ; if ( len == 0 || ( ch = uri . charAt ( 0 ) ) != '/' && ch != '\\' ) cb . append ( '/' ) ; for ( int i = 0 ; i < len ; i ++ ) { ch = uri . charAt ( i ) ; if ( ch == '/' || ch == '\\' ) { dots : while ( i + 1 < len ) { ch = uri . charAt ( i + 1 ) ; if ( ch == '/' || ch == '\\' ) i ++ ; else if ( ch != '.' ) break dots ; else if ( len <= i + 2 || ( ch = uri . charAt ( i + 2 ) ) == '/' || ch == '\\' ) { i += 2 ; } else if ( ch != '.' ) break dots ; else if ( len <= i + 3 || ( ch = uri . charAt ( i + 3 ) ) == '/' || ch == '\\' ) { int j ; for ( j = cb . length ( ) - 1 ; j >= 0 ; j -- ) { if ( ( ch = cb . charAt ( j ) ) == '/' || ch == '\\' ) break ; } if ( j > 0 ) cb . length ( j ) ; else cb . length ( 0 ) ; i += 3 ; } else { throw new BadRequestException ( L . l ( "The request contains an illegal URL." ) ) ; } } while ( isWindows && cb . length ( ) > 0 && ( ( ch = cb . lastChar ( ) ) == '.' || ch == ' ' ) ) { cb . length ( cb . length ( ) - 1 ) ; if ( cb . length ( ) > 0 && ( ch = cb . lastChar ( ) ) == '/' || ch == '\\' ) { cb . length ( cb . length ( ) - 1 ) ; continue ; } } cb . append ( '/' ) ; } else if ( ch == 0 ) throw new BadRequestException ( L . l ( "The request contains an illegal URL." ) ) ; else cb . append ( ch ) ; } while ( isWindows && cb . length ( ) > 0 && ( ( ch = cb . lastChar ( ) ) == '.' || ch == ' ' ) ) { cb . length ( cb . length ( ) - 1 ) ; } return cb . toString ( ) ; }
normalize a uri to remove ' / / / ' , ' / . / ' , ' foo / . . ' , etc .
