Revision: 9327
Author: [email protected]
Date: Wed Dec 1 08:36:36 2010
Log: Remove dependency on dev.Util class in DynaTableRf sample code.
Issue 5681.
Patch by: bobv
Review by: rchandia, rjrjr
Review at http://gwt-code-reviews.appspot.com/1164802
http://code.google.com/p/google-web-toolkit/source/detail?r=9327
Modified:
/trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/console/HttpClientTransport.java
=======================================
---
/trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/console/HttpClientTransport.java
Thu Nov 18 13:15:58 2010
+++
/trunk/samples/dynatablerf/src/com/google/gwt/sample/dynatablerf/console/HttpClientTransport.java
Wed Dec 1 08:36:36 2010
@@ -15,7 +15,6 @@
*/
package com.google.gwt.sample.dynatablerf.console;
-import com.google.gwt.dev.util.Util;
import com.google.gwt.requestfactory.shared.RequestTransport;
import org.apache.http.HttpResponse;
@@ -25,7 +24,9 @@
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URI;
@@ -51,7 +52,7 @@
post.setEntity(new StringEntity(payload, "UTF-8"));
HttpResponse response = client.execute(post);
if (200 == response.getStatusLine().getStatusCode()) {
- String contents =
Util.readStreamAsString(response.getEntity().getContent());
+ String contents =
readStreamAsString(response.getEntity().getContent());
receiver.onTransportSuccess(contents);
} else {
receiver.onTransportFailure(response.getStatusLine().getReasonPhrase());
@@ -66,4 +67,33 @@
}
receiver.onTransportFailure(ex.getMessage());
}
-}
+
+ /**
+ * Reads an entire input stream as String. Closes the input stream.
+ */
+ private String readStreamAsString(InputStream in) {
+ try {
+ ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
+ byte[] buffer = new byte[1024];
+ int count;
+ do {
+ count = in.read(buffer);
+ if (count > 0) {
+ out.write(buffer, 0, count);
+ }
+ } while (count >= 0);
+ return out.toString("UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ throw new RuntimeException(
+ "The JVM does not support the compiler's default encoding.", e);
+ } catch (IOException e) {
+ return null;
+ } finally {
+ try {
+ in.close();
+ } catch (IOException ignored) {
+ }
+ }
+ }
+
+}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors