jpayne@68: package tax; jpayne@68: jpayne@68: import java.io.IOException; jpayne@68: import java.io.InputStream; jpayne@68: import java.net.MalformedURLException; jpayne@68: import java.net.URL; jpayne@68: import java.util.Arrays; jpayne@68: import java.util.Locale; jpayne@68: jpayne@68: import shared.Shared; jpayne@68: import shared.Timer; jpayne@68: jpayne@68: public class Query { jpayne@68: jpayne@68: /** For testing throughput */ jpayne@68: public static void main(String[] args){ jpayne@68: jpayne@68: // sun.net.http.errorstream.enableBuffering=true; jpayne@68: jpayne@68: // System.setProperty("sun.net.http.errorstream.enableBuffering", "true"); jpayne@68: // System.setProperty("http.errorstream.enableBuffering", "true"); jpayne@68: ////// System.setProperty("", ""); jpayne@68: // System.setProperty("http.keepAlive", "true"); jpayne@68: // System.setProperty("http.maxConnections", "50"); jpayne@68: //// System.setProperty("", ""); jpayne@68: //// System.setProperty("", ""); jpayne@68: // jpayne@68: // System.out.println("sun.net.http.errorstream.enableBuffering="+System.getProperty("sun.net.http.errorstream.enableBuffering")); jpayne@68: // System.out.println("sun.net.http.errorstream.timeout="+System.getProperty("sun.net.http.errorstream.timeout")); jpayne@68: // System.out.println("sun.net.http.errorstream.bufferSize="+System.getProperty("sun.net.http.errorstream.bufferSize")); jpayne@68: // System.out.println("http.keepAlive="+System.getProperty("http.keepAlive")); jpayne@68: // System.out.println("http.maxConnections="+System.getProperty("http.maxConnections")); jpayne@68: // System.out.println(System.getProperties()); jpayne@68: // System.out.println("="+System.getProperty("")); jpayne@68: // System.out.println("="+System.getProperty("")); jpayne@68: // System.out.println("="+System.getProperty("")); jpayne@68: jpayne@68: String x=args[0]; jpayne@68: int requests=(args.length>1 ? Integer.parseInt(args[1]) : 1); jpayne@68: jpayne@68: Timer t=new Timer(); jpayne@68: Timer t2=new Timer(); jpayne@68: Timer t3=new Timer(); jpayne@68: jpayne@68: // URL url=toUrl(x); jpayne@68: for(int i=0; i-1){ jpayne@68: next+=count; jpayne@68: if(next>=buffer.length){ jpayne@68: buffer=Arrays.copyOf(buffer, buffer.length*2); jpayne@68: } jpayne@68: count=is.read(buffer, next, buffer.length-next); jpayne@68: } jpayne@68: is.close(); //TODO: Why am I not closing this stream? jpayne@68: return new String(buffer, 0, next); jpayne@68: } catch (IOException e) { jpayne@68: // TODO Auto-generated catch block jpayne@68: e.printStackTrace(); jpayne@68: } jpayne@68: try { jpayne@68: is.close(); jpayne@68: } catch (IOException e) { jpayne@68: // TODO Auto-generated catch block jpayne@68: e.printStackTrace(); jpayne@68: } jpayne@68: return null; jpayne@68: } jpayne@68: jpayne@68: public static InputStream toStream(String x){ jpayne@68: URL url=null; jpayne@68: jpayne@68: try { jpayne@68: url = new URL(x); jpayne@68: } catch (MalformedURLException e1) { jpayne@68: // TODO Auto-generated catch block jpayne@68: e1.printStackTrace(); jpayne@68: return null; jpayne@68: } jpayne@68: jpayne@68: try { jpayne@68: InputStream is=url.openStream(); jpayne@68: return is; jpayne@68: } catch (IOException e) { jpayne@68: // TODO Auto-generated catch block jpayne@68: e.printStackTrace(); jpayne@68: } jpayne@68: return null; jpayne@68: } jpayne@68: jpayne@68: // public static URL toUrl(String x){ jpayne@68: // URL url=null; jpayne@68: // try { jpayne@68: // url = new URL(x); jpayne@68: // } catch (MalformedURLException e1) { jpayne@68: // // TODO Auto-generated catch block jpayne@68: // e1.printStackTrace(); jpayne@68: // } jpayne@68: // jpayne@68: // return url; jpayne@68: // } jpayne@68: // jpayne@68: // public static URLConnection toUrlConnection(URL url, String x){ jpayne@68: // URLConnection urlc=null; jpayne@68: // jpayne@68: // try { jpayne@68: // urlc = url.openConnection(); jpayne@68: // } catch (IOException e) { jpayne@68: // // TODO Auto-generated catch block jpayne@68: // e.printStackTrace(); jpayne@68: // } jpayne@68: // return urlc; jpayne@68: // } jpayne@68: jpayne@68: }