Don't flame.
Create a .dat file and upload it to your host and put the url inside the URL string and be sure to add the urls in the file separated as in:
Code:
http://www.bestrsps.com/play
http://www.bestrsps.com/forum
http://www.bestrsps.com/download
The use of it is highlighted inside the URLManager class. Make sure to add the correct imports. You might end up with errors so be sure to post them below and someone here or I will give it an attempt to help fix.
Code:
import java.util.List;
public final class URLManager {
/**
* Put your server name here in lowercase.
*/
public static String SERVER_NAME = "";
/**
* Put your server url here.
*/
public static String URL = "http://www.myserver.com/"+"/urllist.dat";
public URLManager() {
parse(new String[]{ URL });
}
/**
* Parses the worlds from the specified url into an array of URL instances.
* @Param url
* @return
*/
public void parse(String[] urls) {
List<String> lines = URLUtils.getLines(urls);
if (lines != null) {
this.urls = new String[lines.size()][];
for (int index = 0; index < this.urls.length; index++) {
String[] args = lines.get(index).split(" ");
this.urls[index] = args;
}
} else {
System.out.println("An error occurred while creating the URL list.");
}
}
/**
* Finds the url for the specified string.
* @Param toFind
* @return
*/
private String[] find(String toFind) {
if (urls == null) {
return null;
}
for (String[] list : urls) {
for (String url : list) {
if (url.contains(toFind)) {
return list;
}
}
}
System.out.println("could not find url: " + toFind);
return null;
}
/**
* Returns the url for the world list.
* @return
*/
public String[] getWorldList() {
return find("world");
}
/**
* The URLs.
*/
private String[][] urls;
}
Code:
public final class URLUtils {
/**
* Retrieves the lines from one of the specified urls.
* @Param urls
* @return
*/
public final static List<String> getLines(String[] urls) {
if (urls == null) {
return null;
}
for (String url : urls) {
try {
byte[] urlData = DataUtilities.getData(new URL(url));
if (urlData == null) {
System.out.println("The data retrieved from the url '" + url + "' was null.");
continue;
}
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(urlData)));
List<String> lines = new ArrayList<String>();
while (true) {
String line = bufferedReader.readLine();
if (line == null) {
break;
}
if (line.startsWith("//")) {
continue;
}
lines.add(line);
}
return lines;
} catch (MalformedURLException e) {
System.out.println("The lines were requested from a Malformed URL.");
continue;
} catch (IOException e) {
System.out.println("The lines were requested and received incorrectly.");
continue;
}
}
return null;
}
}
Code:
public final class DataUtilities {
/**
* Generates a Jagex hash for the specified string.
*
* @Param string
* @return
*/
public static int getHash(String string) {
int identifier = 0;
string = string.toUpperCase();
for (int index = 0; index < string.length(); index++) {
identifier = (identifier * 61 + string.charAt(index)) - 32;
}
return identifier;
}
/**
* Returns the specified string as an MD5 hash.
* @Param string
* @return
*/
public static String getMD5(String string) {
try {
java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
byte[] array = md.digest(string.getBytes());
StringBuffer hash = new StringBuffer();
for (int i = 0; i < array.length; ++i) {
hash.append(Integer.toHexString((array[i] & 0xFF) | 0x100).substring(1,3));
}
return hash.toString();
} catch (java.security.NoSuchAlgorithmException e) {
}
return null;
}
/**
* Returns the file as a byte array.
*
* @Param name
* @return
*/
public static byte[] getData(String name) {
File file = new File(PathManager.getDirectory() + name);
if (!file.exists()) {
System.out.println("file '" + file.getAbsolutePath() + "' doesn't exist");
return null;
}
byte[] data = null;
try {
data = new byte[(int) file.length()];
FileInputStream fis = new FileInputStream(file);
fis.read(data);
fis.close();
return data;
} catch (IOException e) {
e.printStackTrace();
} finally {
if (data != null) {
data = null;
}
}
return null;
}
/**
* Returns the file as a byte array.
*
* @Param file
* @return
*/
public static byte[] getData(File file) {
try {
byte[] data = new byte[(int) file.length()];
FileInputStream fis = new FileInputStream(file);
fis.read(data);
fis.close();
return data;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* Gets the file data from the specified URL.
* @Param url
* @return
*/
public static byte[] getData(URL url) {
try {
URLConnection connection = url.openConnection();
int length = connection.getContentLength();
if (length < 0) {
return null;
}
byte[] data = new byte[length];
InputStream inputstream = connection.getInputStream();
int off = 0;
while (off < length) {
int len = length - off;
if (len > 1000) {
len = 1000;
}
int read = inputstream.read(data, off, len);
if (read < 0) {
throw new EOFException();
}
off += read;
}
inputstream.close();
return data;
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
/**
* Compresses the raw data in gzip format.
*
* @Param raw
* @return
*/
public static byte[] compress(byte[] raw) {
try {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
GZIPOutputStream gzo = new GZIPOutputStream(bos);
try {
gzo.write(raw, 0, raw.length);
} finally {
gzo.flush();
bos.flush();
gzo.close();
bos.close();
}
return bos.toByteArray();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* Decompresses the data from gzip.
*
* @Param data
* @return
* @throws IOException
*/
public static byte[] decompress(byte[] data) {
byte[] decompressed = null;
ByteArrayOutputStream out = null;
try {
GZIPInputStream gzi = new GZIPInputStream(new ByteArrayInputStream(data));
out = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int len;
while ((len = gzi.read(buf)) > 0) {
out.write(buf, 0, len);
}
decompressed = out.toByteArray();
return decompressed;
} catch (IOException e) {
e.printStackTrace();
} finally {
decompressed = null;
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return data;
}
/**
* Writes data to the specified file.
*
* @Param file
* @Param data
*/
public static void write(String file, byte[] data) {
try {
if (data != null) {
OutputStream out = new FileOutputStream(file);
out.write(data);
out.flush();
out.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Code:
public final class PathManager {
/**
* Returns the cache directory.
* If it cannot find the default directory or it cannot be made, it will revert to a local
* folder relative to the location the client was started from.
* @return
*/
/**
* Directory strings.
*/
private static String CACHE_DIRECTORY;
private static String WORKING_DIRECTORY;
/**
* Put server cache name here.
*/
private static String CACHE_NAME = "";
public static final String getDirectory(){
if (CACHE_DIRECTORY == null) {
CACHE_DIRECTORY = getInitialDirectory();
}
return CACHE_DIRECTORY;
}
private static final String getInitialDirectory() {
String file_store = "."+CACHE_NAME;
try {
String path = System.getProperty("user.home") + System.getProperty("file.separator");
File loc = new File(path + file_store);
if (!loc.exists()) {
if (loc.mkdirs()) {
System.out.println("[PathManager] The cache directory was created successfully: " + loc.getAbsolutePath());
} else {
System.out.println("[PathManager] An error occurred while creating the cache directory: " + loc.getAbsolutePath());
}
}
if (loc.exists()) {
return path + file_store + System.getProperty("file.separator");
}
} catch (Exception _ex) {
}
String location = ".\\cache\\";
File loc = new File(location);
if (!loc.exists()) {
if (loc.mkdirs()) {
System.out.println("[PathManager] The cache directory was created successfully: " + loc.getAbsolutePath());
} else {
System.out.println("[PathManager] An error occurred while creating the cache directory: " + loc.getAbsolutePath());
}
}
return location;
}
public static final String getWorkingDirectory() {
if (WORKING_DIRECTORY == null) {
WORKING_DIRECTORY = getInitialWorkingDirectory();
}
return WORKING_DIRECTORY;
}
/**
* Returns the working directory.
* @return
*/
private static final String getInitialWorkingDirectory() {
File dir = new File(getDirectory()+ "\\working\\");
if (!dir.exists()) {
if (dir.mkdirs()) {
System.out.println("[PathManager] The working directory was created successfully: " + dir.getAbsolutePath());
} else {
System.out.println("[PathManager] An error occurred while creating working cache directory: " + dir.getAbsolutePath());
}
}
return getDirectory() + "\\working\\";
}
}
Use Eclipse.
Credits: Soulsplit