Search in sources :

Example 1 with BuffersPool

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);
}
Also used : BuffersPool(com.stanfy.enroscar.io.BuffersPool)

Example 2 with BuffersPool

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);
    }
}
Also used : BuffersPool(com.stanfy.enroscar.io.BuffersPool) OutputStream(java.io.OutputStream)

Example 3 with BuffersPool

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");
}
Also used : BuffersPool(com.stanfy.enroscar.io.BuffersPool) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 4 with BuffersPool

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);
        }
    }
}
Also used : BuffersPool(com.stanfy.enroscar.io.BuffersPool) OutputStream(java.io.OutputStream) BinaryData(com.stanfy.enroscar.rest.request.binary.BinaryData)

Aggregations

BuffersPool (com.stanfy.enroscar.io.BuffersPool)4 OutputStream (java.io.OutputStream)2 BinaryData (com.stanfy.enroscar.rest.request.binary.BinaryData)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Test (org.junit.Test)1