From 63641659e95680fbe1e1a2a28e1aac4a71382f21 Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Thu, 18 Mar 2010 14:55:37 -0400 Subject: [PATCH] Can't remember, should have committed before. ConcurrentUpdateServer's added. --- .../org/moparscape/cacheutils/v508/Main.java | 11 +- .../moparscape/cacheutils/v508/MainOrig.java | 160 --------------- client317/src/rs/client.java | 2 +- client508/src/client.java | 2 +- renamed508/src/client.java | 3 +- src/org/moparscape/userver/Server.java | 2 +- ...ver.java => ConcurrentOndemandServer.java} | 10 +- .../v508/ConcurrentOndemandServer.java | 185 ++++++++++++++++++ .../userver/v508/OndemandServer.java | 111 ++++++----- 9 files changed, 257 insertions(+), 229 deletions(-) delete mode 100644 cachedump/src/org/moparscape/cacheutils/v508/MainOrig.java rename src/org/moparscape/userver/v317/{OndemandServer.java => ConcurrentOndemandServer.java} (92%) create mode 100644 src/org/moparscape/userver/v508/ConcurrentOndemandServer.java diff --git a/cachedump/src/org/moparscape/cacheutils/v508/Main.java b/cachedump/src/org/moparscape/cacheutils/v508/Main.java index f4a6ce6..17e2b30 100644 --- a/cachedump/src/org/moparscape/cacheutils/v508/Main.java +++ b/cachedump/src/org/moparscape/cacheutils/v508/Main.java @@ -8,6 +8,8 @@ import java.io.PrintStream; public class Main { public static final String folderName = "/home/mopar/htdocs/508/"; + // some (crappy) filesystems can handle more than this many files in any given folder, so we have to handle it (suffer) + public static final int maxFilesInFolder = 33000; public static PrintStream log; public Main() { @@ -32,13 +34,14 @@ public class Main { // testDump(cache, 0, 2560); //testDump(cache, 7, -32165); //testDump(cache, 0, 59137);//0/59137 + //testDump(cache, 255, 1); //System.exit(0); //int index = 7; - // the ids are unsigned shorts, which in java needs an int and is twice a short + // the ids are unsigned shorts, which in java needs an int and is twice a max short int maxId = Short.MAX_VALUE*2; - System.out.println("maxId: "+maxId); - int[] maxIds = new int[255]; + // goes up to index of 255, which needs length of 256 + int[] maxIds = new int[256]; for(int x = 0; x < maxIds.length; ++x) maxIds[x] = maxId; maxIds[0] = 2509; @@ -74,7 +77,7 @@ public class Main { maxIds[10] = 1; dumpFile(cache, 10,1431655766); - for (byte index = 0; index <= 255 && index >= 0; ++index) + for (short index = 0; index <= 255 && index >= 0; ++index) for (int id = 0; id <= maxId && id >= 0; ++id) //for (int id = 0; id <= maxIds[index] && id >= 0; ++id) dumpFile(cache, index, id); diff --git a/cachedump/src/org/moparscape/cacheutils/v508/MainOrig.java b/cachedump/src/org/moparscape/cacheutils/v508/MainOrig.java deleted file mode 100644 index 54e8a34..0000000 --- a/cachedump/src/org/moparscape/cacheutils/v508/MainOrig.java +++ /dev/null @@ -1,160 +0,0 @@ -package org.moparscape.cacheutils.v508; - -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.PrintStream; - -public class MainOrig { - - public static final String folderName = "/home/mopar/htdocs/508/"; - public static PrintStream log; - - public MainOrig() { - try { - CacheFileSet cache = new CacheFileSet("./cachedump/complete508/"); - File dump = new File(folderName); - - if (dump.exists()) - if (!deleteDir(dump)) - System.out.println("can't delete directory"); - if (!dump.mkdir()) { - System.out.println("can't create directory: " + dump.getPath()); - return; - } - - log = new PrintStream(new FileOutputStream(folderName + "dumplog.txt")); - - dumpUpdatekeys(); - - // client requests the following, but I don't have them... ? - // testDump(cache, 0, 5632); - // testDump(cache, 0, 2560); - - for (int index = 0; index <= 255 && index >= 0; ++index) - for (short id = 0; id <= Short.MAX_VALUE && id >= 0; ++id) - dumpFile(cache, index, id); - - } catch (Exception e) { - e.printStackTrace(); - } - - - } - - public void testDump(CacheFileSet cache, int index, int id) throws Exception { - boolean success = !dumpFile(cache, index, (short) id); - println("testDump: " + index + "," + id + " success: " + success); - } - - public boolean dumpFile(CacheFileSet cache, int index, short id) throws Exception { - byte[] data = cache.read(index, id); - - if (data == null) - // println("no data for: " + index + "," + id); - return true; - - println("data for: " + index + "," + id); - - long hash = (long) ((index << 16) + id); - File file = new File(folderName + hash); - if (file.exists()) { - println("oh shit, collision!!!!!!"); - System.exit(1); - } - DataOutputStream out = new DataOutputStream(new FileOutputStream(file)); - out.writeByte(index); - out.writeShort(id); - - int c = 3; - for (int i = 0; i < data.length; i++) { - - if (c == 512) { - out.writeByte(255); - c = 1; - } - out.writeByte(data[i]); - - c++; - } - - out.close(); - - return false; - } - - public void dumpUpdatekeys() throws Exception { - int index = 255; - short id = 255; - long hash = (long) ((index << 16) + id); - File file = new File(folderName + hash); - if (file.exists()) { - println("oh shit, collision (with update keys)!!!!!!"); - System.exit(1); - } - DataOutputStream out = new DataOutputStream(new FileOutputStream(file)); - - int[] UPDATE_KEYS = { - 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xd8, - 0x84, 0xa1, 0xa1, 0x2b, 0x00, 0x00, 0x00, 0xba, - 0x58, 0x64, 0xe8, 0x14, 0x00, 0x00, 0x00, 0x7b, - 0xcc, 0xa0, 0x7e, 0x23, 0x00, 0x00, 0x00, 0x48, - 0x20, 0x0e, 0xe3, 0x6e, 0x00, 0x00, 0x01, 0x88, - 0xec, 0x0d, 0x58, 0xed, 0x00, 0x00, 0x00, 0x71, - 0xb9, 0x4c, 0xc0, 0x50, 0x00, 0x00, 0x01, 0x8b, - 0x5b, 0x61, 0x79, 0x20, 0x00, 0x00, 0x00, 0x0c, - 0x0c, 0x69, 0xb1, 0xc8, 0x00, 0x00, 0x02, 0x31, - 0xc8, 0x56, 0x67, 0x52, 0x00, 0x00, 0x00, 0x69, - 0x78, 0x17, 0x7b, 0xe2, 0x00, 0x00, 0x00, 0xc3, - 0x29, 0x76, 0x27, 0x6a, 0x00, 0x00, 0x00, 0x05, - 0x44, 0xe7, 0x75, 0xcb, 0x00, 0x00, 0x00, 0x08, - 0x7d, 0x21, 0x80, 0xd5, 0x00, 0x00, 0x01, 0x58, - 0xeb, 0x7d, 0x49, 0x8e, 0x00, 0x00, 0x00, 0x0c, - 0xf4, 0xdf, 0xd6, 0x4d, 0x00, 0x00, 0x00, 0x18, - 0xec, 0x33, 0x31, 0x7e, 0x00, 0x00, 0x00, 0x01, - 0xf7, 0x7a, 0x09, 0xe3, 0x00, 0x00, 0x00, 0xd7, - 0xe6, 0xa7, 0xa5, 0x18, 0x00, 0x00, 0x00, 0x45, - 0xb5, 0x0a, 0xe0, 0x64, 0x00, 0x00, 0x00, 0x75, - 0xba, 0xf2, 0xa2, 0xb9, 0x00, 0x00, 0x00, 0x5f, - 0x31, 0xff, 0xfd, 0x16, 0x00, 0x00, 0x01, 0x48, - 0x03, 0xf5, 0x55, 0xab, 0x00, 0x00, 0x00, 0x1e, - 0x85, 0x03, 0x5e, 0xa7, 0x00, 0x00, 0x00, 0x23, - 0x4e, 0x81, 0xae, 0x7d, 0x00, 0x00, 0x00, 0x18, - 0x67, 0x07, 0x33, 0xe3, 0x00, 0x00, 0x00, 0x14, - 0xab, 0x81, 0x05, 0xac, 0x00, 0x00, 0x00, 0x03, - 0x24, 0x75, 0x85, 0x14, 0x00, 0x00, 0x00, 0x36 - }; - - for (int i : UPDATE_KEYS) - out.writeByte(i); - - out.close(); - } - - public static boolean deleteDir(File dir) { - if (dir.isDirectory()) { - String[] children = dir.list(); - for (int i = 0; i < children.length; i++) { - boolean success = deleteDir(new File(dir, children[i])); - if (!success) - return false; - } - } - - // The directory is now empty so delete it - return dir.delete(); - } - - public static void println(String s) throws Exception { - //System.out.println(s); - log.println(s); - } - - public static void main(String args[]) throws Exception { - long startTime = System.currentTimeMillis(); - new MainOrig(); - println("execution time: " + ((System.currentTimeMillis() - startTime) / 1000) + "s"); - log.close(); - - } -} \ No newline at end of file diff --git a/client317/src/rs/client.java b/client317/src/rs/client.java index 658ddb9..6df2c40 100755 --- a/client317/src/rs/client.java +++ b/client317/src/rs/client.java @@ -109,7 +109,7 @@ public class client extends RSApplet { public org.moparscape.userver.Server[] getUpdateServers(String defaultLocation, String customLocation) { org.moparscape.userver.Server[] ret = new org.moparscape.userver.Server[2]; ret[0] = new org.moparscape.userver.v317.JaggrabServer(defaultLocation, customLocation); - ret[1] = new org.moparscape.userver.v317.OndemandServer(defaultLocation, customLocation); + ret[1] = new org.moparscape.userver.v317.ConcurrentOndemandServer(defaultLocation, customLocation); return ret; } diff --git a/client508/src/client.java b/client508/src/client.java index 621ac82..a8fd7d0 100644 --- a/client508/src/client.java +++ b/client508/src/client.java @@ -93,7 +93,7 @@ public class client extends Applet_Sub1 implements ClientInterface { public org.moparscape.userver.Server[] getUpdateServers(String defaultLocation, String customLocation) { org.moparscape.userver.Server[] ret = new org.moparscape.userver.Server[2]; - ret[0] = new org.moparscape.userver.v508.OndemandServer443(defaultLocation, customLocation); + //ret[0] = new org.moparscape.userver.v508.OndemandServer443(defaultLocation, customLocation); ret[1] = new org.moparscape.userver.v508.OndemandServer(defaultLocation, customLocation); return ret; } diff --git a/renamed508/src/client.java b/renamed508/src/client.java index 6a7e704..6a8f159 100644 --- a/renamed508/src/client.java +++ b/renamed508/src/client.java @@ -12,6 +12,7 @@ import java.util.HashMap; import nativeadvert.browsercontrol; import org.moparscape.iface.ClientInterface; +import org.moparscape.userver.v508.ConcurrentOndemandServer; public final class client extends GameApplet implements ClientInterface { @@ -96,7 +97,7 @@ public final class client extends GameApplet implements ClientInterface { public org.moparscape.userver.Server[] getUpdateServers(String defaultLocation, String customLocation) { org.moparscape.userver.Server[] ret = new org.moparscape.userver.Server[2]; ret[0] = new org.moparscape.userver.v508.OndemandServer443(defaultLocation, customLocation); - ret[1] = new org.moparscape.userver.v508.OndemandServer(defaultLocation, customLocation); + ret[1] = new ConcurrentOndemandServer(defaultLocation, customLocation); return ret; } diff --git a/src/org/moparscape/userver/Server.java b/src/org/moparscape/userver/Server.java index 6cb1a26..73e1251 100644 --- a/src/org/moparscape/userver/Server.java +++ b/src/org/moparscape/userver/Server.java @@ -120,7 +120,7 @@ public abstract class Server extends Thread { public HttpURLConnection getHttpURLConnection(String request) { HttpURLConnection ret; String urlStr = customLocation + request; - //System.out.println("getHttpURLConnection urlStr: "+urlStr); + System.out.println("getHttpURLConnection urlStr: "+urlStr); try { ret = (HttpURLConnection) new URL(urlStr).openConnection(); // if response code is not 200 diff --git a/src/org/moparscape/userver/v317/OndemandServer.java b/src/org/moparscape/userver/v317/ConcurrentOndemandServer.java similarity index 92% rename from src/org/moparscape/userver/v317/OndemandServer.java rename to src/org/moparscape/userver/v317/ConcurrentOndemandServer.java index 6aa34fd..6dc89ef 100644 --- a/src/org/moparscape/userver/v317/OndemandServer.java +++ b/src/org/moparscape/userver/v317/ConcurrentOndemandServer.java @@ -14,7 +14,7 @@ import java.net.URLConnection; * Date: Jul 6, 2009 * Time: 2:22:11 PM */ -public class OndemandServer extends Server { +public class ConcurrentOndemandServer extends Server { public static final String odsPath = "317/ondemand/"; // 10 seems to be the correct number @@ -22,19 +22,19 @@ public class OndemandServer extends Server { public int[] requests = new int[concurrentRequests*2]; - public OndemandServer(String defaultLocation) { + public ConcurrentOndemandServer(String defaultLocation) { this(defaultLocation, 0); } - public OndemandServer(String defaultLocation, int port) { + public ConcurrentOndemandServer(String defaultLocation, int port) { super(defaultLocation, port); } - public OndemandServer(String defaultLocation, String customLocation) { + public ConcurrentOndemandServer(String defaultLocation, String customLocation) { this(defaultLocation, 0, customLocation); } - public OndemandServer(String defaultLocation, int port, String customLocation) { + public ConcurrentOndemandServer(String defaultLocation, int port, String customLocation) { super(defaultLocation, port, customLocation); } diff --git a/src/org/moparscape/userver/v508/ConcurrentOndemandServer.java b/src/org/moparscape/userver/v508/ConcurrentOndemandServer.java new file mode 100644 index 0000000..f7fe568 --- /dev/null +++ b/src/org/moparscape/userver/v508/ConcurrentOndemandServer.java @@ -0,0 +1,185 @@ +package org.moparscape.userver.v508; + +import org.moparscape.userver.Server; + +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.Socket; +import java.net.URLConnection; + +/** + * Class:OndemandServer + * User: Silabsoft + * Date: Jul 6, 2009 + * Time: 2:22:11 PM + */ +public class ConcurrentOndemandServer extends Server { + + public static final String odsPath = "508/%d/%d"; + public static final int clientVersion = 508; + // for some reason, any more than 1 makes the client request pieces that don't exist (so I'm using OndemandServer now) + public static final int concurrentRequests = 1; + + public String[] requests = new String[concurrentRequests]; + public byte[] buffer = new byte[1024]; + public int len; + + public ConcurrentOndemandServer(String defaultLocation) { + this(defaultLocation, 0); + } + + public ConcurrentOndemandServer(String defaultLocation, int port) { + super(defaultLocation, port); + } + + public ConcurrentOndemandServer(String defaultLocation, String customLocation) { + this(defaultLocation, 0, customLocation); + } + + public ConcurrentOndemandServer(String defaultLocation, int port, String customLocation) { + super(defaultLocation, port, customLocation); + } + + public void handleConnection(Socket s) throws IOException { + //System.out.println("ods: new connection to update server"); + + boolean identify = false; + DataOutputStream out = new DataOutputStream(s.getOutputStream()); + DataInputStream in = new DataInputStream(s.getInputStream()); + //s.setSoTimeout(0); + if (in == null) + return; + while (!s.isClosed()) { + //System.out.println("in loop"); + byte dataType = 0; + int version = 0; + if (!identify) { + //s.setSoTimeout(100); + //System.out.println("HERE!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + dataType = in.readByte(); + //System.out.println("ANDNOW!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"); + //s.setSoTimeout(0); + version = in.readInt(); + //System.out.println("dataType:" + dataType + " version:" + version); + } + if (dataType == 15 && version == clientVersion) { + //System.out.println("new client connected to update server"); + out.writeByte(0); + identify = true; + in.skip(4); + } else { + int type = in.read(); + //System.out.println("type:" + type); + // if (type != 0 && type != 1 && type != 3) + // System.exit(-433); + //int hash = ((in.get()& 0xff) << 16) + ((in.get()& 0xff) << 8) + (in.get()& 0xff); + if (type == 0 || type == 1) { + //int index = in.read() & 0xff; + //int id = in.readShort(); + int uid = (in.readUnsignedByte() << 16) + (in.readUnsignedByte() << 8) + in.readUnsignedByte(); + int index = uid >> 16; + int id = uid & 0xFFFF; + + if (index == 255 && id == 255) { + // serve update keys + URLConnection url = getHttpURLConnection(String.format(odsPath, index, id)); + + // if url is null, custom and default cannot be reached, continue + if (url == null) { + // unless we want the update keys and may not be connected to the internet + // so we server them up if it is that which we are requesting + System.out.println("UpdateServer: Update Keys do not exist on server, serving generic ones."); + int[] UPDATE_KEYS = { + 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xd8, + 0x84, 0xa1, 0xa1, 0x2b, 0x00, 0x00, 0x00, 0xba, + 0x58, 0x64, 0xe8, 0x14, 0x00, 0x00, 0x00, 0x7b, + 0xcc, 0xa0, 0x7e, 0x23, 0x00, 0x00, 0x00, 0x48, + 0x20, 0x0e, 0xe3, 0x6e, 0x00, 0x00, 0x01, 0x88, + 0xec, 0x0d, 0x58, 0xed, 0x00, 0x00, 0x00, 0x71, + 0xb9, 0x4c, 0xc0, 0x50, 0x00, 0x00, 0x01, 0x8b, + 0x5b, 0x61, 0x79, 0x20, 0x00, 0x00, 0x00, 0x0c, + 0x0c, 0x69, 0xb1, 0xc8, 0x00, 0x00, 0x02, 0x31, + 0xc8, 0x56, 0x67, 0x52, 0x00, 0x00, 0x00, 0x69, + 0x78, 0x17, 0x7b, 0xe2, 0x00, 0x00, 0x00, 0xc3, + 0x29, 0x76, 0x27, 0x6a, 0x00, 0x00, 0x00, 0x05, + 0x44, 0xe7, 0x75, 0xcb, 0x00, 0x00, 0x00, 0x08, + 0x7d, 0x21, 0x80, 0xd5, 0x00, 0x00, 0x01, 0x58, + 0xeb, 0x7d, 0x49, 0x8e, 0x00, 0x00, 0x00, 0x0c, + 0xf4, 0xdf, 0xd6, 0x4d, 0x00, 0x00, 0x00, 0x18, + 0xec, 0x33, 0x31, 0x7e, 0x00, 0x00, 0x00, 0x01, + 0xf7, 0x7a, 0x09, 0xe3, 0x00, 0x00, 0x00, 0xd7, + 0xe6, 0xa7, 0xa5, 0x18, 0x00, 0x00, 0x00, 0x45, + 0xb5, 0x0a, 0xe0, 0x64, 0x00, 0x00, 0x00, 0x75, + 0xba, 0xf2, 0xa2, 0xb9, 0x00, 0x00, 0x00, 0x5f, + 0x31, 0xff, 0xfd, 0x16, 0x00, 0x00, 0x01, 0x48, + 0x03, 0xf5, 0x55, 0xab, 0x00, 0x00, 0x00, 0x1e, + 0x85, 0x03, 0x5e, 0xa7, 0x00, 0x00, 0x00, 0x23, + 0x4e, 0x81, 0xae, 0x7d, 0x00, 0x00, 0x00, 0x18, + 0x67, 0x07, 0x33, 0xe3, 0x00, 0x00, 0x00, 0x14, + 0xab, 0x81, 0x05, 0xac, 0x00, 0x00, 0x00, 0x03, + 0x24, 0x75, 0x85, 0x14, 0x00, 0x00, 0x00, 0x36 + }; + for (int i : UPDATE_KEYS) + out.writeByte(i); + out.flush(); + continue; + } + + InputStream data1 = url.getInputStream(); + + // buffer and len are static + while ((len = data1.read(buffer)) >= 0) + out.write(buffer, 0, len); + out.flush(); + data1.close(); + + // served update keys, so get next request + continue; + } + + this.requests[0] = String.format(odsPath, index, id); + //System.out.println("request0: " + this.requests[0]); + // queue the requests + for (int x = 1; x < concurrentRequests; ++x) { + //index = in.read() & 0xff; + //id = in.readShort(); + uid = (in.readUnsignedByte() << 16) + (in.readUnsignedByte() << 8) + in.readUnsignedByte(); + index = uid >> 16; + id = uid & 0xFFFF; + this.requests[x] = String.format(odsPath, index, id); + //System.out.println("request" + x + ": " + this.requests[x]); + } + + // serve the requests + for (String request : requests) { + //System.out.println("request: " + request); + URLConnection url = getHttpURLConnection(request); + // if url is null, custom and default cannot be reached, continue + if (url == null){ + /* out.writeByte(index); + out.writeShort(id); + out.writeByte(0); + out.writeInt(0); + */ continue; + } + + //int size = url.getContentLength(); + // if size == -1 it doesn't exist + // however this cannot be counted on as a 404 will still send html + //System.out.println("size: " + size); + InputStream data1 = url.getInputStream(); + + // buffer and len are static + while ((len = data1.read(buffer)) >= 0) + out.write(buffer, 0, len); + data1.close(); + } + out.flush(); + } + + } + } + } +} diff --git a/src/org/moparscape/userver/v508/OndemandServer.java b/src/org/moparscape/userver/v508/OndemandServer.java index f471215..557437d 100644 --- a/src/org/moparscape/userver/v508/OndemandServer.java +++ b/src/org/moparscape/userver/v508/OndemandServer.java @@ -19,9 +19,7 @@ public class OndemandServer extends Server { public static final String odsPath = "508/%d/%d"; public static final int clientVersion = 508; - public static final int concurrentRequests = 10; - public String[] requests = new String[concurrentRequests]; public byte[] buffer = new byte[1024]; public int len; @@ -80,15 +78,49 @@ public class OndemandServer extends Server { int uid = (in.readUnsignedByte() << 16) + (in.readUnsignedByte() << 8) + in.readUnsignedByte(); int index = uid >> 16; int id = uid & 0xFFFF; + //System.out.println("index:" + index + " id:" + id); +// if (index == 255 && id == 255) { +// System.out.println("writing out update keys"); +// for (int i : UPDATE_KEYS) +// out.writeByte(i); +// out.flush(); +// continue; +// } - if (index == 255 && id == 255) { - // serve update keys - URLConnection url = getHttpURLConnection(String.format(odsPath, index, id)); +// byte[] data = cache.read(index, id); +// out.writeByte(index); +// out.writeShort(id); +// +// if (data == null) { +// System.out.println("oh shit"); +// return; +// } +// int c = 3; +// for (int i = 0; i < data.length; i++) { +// +// if (c == 512) { +// out.writeByte(255); +// c = 1; +// } +// out.writeByte(data[i]); +// +// c++; +// } +// out.flush(); +// +// if(true) +// continue; - // if url is null, custom and default cannot be reached, continue - if (url == null) { - // unless we want the update keys and may not be connected to the internet - // so we server them up if it is that which we are requesting + //long hash = (long) ((index << 16) + id); + //System.out.println("request " + hash); + //System.out.println(String.format(odsPath, index, id)); + + URLConnection url = getHttpURLConnection(String.format(odsPath, index, id)); + // if url is null, custom and default cannot be reached, continue + if (url == null) { + // unless we want the update keys and may not be connected to the internet + // so we server them up if it is that which we are requesting + if (index == 255 && id == 255) { System.out.println("UpdateServer: Update Keys do not exist on server, serving generic ones."); int[] UPDATE_KEYS = { 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0x00, 0xd8, @@ -123,59 +155,26 @@ public class OndemandServer extends Server { for (int i : UPDATE_KEYS) out.writeByte(i); out.flush(); - continue; } - - InputStream data1 = url.getInputStream(); - - // buffer and len are static - while ((len = data1.read(buffer)) >= 0) - out.write(buffer, 0, len); - out.flush(); - data1.close(); - - // served update keys, so get next request continue; } - this.requests[0] = String.format(odsPath, index, id); - //System.out.println("request0: " + this.requests[0]); - // queue the requests - for (int x = 1; x < concurrentRequests; ++x) { - //index = in.read() & 0xff; - //id = in.readShort(); - uid = (in.readUnsignedByte() << 16) + (in.readUnsignedByte() << 8) + in.readUnsignedByte(); - index = uid >> 16; - id = uid & 0xFFFF; - this.requests[x] = String.format(odsPath, index, id); - //System.out.println("request" + x + ": " + this.requests[x]); - } - - // serve the requests - for (String request : requests) { - //System.out.println("request: " + request); - URLConnection url = getHttpURLConnection(request); - // if url is null, custom and default cannot be reached, continue - if (url == null){ - out.writeByte(index); - out.writeShort(id); - out.writeByte(0); - out.writeInt(0); - continue; - } - - //int size = url.getContentLength(); - // if size == -1 it doesn't exist - // however this cannot be counted on as a 404 will still send html - //System.out.println("size: " + size); - InputStream data1 = url.getInputStream(); - - // buffer and len are static - while ((len = data1.read(buffer)) >= 0) - out.write(buffer, 0, len); - data1.close(); + //int size = url.getContentLength(); + // if size == -1 it doesn't exist + // however this cannot be counted on as a 404 will still send html + //System.out.println("size: " + size); + System.out.println("opening stream"); + InputStream data1 = url.getInputStream(); + System.out.println("InputStream Open!"); + + // buffer and len are static + while ((len = data1.read(buffer)) >= 0){ + System.out.println("len read:"+len); + out.write(buffer, 0, len); } + System.out.println("Data Written! len:"+len); out.flush(); + data1.close(); } }