php.java.script
Class URLReader

java.lang.Object
  extended by java.io.Reader
      extended by php.java.script.URLReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable, IScriptReader

public class URLReader
extends java.io.Reader
implements IScriptReader

This class can be used to connect to a HTTP server to allocate and to invoke php scripts. Example:

ScriptEngine e = new ScriptEngineManager().getEngineByName("php-invocable");
e.eval(new URLReader(new URL("http://localhost:80/JavaProxy.php"));
System.out.println(((Invocable)e).invoke("java_get_server_name", new Object[]{}));
((Closeable)e).close();

Author:
jostb

Field Summary
 
Fields inherited from interface php.java.script.IScriptReader
HEADER
 
Constructor Summary
URLReader(java.net.HttpURLConnection conn)
          Create a special reader which can be used to read data from a URL.
URLReader(java.net.URL url)
          Create a special reader which can be used to read data from a URL.
 
Method Summary
 void close()
          
 java.net.URL getURL()
          Returns the URL to which this reader connects.
 int read(char[] cbuf, int off, int len)
          
 void read(java.util.Map env, java.io.OutputStream out, HeaderParser headerParser)
          Read from the URL and write the data to out.
 java.lang.String toString()
          
 
Methods inherited from class java.io.Reader
mark, markSupported, read, read, read, ready, reset, skip
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

URLReader

public URLReader(java.net.URL url)
          throws java.net.UnknownHostException,
                 java.io.IOException
Create a special reader which can be used to read data from a URL.

Parameters:
url -
Throws:
java.io.IOException
java.net.UnknownHostException

URLReader

public URLReader(java.net.HttpURLConnection conn)
Create a special reader which can be used to read data from a URL. Example:
URL url = new URL("http://...."); HttpURLConnection conn = (HttpURLConnection)url.openConnection(); conn.setDoInput(true); conn.setRequestMethod("GET"); conn.setRequestProperty ("SOME_VAR", SOME_VAL); scriptEngine.eval(new URLReader(conn)); ((Invocable)scriptEngine).invokeFunction(...); ((Closeable)scriptEngine).close();

Parameters:
conn - the URL connection
Method Detail

getURL

public java.net.URL getURL()
Returns the URL to which this reader connects.

Returns:
the URL.

read

public int read(char[] cbuf,
                int off,
                int len)
         throws java.io.IOException

Specified by:
read in class java.io.Reader
Throws:
java.io.IOException

read

public void read(java.util.Map env,
                 java.io.OutputStream out,
                 HeaderParser headerParser)
          throws java.io.IOException
Description copied from interface: IScriptReader
Read from the URL and write the data to out.

Specified by:
read in interface IScriptReader
Parameters:
env - The environment, must contain values for X_JAVABRIDGE_CONTEXT. It may contain X_JAVABRIDGE_OVERRIDE_HOSTS.
out - The OutputStream.
headerParser - The header parser
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException

Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Reader
Throws:
java.io.IOException

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object