vmassol 01/09/16 04:11:58
Modified: src/framework/share/org/apache/cactus WebResponse.java
Log:
getText() and getTextAsArray() can now be called several times with the same result
Revision Changes Path
1.9 +34 -15
jakarta-cactus/src/framework/share/org/apache/cactus/WebResponse.java
Index: WebResponse.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/src/framework/share/org/apache/cactus/WebResponse.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- WebResponse.java 2001/09/14 20:21:36 1.8
+++ WebResponse.java 2001/09/16 11:11:58 1.9
@@ -72,7 +72,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
*
- * @version $Id: WebResponse.java,v 1.8 2001/09/14 20:21:36 pier Exp $
+ * @version $Id: WebResponse.java,v 1.9 2001/09/16 11:11:58 vmassol Exp $
*/
public class WebResponse
{
@@ -93,6 +93,11 @@
private WebRequest request;
/**
+ * Save the response content for repeatable reads.
+ */
+ private String content;
+
+ /**
* @param theRequest the request data that were used to open the
* connection to the server.
* @param theConnection the original <code>HttpURLConnection</code> used
@@ -127,22 +132,30 @@
*/
public String getText()
{
- StringBuffer sb = new StringBuffer();
-
- try {
- BufferedReader input = new BufferedReader(
- new InputStreamReader(this.connection.getInputStream()));
- char[] buffer = new char[2048];
- int nb;
- while (-1 != (nb = input.read(buffer, 0, 2048))) {
- sb.append(buffer, 0, nb);
+ // Get the text from the save content if content has already been
+ // read.
+ if (this.content == null) {
+
+ StringBuffer sb = new StringBuffer();
+
+ try {
+ BufferedReader input = new BufferedReader(
+ new InputStreamReader(this.connection.getInputStream()));
+ char[] buffer = new char[2048];
+ int nb;
+ while (-1 != (nb = input.read(buffer, 0, 2048))) {
+ sb.append(buffer, 0, nb);
+ }
+ input.close();
+ } catch (IOException e) {
+ throw new ChainedRuntimeException(e);
}
- input.close();
- } catch (IOException e) {
- throw new ChainedRuntimeException(e);
+
+ this.content = sb.toString();
+
}
- return sb.toString();
+ return this.content;
}
/**
@@ -154,8 +167,14 @@
Vector lines = new Vector();
try {
+
+ // Read content first
+ if (this.content == null) {
+ getText();
+ }
+
BufferedReader input = new BufferedReader(
- new InputStreamReader(this.connection.getInputStream()));
+ new StringReader(this.content));
String str;
while (null != (str = input.readLine())) {
lines.addElement(str);
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]