2006/unicorn/org/w3c/unicorn/request DirectRequestGET.java,1.5,1.6 DirectRequestPOST.java,1.7,1.8 Request.java,1.7,1.8 URIRequest.java,1.6,1.7 UploadRequest.java,1.6,1.7

Update of /sources/public/2006/unicorn/org/w3c/unicorn/request
In directory hutz:/tmp/cvs-serv7539/org/w3c/unicorn/request

Modified Files:
	DirectRequestGET.java DirectRequestPOST.java Request.java 
	URIRequest.java UploadRequest.java 
Log Message:
fixed a bug with special characters caused by a deprecated class (now using a StringBuilder)

Index: DirectRequestPOST.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/DirectRequestPOST.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- DirectRequestPOST.java	27 Aug 2008 12:09:45 -0000	1.7
+++ DirectRequestPOST.java	10 Sep 2008 10:10:40 -0000	1.8
@@ -175,21 +175,8 @@
 		this.aOutputStream.close();
 		
 		InputStream is = aURLConnection.getInputStream();
-		StringBuffer sb = new StringBuffer();
 		
-		BufferedReader br = new BufferedReader(new InputStreamReader(is));
-		String s;
-		while ((s = br.readLine()) != null) {
-			sb.append(s + "\n");
-		}
-		br.close();
-		this.setResponseBuffer(sb);
-		
-		StringBufferInputStream sbis = new StringBufferInputStream(sb.toString());
-		Response aObservationResponse = ResponseParserFactory.parse(sbis,
-				this.getResponseType());
-		aObservationResponse.setXml(sb);
-		return aObservationResponse;
+    return streamToResponse(is);
 	}
 
 	@Override

Index: DirectRequestGET.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/DirectRequestGET.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- DirectRequestGET.java	27 Aug 2008 12:09:45 -0000	1.5
+++ DirectRequestGET.java	10 Sep 2008 10:10:40 -0000	1.6
@@ -103,21 +103,8 @@
 		final URLConnection aURLConnection = aURL.openConnection();
 		aURLConnection.setRequestProperty("Accept-Language", this.sLang);
 		InputStream is = aURLConnection.getInputStream();
-		StringBuffer sb = new StringBuffer();
-		
-		BufferedReader br = new BufferedReader(new InputStreamReader(is));
-		String s;
-		while ((s = br.readLine()) != null) {
-			sb.append(s + "\n");
-		}
-		br.close();
-		this.setResponseBuffer(sb);
-		
-		StringBufferInputStream sbis = new StringBufferInputStream(sb.toString());
-		Response aObservationResponse = ResponseParserFactory.parse(sbis,
-				this.getResponseType());
-		aObservationResponse.setXml(sb);
-		return aObservationResponse;
+
+    return streamToResponse(is);
 	}
 
 	@Override

Index: UploadRequest.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/UploadRequest.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- UploadRequest.java	27 Aug 2008 12:09:59 -0000	1.6
+++ UploadRequest.java	10 Sep 2008 10:10:40 -0000	1.7
@@ -124,22 +124,7 @@
 		final Response aObservationResponse;
 		InputStream is = this.aClientHttpRequest.post();
 		
-		StringBuffer sb = new StringBuffer();
-		
-		BufferedReader br = new BufferedReader(new InputStreamReader(is));
-		String s;
-		while ((s = br.readLine()) != null) {
-			sb.append(s + "\n");
-		}
-		br.close();
-		this.setResponseBuffer(sb);
-		
-		StringBufferInputStream sbis = new StringBufferInputStream(sb.toString());
-		
-		aObservationResponse = ResponseParserFactory.parse(sbis
-				, this.getResponseType());
-		aObservationResponse.setXml(sb);
-		return aObservationResponse;
+    return streamToResponse(is);
 	}
 
 	@Override

Index: Request.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/Request.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- Request.java	27 Aug 2008 12:09:45 -0000	1.7
+++ Request.java	10 Sep 2008 10:10:40 -0000	1.8
@@ -6,11 +6,14 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.InputStreamReader;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.w3c.unicorn.contract.EnumInputMethod;
 import org.w3c.unicorn.input.InputModule;
+import org.w3c.unicorn.response.Response;
+import org.w3c.unicorn.response.parser.ResponseParserFactory;
 
 /**
  * 
@@ -23,10 +26,6 @@
 	protected static final Log logger = LogFactory
 			.getLog("org.w3c.unicorn.request");
 
-	protected InputStream responseStream;
-	protected StringBuffer responseBuffer;
-	
-	
 	/**
 	 * Language of the request
 	 */
@@ -136,20 +135,19 @@
 		this.responseType = responseType;
 	}
 	
-	public InputStream getResponseStream() {
-		return responseStream;
-	}
-	
-	public void setResponseStream(InputStream is) {
-		this.responseStream = is;
-	}
-	
-	public StringBuffer getResponseBuffer() {
-		return responseBuffer;
-	}
-	
-	public void setResponseBuffer(StringBuffer sb) {
-		this.responseBuffer = sb;
-	}
+  protected Response streamToResponse(InputStream is) throws IOException {
+      StringBuilder builder = new StringBuilder();
+      InputStreamReader isr = new InputStreamReader(is);
+      char[] chararray = new char[8192];
+      int readLength = 0;
+      while((readLength = isr.read(chararray, 0, 8192)) > -1) {
+          builder.append(chararray, 0, readLength);
+      }
+      
+      Response res = ResponseParserFactory.parse(builder.toString(), 
+                                                 this.getResponseType());
+      res.setXml(builder);
 
+      return res;
+  }
 }

Index: URIRequest.java
===================================================================
RCS file: /sources/public/2006/unicorn/org/w3c/unicorn/request/URIRequest.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- URIRequest.java	27 Aug 2008 12:09:59 -0000	1.6
+++ URIRequest.java	10 Sep 2008 10:10:40 -0000	1.7
@@ -121,32 +121,8 @@
 		aURLConnection.setRequestProperty("Accept-Language", this.sLang);
 
 		InputStream is = aURLConnection.getInputStream();
-		//System.out.println("mark supported : " + is.markSupported());
-		//System.out.println("is class : " + is.getClass());
-		setResponseStream(is);
-		
-		StringBuffer sb = new StringBuffer();
-		
-		BufferedReader br = new BufferedReader(new InputStreamReader(is));
-		String s;
-		while ((s = br.readLine()) != null) {
-			sb.append(s + "\n");
-			//System.out.println(s);
-		}
-		br.close();
-		this.setResponseBuffer(sb);
-		
 
-		StringBufferInputStream sbis = new StringBufferInputStream(sb.toString());
-		//System.out.println(sb.toString());
-		//System.out.println("response stream set");
-		//Response res = this.aResponseParser.parse(is);
-		Response res = ResponseParserFactory.parse(sbis, this.getResponseType());
-		res.setXml(sb);
-		//Response res = null;
-		//System.out.println("response created");
-		//is.reset();
-		return res;
+		return streamToResponse(is);
 	}
 
 	@Override

Received on Wednesday, 10 September 2008 10:11:17 UTC