Last active
July 10, 2016 20:26
-
-
Save Xhendos/dd735bb5fb9d419731b74ca98d0c6e14 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.utils; | |
import java.io.BufferedReader; | |
import java.io.File; | |
import java.io.FileOutputStream; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.io.InputStreamReader; | |
import java.io.OutputStream; | |
import java.net.URL; | |
import java.net.URLConnection; | |
import java.util.ArrayList; | |
import java.util.jar.JarFile; | |
public class WebUtility { | |
public static String getGamepackURL() throws IOException | |
{ | |
String line; | |
ArrayList<String> list = new ArrayList<String>(); | |
/* | |
* | |
* Build the URL and open the connection | |
* | |
*/ | |
String location = "http://www.oldschool.runescape.com/jav_config.ws"; | |
URL url = new URL(location); | |
URLConnection connection = url.openConnection(); | |
/* | |
* | |
* Set up the reader and read out | |
* | |
*/ | |
InputStream in = connection.getInputStream(); | |
InputStreamReader inr = new InputStreamReader(in); | |
BufferedReader bufr = new BufferedReader(inr); | |
while((line = bufr.readLine()) != null) | |
{ | |
list.add(line); | |
} | |
bufr.close(); | |
/* | |
* | |
* Gets the codebase and initial jar location | |
* | |
*/ | |
String codebase = getCodebase(list); | |
String jar = getInitialJar(list); | |
return codebase + jar; | |
} | |
private static String getCodebase(ArrayList<String> list) | |
{ | |
String raw = list.get(2); | |
String[] filtered = raw.split("codebase="); | |
for(String s : filtered) | |
{ | |
if(s.startsWith("http")) | |
{ | |
return s; | |
} | |
} | |
return null; | |
} | |
private static String getInitialJar(ArrayList<String> list) | |
{ | |
String raw = list.get(5); | |
String[] filtered = raw.split("initial_jar="); | |
for(String s : filtered) | |
{ | |
if(s.startsWith("gamepack")) | |
{ | |
return s; | |
} | |
} | |
return null; | |
} | |
public static JarFile downloadGamepack(String location) throws IOException | |
{ | |
try | |
{ | |
OutputStream out; | |
InputStream in; | |
int read; | |
URL url = new URL(location); | |
URLConnection connection = url.openConnection(); | |
in = connection.getInputStream(); | |
out = new FileOutputStream("/home/pi/Downloads/downloadedJar.jar"); | |
while((read = in.read()) != -1) | |
{ | |
out.write(read); | |
} | |
out.flush(); | |
out.close(); | |
JarFile file = new JarFile("/home/pi/Downloads/downloadedJar.jar"); | |
return file; | |
} catch(Exception e) | |
{ | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment