use of com.stanfy.enroscar.io.BuffersPool in project enroscar by stanfy.
the class BinaryData method writeInputStreamToOutput.
/**
* Utility method for transferring input stream to output.
* @param context application context (needed to retrieve a buffers pool)
* @param source input stream
* @param output output stream
* @throws IOException if I/O error happens
*/
protected static void writeInputStreamToOutput(final Context context, final InputStream source, final OutputStream output) throws IOException {
BuffersPool pool = BeansManager.get(context).getContainer().getBean(BuffersPool.class);
IoUtils.transfer(source, output, pool);
}
use of com.stanfy.enroscar.io.BuffersPool in project enroscar by stanfy.
the class UploadPostConverter method sendRequest.
@Override
public void sendRequest(final URLConnection connection) throws IOException {
final BuffersPool buffersPool = BeansManager.get(getContext()).getContainer().getBean(BuffersPool.class);
final OutputStream out = buffersPool.bufferize(connection.getOutputStream());
if (Utils.isDebugRest(getContext())) {
Log.d(TAG, "(" + getRequestDescription().getId() + ") Parts: " + Arrays.toString(parts));
}
try {
Part.sendParts(out, parts, boundary);
} finally {
IoUtils.closeQuietly(out);
}
}
use of com.stanfy.enroscar.io.BuffersPool in project enroscar by stanfy.
the class IoSampleTest method sample.
@Test
public void sample() throws Exception {
BuffersPool pool = new BuffersPool();
ByteArrayOutputStream output = new ByteArrayOutputStream();
IoUtils.transfer(new ByteArrayInputStream("test value".getBytes()), output, pool);
assertThat(new String(output.toByteArray(), "UTF-8")).isEqualTo("test value");
}
use of com.stanfy.enroscar.io.BuffersPool in project enroscar by stanfy.
the class PayloadPostConverter method sendRequest.
@Override
public void sendRequest(final URLConnection connection) throws IOException {
ArrayList<BinaryData<?>> binaryData = getRequestDescription().getBinaryData();
if (binaryData != null) {
final BuffersPool buffersPool = BeansManager.get(getContext()).getContainer().getBean(BuffersPool.class);
final OutputStream out = buffersPool.bufferize(connection.getOutputStream());
try {
int size = binaryData.size();
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < size; i++) {
binaryData.get(i).writeContentTo(getContext(), out);
}
doSendWorkarounds(UrlConnectionWrapper.unwrap(connection));
} finally {
IoUtils.closeQuietly(out);
}
}
}
Aggregations