diff options
author | Koushik Dutta <koushd@gmail.com> | 2013-09-10 22:06:55 -0700 |
---|---|---|
committer | Koushik Dutta <koushd@gmail.com> | 2013-09-10 22:06:55 -0700 |
commit | 22a2ee68b0b23379593baf007b911f3b043f2088 (patch) | |
tree | 89a35ee07f6331f23846552172fb6f21079c82a0 | |
parent | c7fbf81aa1d58b288fe42ce4569a3ca8c5300016 (diff) | |
download | AndroidAsync-22a2ee68b0b23379593baf007b911f3b043f2088.tar.gz AndroidAsync-22a2ee68b0b23379593baf007b911f3b043f2088.tar.bz2 AndroidAsync-22a2ee68b0b23379593baf007b911f3b043f2088.zip |
move StreamUtility
Change-Id: I52626e70495dc40a4cd039ea4f2cec23a7952d3a
-rw-r--r-- | AndroidAsync/src/com/koushikdutta/async/util/StreamUtility.java (renamed from AndroidAsyncTest/src/com/koushikdutta/async/test/StreamUtility.java) | 60 | ||||
-rw-r--r-- | AndroidAsyncTest/src/com/koushikdutta/async/test/FileTests.java | 1 | ||||
-rw-r--r-- | AndroidAsyncTest/src/com/koushikdutta/async/test/HttpServerTests.java | 1 |
3 files changed, 9 insertions, 53 deletions
diff --git a/AndroidAsyncTest/src/com/koushikdutta/async/test/StreamUtility.java b/AndroidAsync/src/com/koushikdutta/async/util/StreamUtility.java index d381f94..cab90c6 100644 --- a/AndroidAsyncTest/src/com/koushikdutta/async/test/StreamUtility.java +++ b/AndroidAsync/src/com/koushikdutta/async/util/StreamUtility.java @@ -1,12 +1,4 @@ -package com.koushikdutta.async.test; - -import android.net.http.AndroidHttpClient; - -import org.apache.http.HttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.HttpUriRequest; -import org.json.JSONException; -import org.json.JSONObject; +package com.koushikdutta.async.util; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; @@ -18,10 +10,11 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.ByteBuffer; +import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; -class StreamUtility { +public class StreamUtility { public static void fastChannelCopy(final ReadableByteChannel src, final WritableByteChannel dest) throws IOException { final ByteBuffer buffer = ByteBuffer.allocateDirect(16 * 1024); while (src.read(buffer) != -1) { @@ -43,50 +36,11 @@ class StreamUtility { public static void copyStream(InputStream input, OutputStream output) throws IOException { -// final ReadableByteChannel inputChannel = Channels.newChannel(input); -// final WritableByteChannel outputChannel = Channels.newChannel(output); -// // copy the channels -// fastChannelCopy(inputChannel, outputChannel); -// // closing the channels -//// inputChannel.close(); -//// outputChannel.close(); - - - byte[] stuff = new byte[65536]; - int read = 0; - int total = 0; - while ((read = input.read(stuff)) != -1) - { - output.write(stuff, 0, read); - total += read; - } -// return total; + final ReadableByteChannel inputChannel = Channels.newChannel(input); + final WritableByteChannel outputChannel = Channels.newChannel(output); + // copy the channels + fastChannelCopy(inputChannel, outputChannel); } - - public static String downloadUriAsString(String uri) throws IOException { - HttpGet get = new HttpGet(uri); - return downloadUriAsString(get); - } - - - public static String downloadUriAsString(final HttpUriRequest req) throws IOException { - AndroidHttpClient client = AndroidHttpClient.newInstance("Android"); - try { - HttpResponse res = client.execute(req); - return readToEnd(res.getEntity().getContent()); - } - finally { - client.close(); - } - } - - public static JSONObject downloadUriAsJSONObject(String uri) throws IOException, JSONException { - return new JSONObject(downloadUriAsString(uri)); - } - - public static JSONObject downloadUriAsJSONObject(HttpUriRequest req) throws IOException, JSONException { - return new JSONObject(downloadUriAsString(req)); - } public static byte[] readToEndAsArray(InputStream input) throws IOException { diff --git a/AndroidAsyncTest/src/com/koushikdutta/async/test/FileTests.java b/AndroidAsyncTest/src/com/koushikdutta/async/test/FileTests.java index 8b2ae36..1d37239 100644 --- a/AndroidAsyncTest/src/com/koushikdutta/async/test/FileTests.java +++ b/AndroidAsyncTest/src/com/koushikdutta/async/test/FileTests.java @@ -5,6 +5,7 @@ import com.koushikdutta.async.FileDataEmitter; import com.koushikdutta.async.future.Future; import com.koushikdutta.async.future.FutureCallback; import com.koushikdutta.async.parser.StringParser; +import com.koushikdutta.async.util.StreamUtility; import junit.framework.TestCase; diff --git a/AndroidAsyncTest/src/com/koushikdutta/async/test/HttpServerTests.java b/AndroidAsyncTest/src/com/koushikdutta/async/test/HttpServerTests.java index 3d6ca3c..937ed8a 100644 --- a/AndroidAsyncTest/src/com/koushikdutta/async/test/HttpServerTests.java +++ b/AndroidAsyncTest/src/com/koushikdutta/async/test/HttpServerTests.java @@ -12,6 +12,7 @@ import com.koushikdutta.async.http.server.AsyncHttpServer; import com.koushikdutta.async.http.server.AsyncHttpServerRequest; import com.koushikdutta.async.http.server.AsyncHttpServerResponse; import com.koushikdutta.async.http.server.HttpServerRequestCallback; +import com.koushikdutta.async.util.StreamUtility; import junit.framework.TestCase; |