private static void run( File file )
  {
    nsDetector det = new nsDetector() ;

    // Set an observer...
    // The Notify() will be called when a matching charset is found.

    det.Init( new nsICharsetDetectionObserver()
    {
      public void Notify( String charset )
      {
        found = true ;
        System.out.println( "CHARSET = " + charset ) ;
      }
    } ) ;

    try
    {
      BufferedInputStream imp = new BufferedInputStream(
                                    new FileInputStream( file ) ) ;

      byte[] buf = new byte[1024] ;
      int len ;
      boolean done = false ;
      boolean isAscii = true ;

      while ( (!done) && ((len = imp.read( buf, 0, buf.length)) != -1 ))
      {

        // Check if the stream is only ascii.
        if ( isAscii )
        {
          isAscii = det.isAscii( buf, len ) ;
        }

        // DoIt if non-ascii and not done yet.
        if ( !isAscii && !done )
        {
          done = det.DoIt( buf, len, false ) ;
        }
      }
      det.DataEnd() ;

      if (isAscii) {
         System.out.println("CHARSET = ASCII");
         found = true ;
      }

      if (!found) {
         String prob[] = det.getProbableCharsets() ;
         for(int i=0; i<prob.length; i++) {
              System.out.println("Probable Charset = " + prob[i]);
         }
      }

    }
    catch (Exception e)
    {
      System.out.println( "ERROR" ) ;
    }

  }