URL-CSV -> Array

Discussion in 'Plugin Development' started by Sayshal, May 10, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Sayshal

    Hey guys, I have a file "admins.csv" on my webserver, and I need to do the following with it:
    The csv is laid out as follows:
    String,String,int,boolean
    NAME,ID,0/1/2,true/false

    So basically, I need to store this data in an Array/HashMap/something that would allow me to read this data and do some math with data matching it. Basically what my program will do is return how many hours a player has been online, Sorting them by Name. The int refers to which gamemode they administrate (we have 3), and the boolean is if they're a multi-gamemode admin.

    Here's my code thus far:
    Code:
    package org.sngaming.bonana.SNG;
     
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import java.util.regex.Pattern;
     
    public class DownloadAndSortCSV {
    private final static Logger dataLogger = Logger.getLogger("LOG");
     
    public static void FileStore() {
    String nextLine;
    URL csvURL = null;
    URLConnection urlConn = null;
    InputStreamReader inputStream = null;
    BufferedReader buffReader = null;
    try {
    // Create the URL object that points
    // at the default file index.html
    csvURL = new URL("http://sngaming.org/admins.csv");
    urlConn = csvURL.openConnection();
    inputStream = new InputStreamReader(urlConn.getInputStream());
    buffReader = new BufferedReader(inputStream);
     
    // Read and print the lines from CSV
    while (true) {
    nextLine = buffReader.readLine();
    if (nextLine != null) {
    System.out.println(nextLine);
    } else {
    break;
    }
    }
    } catch (MalformedURLException e) {
    dataLogger.log(Level.SEVERE,"Please check the URL:" + e.toString());
    } catch (IOException e1) {
    dataLogger.log(Level.SEVERE,"Can't read  from the Internet: " + e1.toString());
    }
    }
     
    static Pattern SteamIDRegex = Pattern.compile(
    "STEAM_(?<universe>[0-5]):(?<authserver>[0-1]):(?<accountid>\\d+)",
    Pattern.CASE_INSENSITIVE);
     
    public static void getMatchingStrings(String adminlist[][]) {
    String regex = "/^STEAM_0:[01]:[0-9]{7,8}$/";
    Pattern steamIDFormat = Pattern
    .compile(regex, Pattern.CASE_INSENSITIVE); /*
    * Case doesn't
    * really matter I
    * guess
    */
    for (int index = 0; adminlist[index][1] != null; index++) {
     
    if (!steamIDFormat.matcher(regex).matches()) {
    dataLogger.log(Level.SEVERE,adminlist[index][0]
    + " has an invalid STEAMID: " + adminlist[index][1]
    + " !");
    }
    }
     
    }
    }
    /*
    * CSV FORMAT NAME,STEAM_ID,0/1/2,TRUE/FALSE,TRUE/FALSE Admin Name, Steam ID,
    * GameMode INT, isMultiAdmin, isTrialAdmin String,String,int,boolean,boolean
    */
    http://pastie.org/7827758 <-- Somewhat better formatting
    I found this code from a daniweb page, as I've never attempted to read/store data from a remote location.

    P.S: Yes, the URL doesn't exist, that's not the problem, right now I just need to make sure it'll store the data correctly.

    Updated code to what I've been trying, sorry to bump but I really need help.

    Bump, does anybody know?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 1, 2016
  2. Offline

    Sayshal

    Kinda worried, no replies... Bump? D:
     
Thread Status:
Not open for further replies.

Share This Page