Guest User

Checker.java

a guest
Oct 12th, 2011
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.89 KB | None | 0 0
  1. package maintenance;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.net.MalformedURLException;
  7. import java.net.URL;
  8. import java.net.URLConnection;
  9.  
  10. /**
  11.  *
  12.  * @author Tim
  13.  */
  14. public class Checker {
  15.  
  16.     /**
  17.      *
  18.      * @return boolean returns a the status. First of Gamesig online or not. Then s4, then LOCO
  19.      * Will read the data from the GameSig maintenance checker
  20.      */
  21.     public boolean[] checkGames() {
  22.         String line = null; // create empty string
  23.         boolean[] array = new boolean[3]; //create array
  24.  
  25.         //Set gamesig on online and the rest on offline
  26.         array[0] = true;
  27.         array[1] = false;
  28.         array[2] = false;
  29.  
  30.         try {
  31.             URLConnection urlConn = null; //create connection object
  32.             InputStreamReader inStream = null; //create inputstreamreader
  33.             BufferedReader buff = null; //create buffered reader
  34.  
  35.             URL link = new URL("http://www.gamesig.net:80/maintcheck.php?game=java"); //create new URL object with correct link
  36.  
  37.             urlConn = link.openConnection(); //open connection
  38.             inStream = new InputStreamReader(urlConn.getInputStream()); //read data
  39.             buff = new BufferedReader(inStream); //read data
  40.  
  41.             line = buff.readLine(); //get first line
  42.  
  43.             if (line.equals("0")) {
  44.                 array[1] = true; //S4 is online
  45.             }
  46.  
  47.             line = buff.readLine(); //read next line
  48.  
  49.             if (line.equals("1")) {
  50.                 array[2] = true; //LOCO is online
  51.             }
  52.  
  53.         } catch (MalformedURLException e) { //incorrect URL format, will never occur as its predefined
  54.         } catch (IOException e1) { //This means, gameSig is offline
  55.             array[0] = false; //GameSig is offline
  56.             return array;
  57.         }
  58.         return array;
  59.     }
  60. }
  61.  
  62.  
Advertisement
Add Comment
Please, Sign In to add comment