aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android
diff options
context:
space:
mode:
authorKurt Partridge <kep@google.com>2013-03-07 19:13:56 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2013-03-07 19:13:56 -0800
commitd9fe8049d44676c74cf8d7209232212f11bb5ba1 (patch)
treea7b043f3817ca9339adca14d404430a04d670504 /java/src/com/android
parent0079d3abf4605baa9a547f37a9ea92365097daf3 (diff)
parentee3261ff558ee734e15af5424f98bb8d8776795f (diff)
downloadlatinime-d9fe8049d44676c74cf8d7209232212f11bb5ba1.tar.gz
latinime-d9fe8049d44676c74cf8d7209232212f11bb5ba1.tar.xz
latinime-d9fe8049d44676c74cf8d7209232212f11bb5ba1.zip
am ee3261ff: [FileEncap7] Extract uploadContents method
* commit 'ee3261ff558ee734e15af5424f98bb8d8776795f': [FileEncap7] Extract uploadContents method
Diffstat (limited to 'java/src/com/android')
-rw-r--r--java/src/com/android/inputmethod/research/Uploader.java19
1 files changed, 11 insertions, 8 deletions
diff --git a/java/src/com/android/inputmethod/research/Uploader.java b/java/src/com/android/inputmethod/research/Uploader.java
index 14e46cd34..ac64076cb 100644
--- a/java/src/com/android/inputmethod/research/Uploader.java
+++ b/java/src/com/android/inputmethod/research/Uploader.java
@@ -143,14 +143,7 @@ public final class Uploader {
connection.setDoOutput(true);
connection.setFixedLengthStreamingMode(contentLength);
final OutputStream outputStream = connection.getOutputStream();
- final byte[] buf = new byte[BUF_SIZE];
- int numBytesRead;
- while ((numBytesRead = fileInputStream.read(buf)) != -1) {
- outputStream.write(buf, 0, numBytesRead);
- if (DEBUG) {
- Log.d(TAG, new String(buf));
- }
- }
+ uploadContents(fileInputStream, outputStream);
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
Log.d(TAG, "upload failed: " + connection.getResponseCode());
final InputStream netInputStream = connection.getInputStream();
@@ -184,4 +177,14 @@ public final class Uploader {
}
return success;
}
+
+ private static void uploadContents(final InputStream is, final OutputStream os)
+ throws IOException {
+ // TODO: Switch to NIO.
+ final byte[] buf = new byte[BUF_SIZE];
+ int numBytesRead;
+ while ((numBytesRead = is.read(buf)) != -1) {
+ os.write(buf, 0, numBytesRead);
+ }
+ }
}