So I have been working on a little method that parses string from a .txt file from my dropbox.
I parse the string, split it and then use the fragments as variables (for quick id fixes, live updates, etc...).
Everything works fine but even though the getDropbox() method is only called during onStart I still feel that it slows down the script way to much.
String dropboxLink = "https://dl.dropboxusercontent.com/u/xxx/xxx.txt";
URL url;
BufferedInputStream in;
HttpURLConnection con;
int responseCode = 0;
public String[] dropboxDataArray;
private void getDropBox() throws IOException {
try {
url = new URL(dropboxLink);
} catch (MalformedURLException e1) {
e1.printStackTrace();
}
HttpURLConnection.setFollowRedirects(true);
try {
con = (HttpURLConnection) url.openConnection();
} catch (IOException e4) {
e4.printStackTrace();
}
con.setDoOutput(false);
con.setReadTimeout(20000);
con.setRequestProperty("Connection", "keep-alive");
con.setRequestProperty("User-Agent",
"Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0");
try {
((HttpURLConnection) con).setRequestMethod("GET");
} catch (ProtocolException e3) {
e3.printStackTrace();
}
con.setConnectTimeout(5000);
try {
in = new BufferedInputStream(con.getInputStream());
} catch (IOException e2) {
e2.printStackTrace();
}
try {
responseCode = con.getResponseCode();
} catch (IOException e1) {
e1.printStackTrace();
}
if (responseCode == HttpURLConnection.HTTP_OK) {
}
StringBuffer buffer = new StringBuffer();
int chars_read;
while ((chars_read = in.read()) != -1)
{
char g = (char) chars_read;
buffer.append(g);
}
final String dropboxContent = buffer.toString();
dropboxDataArray = dropboxContent.split("\\s+");
}