Java function returning stream convert to clob
769226May 8 2010 — edited May 9 2010Hello
I have a java class
package html;
import java.io.ByteArrayOutputStream;
import java.net.URL;
import java.net.Proxy;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringWriter;
import org.w3c.tidy.*;
public class Client {
//private static final String driver_class = "oracle.jdbc.driver.OracleDriver";
public static void setProxy(String host, Integer port){
System.setProperty("http.proxyHost", host);
System.setProperty("http.proxyPOrt", port.toString());
}
public static void main(String[] args){
setProxy("192.168.0.191", 3128);
try{
System.out.println(getSite2("http://www.scoach.ch/"));
} catch (Exception e){
e.printStackTrace();
}
}
public static OutputStream getSite(String sourceUrl) throws Exception {
URL url = new URL(sourceUrl);
InputStream is = url.openStream();
OutputStream os = new ByteArrayOutputStream();
Tidy tidy = new Tidy();
tidy.setQuiet(true);
tidy.setShowWarnings(false);
tidy.setShowErrors(0);
tidy.parse(is, os);
return os;
}
public static String getSite2(String sourceUrl) throws Exception {
URL url = new URL(sourceUrl);
InputStream is = url.openStream();
StringWriter os = new StringWriter();
Tidy tidy = new Tidy();
tidy.setQuiet(true);
tidy.setShowWarnings(false);
tidy.setShowErrors(0);
tidy.parse(is, os);
return os.toString();
}
}
and the wrapper classes:
create or replace procedure set_proxy(proxy IN varchar2, port IN number) AS LANGUAGE JAVA
NAME 'html.Client.setProxy(java.lang.String, java.lang.String)';
/
create or replace function get_site2(site IN varchar2) RETURN CLOB AS LANGUAGE JAVA
NAME 'html.Client.getSite(java.lang.String) return java.lang.String';
/
create or replace function get_site(site IN varchar2) RETURN CLOB AS LANGUAGE JAVA
NAME 'html.Client.getSite(java.lang.String) return java.io.OutputStream';
/
But String and Stream seems not to be compatible to CLOB ... I have found a lot of JDBC samples on the web, but I could not figure out how to use in a java function without inserting into somewhere. What would be the correct way to do this - sorry for the noob question .. I did trial and error for a long time ...
Thanks
Christian Maier