use of com.box.androidsdk.content.utils.ProgressOutputStream in project box-android-sdk by box.
the class BoxRequestMultipart method writeBody.
protected void writeBody(HttpURLConnection connection, ProgressListener listener) throws BoxException {
try {
connection.setChunkedStreamingMode(0);
connection.setDoOutput(true);
connection.setUseCaches(false);
this.outputStream = connection.getOutputStream();
for (Map.Entry<String, String> entry : this.fields.entrySet()) {
this.writePartHeader(new String[][] { { "name", entry.getKey() } });
this.writeOutput(entry.getValue());
}
this.writePartHeader(new String[][] { { "name", "filename" }, { "filename", this.filename } }, "application/octet-stream");
OutputStream fileContentsOutputStream = this.outputStream;
if (listener != null) {
fileContentsOutputStream = new ProgressOutputStream(this.outputStream, listener, this.fileSize);
}
byte[] buffer = new byte[BUFFER_SIZE];
int n = this.inputStream.read(buffer);
while (n != -1) {
fileContentsOutputStream.write(buffer, 0, n);
n = this.inputStream.read(buffer);
}
if (LOGGER.isLoggable(Level.FINE)) {
this.loggedRequest.append("<File Contents Omitted>");
}
this.writeBoundary();
this.writeOutput("--");
} catch (IOException e) {
throw new BoxException("Couldn't connect to the Box API due to a network error.", e);
} finally {
if (outputStream != null) {
try {
outputStream.close();
} catch (Exception e) {
}
}
}
}
Aggregations