public static XAuthority[] get_authorities () {
    String auth_filename = System.getenv ("XAUTHORITY");
    if (auth_filename == null || auth_filename.equals (""))
      auth_filename = System.getProperty ("user.home") + File.separatorChar
                      + ".Xauthority";
    File auth_file = new File (auth_filename);
    ArrayList authorities = new ArrayList ();
    FileInputStream in;
    try {
      in = new FileInputStream (auth_file);
      while (bytes_read != -1) {
        XAuthority xauth = new XAuthority (in);
        if (xauth.type != TYPE_EOF)
          authorities.add (xauth);
      }
      in.close ();
    } catch (FileNotFoundException ex) {
      System.err.println ("Can't find Xauthority file: " + auth_filename);
    } catch (IOException ex) {
      System.err.println ("unexpected problem while reading Xauthority file");
    }

    return (XAuthority[]) authorities.toArray
                                         (new XAuthority[authorities.size ()]);
  }