public InputStream getInputStream() throws IOException, ProcessingException {
this.getInfos();
try {
InputStream input = null;
if ( this.isFile ) {
input = new FileInputStream(this.systemId.substring(FILE.length()));
} else {
if (this.connection == null) {
this.connection = this.url.openConnection();
/* The following requires a jdk 1.3 */
String userInfo = this.getUserInfo();
if (this.url.getProtocol().startsWith("http") && userInfo != null) {
this.connection.setRequestProperty("Authorization","Basic "+SourceUtil.encodeBASE64(userInfo));
}
// do a post operation
if (this.connection instanceof HttpURLConnection
&& this.postParameters != null) {
StringBuffer buffer = new StringBuffer(2000);
String key;
Iterator i = postParameters.getParameterNames();
Iterator values;
String value;
boolean first = true;
while ( i.hasNext() ) {
key = (String)i.next();
values = this.postParameters.getParameterValues(key);
while (values.hasNext() == true) {
value = SourceUtil.encode((String)values.next());
if (first == false) buffer.append('&");
first = false;
buffer.append(key.toString());
buffer.append('=");
buffer.append(value);
}
}
HttpURLConnection httpCon = (HttpURLConnection)connection;
httpCon.setDoInput(true);
if (buffer.length() > 1) { // only post if we have parameters
String postString = buffer.toString();
httpCon.setRequestMethod("POST"); // this is POST
httpCon.setDoOutput(true);
httpCon.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
// A content-length header must be contained in a POST request
httpCon.setRequestProperty("Content-length", Integer.toString(postString.length()));
java.io.OutputStream out = new java.io.BufferedOutputStream(httpCon.getOutputStream());
out.write(postString.getBytes());
out.close();
}
if ("text/html".equals(httpCon.getContentType()) == true) {
this.isHTMLContent = true;
}
input = httpCon.getInputStream();
this.connection = null; // make sure a new connection is created next time
return input;
}
}
if ("text/html".equals(this.connection.getContentType()) == true) {
this.isHTMLContent = true;
}
input = this.connection.getInputStream();
this.connection = null; // make sure a new connection is created next time
}
return input;
} catch (FileNotFoundException e) {
throw new ResourceNotFoundException("Resource not found "
+ this.systemId, e);
}
} Deprecated!Return an InputStream object to read from the source. |