[FileEncap7] Extract uploadContents method

Change-Id: I018b2726533042dbcb25713ea039aec41c148db2
main
Kurt Partridge 2013-02-27 14:12:50 -08:00
parent bca8348e98
commit ee3261ff55
1 changed files with 11 additions and 8 deletions

View File

@ -143,14 +143,7 @@ public final class Uploader {
connection.setDoOutput(true); connection.setDoOutput(true);
connection.setFixedLengthStreamingMode(contentLength); connection.setFixedLengthStreamingMode(contentLength);
final OutputStream outputStream = connection.getOutputStream(); final OutputStream outputStream = connection.getOutputStream();
final byte[] buf = new byte[BUF_SIZE]; uploadContents(fileInputStream, outputStream);
int numBytesRead;
while ((numBytesRead = fileInputStream.read(buf)) != -1) {
outputStream.write(buf, 0, numBytesRead);
if (DEBUG) {
Log.d(TAG, new String(buf));
}
}
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
Log.d(TAG, "upload failed: " + connection.getResponseCode()); Log.d(TAG, "upload failed: " + connection.getResponseCode());
final InputStream netInputStream = connection.getInputStream(); final InputStream netInputStream = connection.getInputStream();
@ -184,4 +177,14 @@ public final class Uploader {
} }
return success; 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);
}
}
} }