Exemplo n.º 1
0
 /**
  * Loads the friends list
  *
  * @param file The file with the data
  * @throws IOException On I/O error
  */
 private static void loadFriends(final String file) throws IOException {
   friendFile = file;
   final File $file = new File(file);
   friends = new HashSet<Player>();
   if ($file.exists() == false) saveFriends();
   else {
     ObjectInputStream is = null;
     Object obj = null;
     try {
       is = new ObjectInputStream(new BufferedInputStream(new FileInputStream($file)));
       while ((obj = is.readObject()) != null) friends.add((Player) obj);
     } catch (final ClassNotFoundException err) {
       throw new IOError(err);
     } catch (final IOException | RuntimeException | Error err) {
       System.err.println(err);
       System.err.println("obj: " + obj);
       System.err.println("is: " + is);
       throw err;
     } finally {
       if (is != null)
         try {
           is.close();
         } catch (final Throwable err) {
           // Do nothing
         }
     }
   }
 }
Exemplo n.º 2
0
 /**
  * Load, creates if missing, information about the local users
  *
  * @param file The file with the data
  * @throws IOException On I/O error
  */
 private static void loadMe(final String file) throws IOException {
   myFile = file;
   final File $file = new File(file);
   if ($file.exists() == false) {
     myUUID = UUID.randomUUID();
     updateMe(null);
   } else {
     ObjectInputStream is = null;
     try {
       is = new ObjectInputStream(new BufferedInputStream(new FileInputStream($file)));
       Object obj;
       for (; ; )
         if ((obj = is.readObject()) instanceof UUID) {
           System.err.println("Loading UUID: " + obj);
           myUUID = (UUID) obj;
           break;
         } else {
           System.err.println("Loading DNS: " + obj);
           myDNSes.add((String) obj);
         }
     } catch (final ClassNotFoundException err) {
       throw new IOError(err);
     } finally {
       if (is != null)
         try {
           is.close();
         } catch (final Throwable err) {
           // Do nothing
         }
     }
   }
 }