import org.curl.*;

class test implements CurlWrite {

    public int handleString(byte s[])
    {
        /* output everything */
        System.out.println("IIIIIIIIIII -------------- OOOOOOOOOOOOOOOOOOO");
        try {

          System.out.write(s);

        }
        catch (java.io.IOException moo) {
          // nothing
        }
        return 0;
    }

    public static void main(String[] args)
    {
    	for (int num = 0; num < 10; num++) {
    		System.out.println((num % 2));
    	}
    	
		CurlGlue cg;

        try {
			test cw = null;

        	// Register callback write function
        	cg = new CurlGlue();
        	
        	// this will throw a ERROR_NO_CALLBACK_INSTANCE exception, non-fatal
			try {
				cg.setopt(CURL.OPT_WRITEFUNCTION, cw);
			} catch (CURLException e) {
				System.out.println("Wouldn't have thrown an error if we instantiated test() first!");
			}
        	
        	// we must first instantiate the CurlWrite interface
        	cw = new test();
        	cg.setopt(CURL.OPT_WRITEFUNCTION, cw);
        	
        	
			int result = cg.setopt(CURL.OPT_URL, "https://www.verisign.com");
			cg.setopt(CURL.OPT_SSLVERSION, 3);
			cg.setopt(CURL.OPT_VERBOSE, 1);
			cg.setopt(CURL.OPT_FOLLOWLOCATION, 1);
			cg.setopt(CURL.OPT_HTTPGET, 1);
			
			// I have not tested whether or not the verify peer functions 
			// work with my java implementation. I will be working on this.
			// Better to turn them off for now
			cg.setopt(CURL.OPT_SSL_VERIFYPEER, 0);
			cg.setopt(CURL.OPT_SSL_VERIFYHOST, 0);
			
			result = cg.perform();
			System.out.println("Result of perform: "+result);

			// clean everything up.
			cg.finalize();
		} catch (Exception e) {
       		e.printStackTrace();
		}

    }
}
