I am looking into IBM's quickfile API. Now I am a front-end developer and I do not know much about Java.
I would like to know how I can implement some of the sample code they provide on the developers website: here is one of the sample codes:
Here is an example of how to use the API to get a list of users. This Java program gets the list of users using a REST request, parses the result as a regular expression, and then prints out the total number of users to the console.
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import org.apache.commons.codec.binary.Base64;
public class QuickFileUserCount {
public static void main(String[] args) {
try {
if (args.length < 4) {
System.out.println("Usage is java QuickFileUserCount <host> <port> <userid> <password>");
System.exit(0);
}
String quickFileServer = args[0];
String quickFilePort = args[1];
String quickFileUser = args[2];
String quickFilePassword = args[3];
String quickFileUserQuery = "http://" + quickFileServer + ":" + quickFilePort + "/quickfile/rest/admin/users/0/0";
URL url = new URL(quickFileUserQuery);
HttpURLConnection uc = (HttpURLConnection) url.openConnection();
uc.setRequestMethod("GET");
uc.setDoInput(true);
String uidpw = quickFileUser + ":" + quickFilePassword;
String encodedPassword = Base64.encodeBase64String(uidpw.getBytes());
uc.setRequestProperty("Authorization", "Basic " + encodedPassword);
InputStream is = uc.getInputStream();
StringBuffer sb = new StringBuffer();
int c;
while ((c = is.read()) != -1) {
sb.append((char) c);
}
String ss = sb.toString();
String ps = "(.*?)\"totalRows\":(.+?),.*";
String userCount = ss.replaceAll(ps, "$2");
System.out.println("\nNumber of QuickFile users on server <" + quickFileServer + "> = " + userCount);
uc.disconnect();
} catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
}
}
}
Do I need to build a custom APP to see this in action? If so, how do I go about this? Since I am new at programming, where do I start?
I would appreciate any answer